Skip to content

Commit

Permalink
feat: Cut hole stroke.
Browse files Browse the repository at this point in the history
  • Loading branch information
laosb committed Aug 15, 2023
1 parent 8a4b717 commit 428b3eb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
10 changes: 3 additions & 7 deletions Sources/CropImage/CropImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,8 @@ public struct CropImageView<Controls: View>: 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 {
Expand All @@ -175,7 +171,7 @@ public struct CropImageView<Controls: View>: View {
public var body: some View {
underlyingImage
.clipped()
.overlay(rectHole)
.overlay(cutHole)
.overlay(control)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// RectHoleShape.swift
// DefaultCutHoleShape.swift
//
//
// Created by Shibo Lyu on 2023/7/21.
//

import SwiftUI

struct RectHoleShape: Shape {
struct DefaultCutHoleShape: Shape {
var size: CGSize

var animatableData: AnimatablePair<CGFloat, CGFloat> {
Expand Down Expand Up @@ -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))
}
Expand Down
39 changes: 39 additions & 0 deletions Sources/CropImage/DefaultCutHoleView.swift
Original file line number Diff line number Diff line change
@@ -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))
}
}

0 comments on commit 428b3eb

Please sign in to comment.