Hide controls while moving text items.

pull/2/head
Matthew Chen 6 years ago
parent 9e636b0fc9
commit e63b1169a3

@ -241,6 +241,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
navigationBar.overrideTheme(type: .clear)
updateNavigationBar()
updateControlVisibility()
}
override public func viewDidAppear(_ animated: Bool) {
@ -249,6 +250,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
super.viewDidAppear(animated)
updateNavigationBar()
updateControlVisibility()
}
override public func viewWillDisappear(_ animated: Bool) {
@ -262,12 +264,18 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
}
override public var canBecomeFirstResponder: Bool {
return true
return !shouldHideControls
}
// MARK: - Navigation Bar
public func updateNavigationBar() {
guard !shouldHideControls else {
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.rightBarButtonItem = nil
return
}
var navigationBarItems = [UIView]()
var isShowingCaptionView = false
@ -299,6 +307,27 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
}
}
// MARK: - Control Visibility
public var shouldHideControls: Bool {
guard let pageViewController = pageViewControllers.first else {
return false
}
return pageViewController.shouldHideControls
}
private func updateControlVisibility() {
if shouldHideControls {
if isFirstResponder {
resignFirstResponder()
}
} else {
if !isFirstResponder {
becomeFirstResponder()
}
}
}
// MARK: - View Helpers
func remove(attachmentItem: SignalAttachmentItem) {
@ -376,6 +405,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
}
updateNavigationBar()
updateControlVisibility()
}
// MARK: - UIPageViewControllerDataSource
@ -622,7 +652,11 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate
}
func prepViewControllerUpdateNavigationBar() {
self.updateNavigationBar()
updateNavigationBar()
}
func prepViewControllerUpdateControls() {
updateControlVisibility()
}
func prepViewControllerAttachmentCount() -> Int {
@ -682,6 +716,8 @@ protocol AttachmentPrepViewControllerDelegate: class {
func prepViewControllerUpdateNavigationBar()
func prepViewControllerUpdateControls()
func prepViewControllerAttachmentCount() -> Int
}
@ -712,9 +748,17 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
fileprivate var isShowingCaptionView = false {
didSet {
prepDelegate?.prepViewControllerUpdateNavigationBar()
prepDelegate?.prepViewControllerUpdateControls()
}
}
public var shouldHideControls: Bool {
guard let imageEditorView = imageEditorView else {
return false
}
return imageEditorView.shouldHideControls
}
// MARK: - Initializers
init(attachmentItem: SignalAttachmentItem) {
@ -794,8 +838,7 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
view.addSubview(imageEditorView)
imageEditorView.autoPinEdgesToSuperviewEdges()
imageEditorView.addControls(to: imageEditorView,
viewController: self)
imageEditorUpdateNavigationBar()
}
}
#endif
@ -872,6 +915,7 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
super.viewWillAppear(animated)
prepDelegate?.prepViewControllerUpdateNavigationBar()
prepDelegate?.prepViewControllerUpdateControls()
}
override public func viewDidAppear(_ animated: Bool) {
@ -880,6 +924,7 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
super.viewDidAppear(animated)
prepDelegate?.prepViewControllerUpdateNavigationBar()
prepDelegate?.prepViewControllerUpdateControls()
}
override public func viewWillLayoutSubviews() {
@ -1208,6 +1253,10 @@ extension AttachmentPrepViewController: ImageEditorViewDelegate {
public func imageEditorUpdateNavigationBar() {
prepDelegate?.prepViewControllerUpdateNavigationBar()
}
public func imageEditorUpdateControls() {
prepDelegate?.prepViewControllerUpdateControls()
}
}
// MARK: -

@ -9,6 +9,7 @@ public protocol ImageEditorViewDelegate: class {
func imageEditor(presentFullScreenView viewController: UIViewController,
isTransparent: Bool)
func imageEditorUpdateNavigationBar()
func imageEditorUpdateControls()
}
// MARK: -
@ -81,16 +82,17 @@ public class ImageEditorView: UIView {
return true
}
// TODO: Should this method be private?
@objc
public func addControls(to containerView: UIView,
viewController: UIViewController) {
// MARK: - Navigation Bar
private func updateNavigationBar() {
delegate?.imageEditorUpdateNavigationBar()
}
// MARK: - Navigation Bar
public func navigationBarItems() -> [UIView] {
guard !shouldHideControls else {
return []
}
let undoButton = navigationBarButton(imageName: "image_editor_undo",
selector: #selector(didTapUndo(sender:)))
let brushButton = navigationBarButton(imageName: "image_editor_brush",
@ -110,6 +112,15 @@ public class ImageEditorView: UIView {
return buttons
}
private func updateControls() {
delegate?.imageEditorUpdateControls()
}
public var shouldHideControls: Bool {
// Hide controls during "text item move".
return movingTextItem != nil
}
// MARK: - Actions
@objc func didTapUndo(sender: UIButton) {
@ -271,7 +282,12 @@ public class ImageEditorView: UIView {
// MARK: - Editor Gesture
// These properties are valid while moving a text item.
private var movingTextItem: ImageEditorTextItem?
private var movingTextItem: ImageEditorTextItem? {
didSet {
updateNavigationBar()
updateControls()
}
}
private var movingTextStartUnitCenter: CGPoint?
private var movingTextHasMoved = false
@ -487,11 +503,11 @@ extension ImageEditorView: ImageEditorModelObserver {
public func imageEditorModelDidChange(before: ImageEditorContents,
after: ImageEditorContents) {
delegate?.imageEditorUpdateNavigationBar()
updateNavigationBar()
}
public func imageEditorModelDidChange(changedItemIds: [String]) {
delegate?.imageEditorUpdateNavigationBar()
updateNavigationBar()
}
}

Loading…
Cancel
Save