diff --git a/Dev/Sources/SwiftUIDemo/DemoCropView2.swift b/Dev/Sources/SwiftUIDemo/DemoCropView2.swift index f23da131..535d1c59 100644 --- a/Dev/Sources/SwiftUIDemo/DemoCropView2.swift +++ b/Dev/Sources/SwiftUIDemo/DemoCropView2.swift @@ -18,6 +18,8 @@ struct DemoCropView2: View { @StateObject var editingStack: EditingStack @State var resultImage: ResultImage? @State var angle: EditingCrop.AdjustmentAngle = .zero + @State var baselineAngle: EditingCrop.AdjustmentAngle = .zero + @State var isDragging: Bool = false init( editingStack: @escaping () -> EditingStack @@ -51,9 +53,18 @@ struct DemoCropView2: View { cropOutsideOverlay: { kind in Rectangle() .fill(kind == nil ? Color.white : Color.white.opacity(0.6)) + }, + stateHandler: { state in + state.ifChanged(\.adjustmentKind).do { kind in + if kind.isEmpty { + isDragging = false + } else { + isDragging = true + } + } } ) - .adjustmentAngle(angle) + .adjustmentAngle(angle + baselineAngle) .croppingAspectRatio(.init(width: 1, height: 1.4)) .frame(height: 300) .clipped() @@ -67,7 +78,18 @@ struct DemoCropView2: View { Spacer() - Slider(value: $angle.degrees, in: -45.0...45.0, step: 1) + HStack { + Slider(value: $angle.degrees, in: -45.0...45.0, step: 1) + .disabled(isDragging) + Button(action: { + baselineAngle -= .degrees(90) + }, label: { + Text("Rotate") + }) + .disabled(isDragging) + } + .disabled(isDragging) + .padding(24) } diff --git a/Sources/BrightroomUI/Shared/Components/Crop/CropView._InteractiveCropGuideView.swift b/Sources/BrightroomUI/Shared/Components/Crop/CropView._InteractiveCropGuideView.swift index 6542b64e..23b37798 100644 --- a/Sources/BrightroomUI/Shared/Components/Crop/CropView._InteractiveCropGuideView.swift +++ b/Sources/BrightroomUI/Shared/Components/Crop/CropView._InteractiveCropGuideView.swift @@ -48,6 +48,8 @@ extension CropView { var updating: () -> Void = {} var didChange: () -> Void = {} + var didUpdateAdjustmentKind: (CropView.State.AdjustmentKind) -> Void = { _ in } + private let topLeftControlPointView = TapExpandedView(horizontal: 16, vertical: 16) private let topRightControlPointView = TapExpandedView(horizontal: 16, vertical: 16) private let bottomLeftControlPointView = TapExpandedView(horizontal: 16, vertical: 16) @@ -340,11 +342,13 @@ extension CropView { func willBeginScrollViewAdjustment() { cropInsideOverlay?.didBeginAdjustment(kind: .scrollView) cropOutsideOverlay?.didBeginAdjustment(kind: .scrollView) + didUpdateAdjustmentKind(.scrollView) } func didEndScrollViewAdjustment() { cropInsideOverlay?.didEndAdjustment(kind: .scrollView) cropOutsideOverlay?.didEndAdjustment(kind: .scrollView) + didUpdateAdjustmentKind([]) } @inline(__always) @@ -384,6 +388,7 @@ extension CropView { willChange() cropInsideOverlay?.didBeginAdjustment(kind: .guide) cropOutsideOverlay?.didBeginAdjustment(kind: .guide) + didUpdateAdjustmentKind(.guide) } private func onGestureTrackingChanged() { @@ -399,6 +404,7 @@ extension CropView { didChange() cropInsideOverlay?.didEndAdjustment(kind: .guide) cropOutsideOverlay?.didEndAdjustment(kind: .guide) + didUpdateAdjustmentKind([]) } private var widthConstraint: NSLayoutConstraint! diff --git a/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift b/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift index 23c4cb04..070e3e16 100644 --- a/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift +++ b/Sources/BrightroomUI/Shared/Components/Crop/CropView.swift @@ -57,6 +57,8 @@ public final class CropView: UIView, UIScrollViewDelegate { public fileprivate(set) var frame: CGRect = .zero + public fileprivate(set) var adjustmentKind: AdjustmentKind = [] + fileprivate var layoutVersion: UInt64 = 0 /** @@ -270,9 +272,12 @@ public final class CropView: UIView, UIScrollViewDelegate { scrollView.addSubview(imagePlatterView) scrollView.delegate = self - guideView.didChange = { [weak self] in + guideView.willChange = { [weak self] in guard let self = self else { return } - self.didChangeGuideViewWithDelay() + self.willChangeGuideView() + store.commit { + $0.adjustmentKind = .guide + } } guideView.updating = { [weak self] in @@ -283,9 +288,16 @@ public final class CropView: UIView, UIScrollViewDelegate { // updateScrollViewInset(crop: currentProposedCrop) } - guideView.willChange = { [weak self] in + guideView.didChange = { [weak self] in guard let self = self else { return } - self.willChangeGuideView() + self.didChangeGuideViewWithDelay() + } + + guideView.didUpdateAdjustmentKind = { [weak self] kind in + guard let self else { return } + self.store.commit { + $0.adjustmentKind = kind + } } #if false