Skip to content

#5976 Fix UI getting stuck when transition animation is interrupted #6000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions SignalUI/ImageEditor/ImageEditorCropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ class ImageEditorCropViewController: OWSViewController {
case initial
case final
}

private func updateControlsVisibility(hidden: Bool) {
self.footerView.alpha = hidden ? 0 : 1
self.cropView.setState(hidden ? .initial : .normal, animated: false)
self.bottomBar.setControls(hidden: hidden)
}

private func transitionUI(toState state: UIState, animated: Bool, completion: ((Bool) -> Void)? = nil) {
let layoutGuide: UILayoutGuide = {
Expand All @@ -405,12 +411,6 @@ class ImageEditorCropViewController: OWSViewController {
}()

let hideControls = state == .initial
let setControlsHiddenBlock = {
let alpha: CGFloat = hideControls ? 0 : 1
self.footerView.alpha = alpha
self.cropView.setState(state == .initial ? .initial : .normal, animated: false)
self.bottomBar.setControls(hidden: hideControls)
}

let animationDuration: TimeInterval = 0.15

Expand All @@ -425,9 +425,10 @@ class ImageEditorCropViewController: OWSViewController {
imageView.layer.cornerRadius = imageCornerRadius

if animated {

UIView.animate(withDuration: animationDuration,
animations: {
setControlsHiddenBlock()
self.updateControlsVisibility(hidden: hideControls)
self.constrainContent(to: layoutGuide)
self.updateImageViewTransform()
// Animate layout changes made within bottomBar.setControls(hidden:).
Expand All @@ -436,7 +437,7 @@ class ImageEditorCropViewController: OWSViewController {
},
completion: completion)
} else {
setControlsHiddenBlock()
updateControlsVisibility(hidden: hideControls)
constrainContent(to: layoutGuide)
updateImageViewTransform()
completion?(true)
Expand Down Expand Up @@ -949,7 +950,14 @@ extension ImageEditorCropViewController {
@objc
private func didTapCancel() {
transitionUI(toState: .initial, animated: true) { finished in
guard finished else { return }

// Fallback to reveal controls in case of an animation interruption
guard finished else {
self.updateControlsVisibility(hidden: false)
self.imageView.layer.cornerRadius = 0
self.didTapReset()
return
}
self.dismiss(animated: false)
}
}
Expand All @@ -958,7 +966,14 @@ extension ImageEditorCropViewController {
private func didTapDone() {
model.replace(transform: transform)
transitionUI(toState: .initial, animated: true) { finished in
guard finished else { return }

// Fallback to reveal controls in case of an animation interruption
guard finished else {
self.updateControlsVisibility(hidden: false)
self.imageView.layer.cornerRadius = 0
self.didTapReset()
return
}
self.dismiss(animated: false)
}
}
Expand Down