Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Feb 22, 2024
1 parent 8897bd2 commit a145c6a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/FluidGroup/PrecisionLevelSlider",
"state" : {
"revision" : "cd02d02e8add9886586d12450caba952fcdde910",
"version" : "2.0.0"
"revision" : "ba982248e1b89a021e9ab08aa0f3c660d8da1f73",
"version" : "2.0.1"
}
},
{
Expand Down
39 changes: 34 additions & 5 deletions Dev/Sources/SwiftUIDemo/DemoCropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,42 @@ struct DemoCropView: View {
}

var body: some View {
VStack {
PhotosCropRotating(editingStack: { editingStack })
Button("Done") {
let image = try! editingStack.makeRenderer().render().cgImage
self.resultImage = .init(cgImage: image)
ZStack {

VStack {
PhotosCropRotating(editingStack: { editingStack })
// Button("Done") {
// let image = try! editingStack.makeRenderer().render().cgImage
// self.resultImage = .init(cgImage: image)
// }
}

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()

}
// .safeAreaInset(edge: .top, content: {
// Button("Done") {
// let image = try! editingStack.makeRenderer().render().cgImage
// self.resultImage = .init(cgImage: image)
// }
// })

.onAppear {
editingStack.start()
}
Expand Down
4 changes: 1 addition & 3 deletions Sources/BrightroomUI/Shared/Components/Crop/CropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,7 @@ public final class CropView: UIView, UIScrollViewDelegate {
store.commit {
if let proposedCrop = $0.proposedCrop {
$0.proposedCrop = proposedCrop.makeInitial()
if let ratio = $0.preferredAspectRatio {
$0.proposedCrop!.updateCropExtentIfNeeded(toFitAspectRatio: ratio)
}
$0.preferredAspectRatio = nil
$0.layoutVersion += 1
}
}
Expand Down
26 changes: 26 additions & 0 deletions Sources/BrightroomUI/Shared/Components/Crop/SwiftUICropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public final class _PixelEditor_WrapperViewController<BodyView: UIView>: UIViewC
@available(iOS 14, *)
public struct SwiftUICropView: UIViewControllerRepresentable {

public final class ResetAction {

var onCall: () -> Void = {}

public init() {

}

public func callAsFunction() {
onCall()
}
}

public typealias UIViewControllerType = _PixelEditor_WrapperViewController<CropView>

private let cropInsideOverlay: ((CropView.State.AdjustmentKind?) -> AnyView)?
Expand All @@ -62,6 +75,7 @@ public struct SwiftUICropView: UIViewControllerRepresentable {
private var _rotation: EditingCrop.Rotation?
private var _adjustmentAngle: EditingCrop.AdjustmentAngle?
private var _croppingAspectRatio: PixelAspectRatio?
private var _resetAction: ResetAction?

private let stateHandler: @MainActor (Verge.Changes<CropView.State>) -> Void

Expand Down Expand Up @@ -111,6 +125,10 @@ public struct SwiftUICropView: UIViewControllerRepresentable {

uiViewController.bodyView.setStateHandler(stateHandler)
uiViewController.bodyView.setCroppingAspectRatio(_croppingAspectRatio)

_resetAction?.onCall = {
uiViewController.bodyView.resetCrop()
}
}

public func rotation(_ rotation: EditingCrop.Rotation?) -> Self {
Expand All @@ -136,4 +154,12 @@ public struct SwiftUICropView: UIViewControllerRepresentable {

}

public func registerResetAction(_ action: ResetAction) -> Self {

var modified = self
modified._resetAction = action
return modified

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public struct PhotosCropRotating: View {

@State private var cropViewState: Changes<CropView.State>?

@State var reset: SwiftUICropView.ResetAction = .init()

public init(
editingStack: @escaping () -> EditingStack
) {
Expand Down Expand Up @@ -110,18 +112,7 @@ public struct PhotosCropRotating: View {

if editingStack.state.loadedState?.hasUncommitedChanges ?? false {
Button {
rotation = .angle_0
adjustmentAngle = nil
croppingAspectRatio = nil

// switch croppingAspectRatio {
// case .fixed(let ratio):
// cropView.setCroppingAspectRatio(ratio)
// case .selectable:
// cropView.setCroppingAspectRatio(nil)
// }
// cropView.resetCrop()

reset()
} label: {
Text("RESET")
.font(.subheadline)
Expand Down Expand Up @@ -180,6 +171,7 @@ public struct PhotosCropRotating: View {
.rotation(rotation)
.adjustmentAngle(adjustmentAngle)
.croppingAspectRatio(croppingAspectRatio)
.registerResetAction(reset)
.zIndex(0)

Group {
Expand Down Expand Up @@ -278,6 +270,7 @@ public struct PhotosCropRotating: View {
}
)
.tint(.white)
.accentColor(.white)
.frame(height: 50)
.disabled(isLoading)
}
Expand Down

0 comments on commit a145c6a

Please sign in to comment.