Skip to content

Commit

Permalink
chore: convert to preview macro
Browse files Browse the repository at this point in the history
  • Loading branch information
laosb committed Dec 18, 2024
1 parent 6b33bcd commit 5486180
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 41 deletions.
24 changes: 11 additions & 13 deletions Sources/CropImage/CropImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ public struct CropImageView<Controls: View, CutHole: View>: View {
}
}

struct CropImageView_Previews: PreviewProvider {
#Preview {
struct PreviewView: View {
@State private var targetSize: CGSize = .init(width: 100, height: 100)
@State private var result: Result<PlatformImage, Error>? = nil

var body: some View {
VStack {
CropImageView(
image: .init(contentsOfFile: "/Users/laosb/Downloads/png.png")!,
image: .init(contentsOf: URL(string: "file:///System/Library/Desktop%20Pictures/Hello%20Metallic%20Blue.heic")!)!,
targetSize: targetSize
) {
result = $0
Expand Down Expand Up @@ -262,18 +262,16 @@ struct CropImageView_Previews: PreviewProvider {
}
} header: { Text("Result") }
}
#if os(macOS)
#if os(macOS)
.formStyle(.grouped)
#endif
#endif
}
}
}

static var previews: some View {
PreviewView()
#if os(macOS)
.frame(width: 500)
.frame(minHeight: 600)
#endif
}

return PreviewView()
#if os(macOS)
.frame(width: 500)
.frame(minHeight: 600)
#endif
}
26 changes: 12 additions & 14 deletions Sources/CropImage/DefaultCutHoleShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,18 @@ struct DefaultCutHoleShape: Shape {
}
}

struct DefaultCutHoleShape_Previews: PreviewProvider {
static var previews: some View {
VStack {
DefaultCutHoleShape(size: .init(width: 100, height: 100))
.fill(style: FillStyle(eoFill: true))
.foregroundColor(.black.opacity(0.6))
}
.previewDisplayName("Default")
VStack {
DefaultCutHoleShape(size: .init(width: 100, height: 100), isCircular: true)
.fill(style: FillStyle(eoFill: true))
.foregroundColor(.black.opacity(0.6))
}
.previewDisplayName("Circular")
#Preview("Default") {
VStack {
DefaultCutHoleShape(size: .init(width: 100, height: 100))
.fill(style: FillStyle(eoFill: true))
.foregroundColor(.black.opacity(0.6))
}
}

#Preview("Circular") {
VStack {
DefaultCutHoleShape(size: .init(width: 100, height: 100), isCircular: true)
.fill(style: FillStyle(eoFill: true))
.foregroundColor(.black.opacity(0.6))
}
}
13 changes: 6 additions & 7 deletions Sources/CropImage/DefaultCutHoleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ public struct DefaultCutHoleView: View {
}
}

struct DefaultCutHoleView_Previews: PreviewProvider {
static var previews: some View {
DefaultCutHoleView(targetSize: .init(width: 100, height: 100))
.previewDisplayName("Default")
DefaultCutHoleView(targetSize: .init(width: 100, height: 100), isCircular: true)
.previewDisplayName("Circular")
}
#Preview("Default") {
DefaultCutHoleView(targetSize: .init(width: 100, height: 100))
}

#Preview("Circular") {
DefaultCutHoleView(targetSize: .init(width: 100, height: 100), isCircular: true)
}
12 changes: 5 additions & 7 deletions Sources/CropImage/UnderlyingImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,25 @@ struct UnderlyingImageView: View {
}
}

struct MoveAndScalableImageView_Previews: PreviewProvider {
#Preview {
struct PreviewView: View {
@State private var offset: CGSize = .zero
@State private var scale: CGFloat = 1
@State private var rotation: Angle = .zero

var body: some View {
UnderlyingImageView(
offset: $offset,
scale: $scale,
rotation: $rotation,
image: .init(contentsOfFile: "/Users/laosb/Downloads/png.png")!,
image: .init(contentsOf: URL(string: "file:///System/Library/Desktop%20Pictures/Hello%20Metallic%20Blue.heic")!)!,
viewSize: .init(width: 200, height: 100),
targetSize: .init(width: 100, height: 100),
fulfillTargetFrame: true
)
.frame(width: 200, height: 100)
}
}

static var previews: some View {
PreviewView()
}

return PreviewView()
}

0 comments on commit 5486180

Please sign in to comment.