/
DemoCropView2.swift
115 lines (99 loc) 路 2.7 KB
/
DemoCropView2.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// DemoCropView2.swift
// SwiftUIDemo
//
// Created by Jinsei Shima on 2024/02/28.
// Copyright 漏 2024 muukii. All rights reserved.
//
import BrightroomEngine
import BrightroomUI
import BrightroomUIPhotosCrop
import SwiftUI
import UIKit
import SwiftUISupport
struct DemoCropView2: View {
@StateObject var editingStack: EditingStack
@State var resultImage: ResultImage?
@State var angle: EditingCrop.AdjustmentAngle = .zero
init(
editingStack: @escaping () -> EditingStack
) {
self._editingStack = .init(wrappedValue: editingStack())
}
var body: some View {
ZStack {
VStack {
Spacer()
SwiftUICropView(
editingStack: editingStack,
isGuideInteractionEnabled: false,
contentInset: .init(top: 20, left: 20, bottom: 20, right: 20),
cropInsideOverlay: { kind in
ViewHost(instantiated: CropView.RuleOfThirdsView(lineColor: .white))
.overlay {
Rectangle()
.fill(kind == nil ? Color.white : Color.white.opacity(0.6))
.overlay {
RoundedRectangle(cornerRadius: 24, style: .continuous)
.blendMode(.destinationOut)
}
.compositingGroup()
}
},
cropOutsideOverlay: { kind in
Rectangle()
.fill(kind == nil ? Color.white : Color.white.opacity(0.6))
}
)
.adjustmentAngle(angle)
.frame(height: 500)
.clipped()
.background(Color.gray)
Spacer()
Slider(value: $angle.degrees, in: -45.0...45.0, step: 1)
}
VStack {
HStack {
Spacer()
Button("Done") {
let image = try! editingStack.makeRenderer().render().cgImage
self.resultImage = .init(cgImage: image)
}
.buttonStyle(.borderedProminent)
.buttonBorderShape(.capsule)
.tint(.yellow)
.foregroundColor(.black)
}
Spacer()
}
.padding(.horizontal, 30)
.padding(.vertical, 15)
.ignoresSafeArea()
}
.onAppear {
editingStack.start()
}
.sheet(item: $resultImage) {
RenderedResultView(result: $0)
}
}
}
#Preview("local") {
DemoCropView2(
editingStack: { Mocks.makeEditingStack(image: Mocks.imageHorizontal()) }
)
}
#Preview("remote") {
DemoCropView2(
editingStack: {
EditingStack(
imageProvider: .init(
editableRemoteURL: URL(
string:
"https://images.unsplash.com/photo-1604456930969-37f67bcd6e1e?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1"
)!
)
)
}
)
}