vOOice/VoiceInk/Views/Recorder/NotchShape.swift

59 lines
2.0 KiB
Swift

import SwiftUI
struct NotchShape: Shape {
var topCornerRadius: CGFloat {
if bottomCornerRadius > 15 {
bottomCornerRadius - 5
} else {
5
}
}
var bottomCornerRadius: CGFloat
init(cornerRadius: CGFloat? = nil) {
if cornerRadius == nil {
self.bottomCornerRadius = 10
} else {
self.bottomCornerRadius = cornerRadius!
}
}
var animatableData: CGFloat {
get { bottomCornerRadius }
set { bottomCornerRadius = newValue }
}
func path(in rect: CGRect) -> Path {
var path = Path()
// Start from the top left corner
path.move(to: CGPoint(x: rect.minX, y: rect.minY))
// Top left inner curve
path.addQuadCurve(
to: CGPoint(x: rect.minX + topCornerRadius, y: topCornerRadius),
control: CGPoint(x: rect.minX + topCornerRadius, y: rect.minY)
)
// Left vertical line
path.addLine(to: CGPoint(x: rect.minX + topCornerRadius, y: rect.maxY - bottomCornerRadius))
// Bottom left corner
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))
// Bottom right corner
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 + bottomCornerRadius))
// Closing the path to top right inner curve
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
}
}