diff --git a/Sources/TsuzuKit/Representable/PartlyRoundedCornerView.swift b/Sources/TsuzuKit/Representable/PartlyRoundedCornerView.swift new file mode 100644 index 0000000..83cb0e4 --- /dev/null +++ b/Sources/TsuzuKit/Representable/PartlyRoundedCornerView.swift @@ -0,0 +1,36 @@ +/// https://qiita.com/chocoyama/items/1cb7040f0e717406a6f4 +/// Useage +/// .cornerRadius(20, maskedCorners: [.layerMinXMinYCorner, .layerMaxXMinYCorner]) + +import SwiftUI + +public struct PartlyRoundedCornerView: UIViewRepresentable { + let cornerRadius: CGFloat + let maskedCorners: CACornerMask + + public func makeUIView(context: UIViewRepresentableContext) -> UIView { + let uiView = UIView() + uiView.layer.cornerRadius = cornerRadius + uiView.layer.maskedCorners = maskedCorners + uiView.backgroundColor = .white + return uiView + } + + public func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext) { + } +} + +public struct PartlyRoundedCornerModifier: ViewModifier { + let cornerRadius: CGFloat + let maskedCorners: CACornerMask + + public func body(content: Content) -> some View { + content.mask(PartlyRoundedCornerView(cornerRadius: self.cornerRadius, maskedCorners: self.maskedCorners)) + } +} + +extension View { + public func cornerRadius(_ radius: CGFloat, maskedCorners: CACornerMask) -> some View { + self.modifier(PartlyRoundedCornerModifier(cornerRadius: radius, maskedCorners: maskedCorners)) + } +}