diff --git a/SignalUI/ImageEditor/ImageEditorCropViewController.swift b/SignalUI/ImageEditor/ImageEditorCropViewController.swift index 12d7c364780..66382072a2c 100644 --- a/SignalUI/ImageEditor/ImageEditorCropViewController.swift +++ b/SignalUI/ImageEditor/ImageEditorCropViewController.swift @@ -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 = { @@ -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 @@ -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:). @@ -436,7 +437,7 @@ class ImageEditorCropViewController: OWSViewController { }, completion: completion) } else { - setControlsHiddenBlock() + updateControlsVisibility(hidden: hideControls) constrainContent(to: layoutGuide) updateImageViewTransform() completion?(true) @@ -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) } } @@ -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) } }