/* * Atoll (DynamicIsland) * Copyright (C) 2024-2026 Atoll Contributors * * Originally from boring.notch project * Modified and adapted for Atoll (DynamicIsland) * See NOTICE for details. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import SwiftUI struct NotchShape: Shape { private var topCornerRadius: CGFloat private var bottomCornerRadius: CGFloat init( topCornerRadius: CGFloat? = nil, bottomCornerRadius: CGFloat? = nil ) { self.topCornerRadius = topCornerRadius ?? 6 self.bottomCornerRadius = bottomCornerRadius ?? 14 } var animatableData: AnimatablePair { get { .init( topCornerRadius, bottomCornerRadius ) } set { topCornerRadius = newValue.first bottomCornerRadius = newValue.second } } func path(in rect: CGRect) -> Path { var path = Path() path.move( to: CGPoint( x: rect.minX, y: rect.minY ) ) path.addQuadCurve( to: CGPoint( x: rect.minX + topCornerRadius, y: rect.minY + topCornerRadius ), control: CGPoint( x: rect.minX + topCornerRadius, y: rect.minY ) ) path.addLine( to: CGPoint( x: rect.minX + topCornerRadius, y: rect.maxY - bottomCornerRadius ) ) path.addQuadCurve( to: CGPoint( x: rect.minX + topCornerRadius + bottomCornerRadius, y: rect.maxY ), control: CGPoint( x: rect.minX + topCornerRadius, y: rect.maxY ) ) path.addLine( to: CGPoint( x: rect.maxX - topCornerRadius - bottomCornerRadius, y: rect.maxY ) ) path.addQuadCurve( to: CGPoint( x: rect.maxX - topCornerRadius, y: rect.maxY - bottomCornerRadius ), control: CGPoint( x: rect.maxX - topCornerRadius, y: rect.maxY ) ) path.addLine( to: CGPoint( x: rect.maxX - topCornerRadius, y: rect.minY + topCornerRadius ) ) path.addQuadCurve( to: CGPoint( x: rect.maxX, y: rect.minY ), control: CGPoint( x: rect.maxX - topCornerRadius, y: rect.minY ) ) path.addLine( to: CGPoint( x: rect.minX, y: rect.minY ) ) return path } } #Preview { NotchShape(topCornerRadius: 6, bottomCornerRadius: 14) .frame(width: 200, height: 32) .padding(10) }