diff --git a/Sources/CropImage/CropImageView.swift b/Sources/CropImage/CropImageView.swift index fc1b7f4..6ead4c8 100644 --- a/Sources/CropImage/CropImageView.swift +++ b/Sources/CropImage/CropImageView.swift @@ -154,12 +154,8 @@ public struct CropImageView: View { ) } - var rectHole: some View { - RectHoleShape(size: targetSize) - .fill(style: FillStyle(eoFill: true)) - .foregroundColor(.black.opacity(0.6)) - .animation(.default, value: targetSize) - .allowsHitTesting(false) + var cutHole: some View { + DefaultCutHoleView(targetSize: targetSize) } @MainActor var control: some View { @@ -175,7 +171,7 @@ public struct CropImageView: View { public var body: some View { underlyingImage .clipped() - .overlay(rectHole) + .overlay(cutHole) .overlay(control) } } diff --git a/Sources/CropImage/RectHoleShape.swift b/Sources/CropImage/DefaultCutHoleShape.swift similarity index 87% rename from Sources/CropImage/RectHoleShape.swift rename to Sources/CropImage/DefaultCutHoleShape.swift index ca317f5..818324c 100644 --- a/Sources/CropImage/RectHoleShape.swift +++ b/Sources/CropImage/DefaultCutHoleShape.swift @@ -1,5 +1,5 @@ // -// RectHoleShape.swift +// DefaultCutHoleShape.swift // // // Created by Shibo Lyu on 2023/7/21. @@ -7,7 +7,7 @@ import SwiftUI -struct RectHoleShape: Shape { +struct DefaultCutHoleShape: Shape { var size: CGSize var animatableData: AnimatablePair { @@ -39,10 +39,10 @@ struct RectHoleShape: Shape { } } -struct RectHoleShape_Previews: PreviewProvider { +struct DefaultCutHoleShape_Previews: PreviewProvider { static var previews: some View { VStack { - RectHoleShape(size: .init(width: 100, height: 100)) + DefaultCutHoleShape(size: .init(width: 100, height: 100)) .fill(style: FillStyle(eoFill: true)) .foregroundColor(.black.opacity(0.6)) } diff --git a/Sources/CropImage/DefaultCutHoleView.swift b/Sources/CropImage/DefaultCutHoleView.swift new file mode 100644 index 0000000..9b021aa --- /dev/null +++ b/Sources/CropImage/DefaultCutHoleView.swift @@ -0,0 +1,39 @@ +// +// SwiftUIView.swift +// +// +// Created by Shibo Lyu on 2023/8/15. +// + +import SwiftUI + +struct DefaultCutHoleView: View { + var targetSize: CGSize + var showStroke = true + + var background: some View { + DefaultCutHoleShape(size: targetSize) + .fill(style: FillStyle(eoFill: true)) + .foregroundColor(.black.opacity(0.6)) + } + + var stroke: some View { + Rectangle() + .strokeBorder(style: .init(lineWidth: 2)) + .frame(width: targetSize.width + 4, height: targetSize.height + 4) + .foregroundColor(.white) + } + + var body: some View { + background + .allowsHitTesting(false) + .overlay(showStroke ? stroke : nil) + .animation(.default, value: targetSize) + } +} + +struct DefaultCutHoleView_Previews: PreviewProvider { + static var previews: some View { + DefaultCutHoleView(targetSize: .init(width: 100, height: 100)) + } +}