Skip to content

Commit

Permalink
fix: Dragging after rotation(#1), adjust to fill after rotation, anim…
Browse files Browse the repository at this point in the history
…ation.
  • Loading branch information
laosb committed Sep 1, 2023
1 parent 63a60f8 commit e703e25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/CropImage/DefaultControlsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct DefaultControlsView: View {
var rotateButton: some View {
Button {
let roundedAngle = Angle.degrees((rotation.degrees / 90).rounded() * 90)
withAnimation {
withAnimation(.interactiveSpring()) {
rotation = roundedAngle + .degrees(90)
}
} label: {
Expand Down
17 changes: 12 additions & 5 deletions Sources/CropImage/UnderlyingImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct UnderlyingImageView: View {
clampedOffset.height = clampedOffset.height.clamped(to: yOffsetBounds(at: clampedScale))

if clampedScale != scale || clampedOffset != offset {
withAnimation {
withAnimation(.interactiveSpring()) {
scale = clampedScale
offset = clampedOffset
}
Expand Down Expand Up @@ -104,7 +104,6 @@ struct UnderlyingImageView: View {
.onEnded { value in
offset = offset + tempOffset
tempOffset = .zero
adjustToFulfillTargetFrame()
}
}

Expand All @@ -116,7 +115,6 @@ struct UnderlyingImageView: View {
.onEnded { value in
scale = scale * tempScale
tempScale = 1
adjustToFulfillTargetFrame()
}
}

Expand All @@ -133,14 +131,23 @@ struct UnderlyingImageView: View {

var body: some View {
imageView
.rotationEffect(rotation + tempRotation)
.scaleEffect(scale * tempScale)
.offset(offset + tempOffset)
.rotationEffect(rotation + tempRotation)
.overlay(interactionView)
.clipped()
.onChange(of: viewSize) { newValue in
setInitialScale(basedOn: newValue)
}
.clipped()
.onChange(of: scale) { _ in
adjustToFulfillTargetFrame()
}
.onChange(of: offset) { _ in
adjustToFulfillTargetFrame()
}
.onChange(of: rotation) { _ in
adjustToFulfillTargetFrame()
}
}
}

Expand Down

0 comments on commit e703e25

Please sign in to comment.