mirror of
				https://github.com/laosb/CropImage.git
				synced 2025-11-04 08:01:38 +00:00 
			
		
		
		
	feat: Cut hole stroke.
This commit is contained in:
		
							parent
							
								
									8a4b71757c
								
							
						
					
					
						commit
						428b3eb5e8
					
				
					 3 changed files with 46 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -175,7 +171,7 @@ public struct CropImageView<Controls: View>: View {
 | 
			
		|||
    public var body: some View {
 | 
			
		||||
        underlyingImage
 | 
			
		||||
            .clipped()
 | 
			
		||||
            .overlay(rectHole)
 | 
			
		||||
            .overlay(cutHole)
 | 
			
		||||
            .overlay(control)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<CGFloat, CGFloat> {
 | 
			
		||||
| 
						 | 
				
			
			@ -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))
 | 
			
		||||
        }
 | 
			
		||||
							
								
								
									
										39
									
								
								Sources/CropImage/DefaultCutHoleView.swift
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Sources/CropImage/DefaultCutHoleView.swift
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue