Further improve "first responder" behavior in the image editor.

pull/2/head
Matthew Chen 5 years ago
parent d3869af067
commit 517a550593

@ -101,11 +101,7 @@ class AttachmentApprovalInputAccessoryView: UIView {
// MARK: // MARK:
public var shouldHideControls = false { private var shouldHideControls = false
didSet {
updateContents()
}
}
private func updateContents() { private func updateContents() {
var hasCurrentCaption = false var hasCurrentCaption = false
@ -135,6 +131,10 @@ class AttachmentApprovalInputAccessoryView: UIView {
if !attachmentCaptionToolbar.textView.isFirstResponder { if !attachmentCaptionToolbar.textView.isFirstResponder {
attachmentCaptionToolbar.textView.becomeFirstResponder() attachmentCaptionToolbar.textView.becomeFirstResponder()
} }
} else {
if attachmentCaptionToolbar.textView.isFirstResponder {
attachmentCaptionToolbar.textView.resignFirstResponder()
}
} }
// NOTE: We don't automatically make attachmentTextToolbar.textView // NOTE: We don't automatically make attachmentTextToolbar.textView
// first responder; // first responder;
@ -143,9 +143,18 @@ class AttachmentApprovalInputAccessoryView: UIView {
} }
public func update(isEditingCaptions: Bool, public func update(isEditingCaptions: Bool,
currentAttachmentItem: SignalAttachmentItem?) { currentAttachmentItem: SignalAttachmentItem?,
shouldHideControls: Bool) {
// De-bounce
guard self.isEditingCaptions != isEditingCaptions ||
self.currentAttachmentItem != currentAttachmentItem ||
self.shouldHideControls != shouldHideControls else {
return
}
self.isEditingCaptions = isEditingCaptions self.isEditingCaptions = isEditingCaptions
self.currentAttachmentItem = currentAttachmentItem self.currentAttachmentItem = currentAttachmentItem
self.shouldHideControls = shouldHideControls
updateContents() updateContents()
} }

@ -184,7 +184,6 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
private func updateContents() { private func updateContents() {
updateNavigationBar() updateNavigationBar()
updateInputAccessory() updateInputAccessory()
updateControlVisibility()
touchInterceptorView.isHidden = !isEditingCaptions touchInterceptorView.isHidden = !isEditingCaptions
} }
@ -206,7 +205,10 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
currentPageViewController = pageViewControllers.first currentPageViewController = pageViewControllers.first
} }
let currentAttachmentItem: SignalAttachmentItem? = currentPageViewController?.attachmentItem let currentAttachmentItem: SignalAttachmentItem? = currentPageViewController?.attachmentItem
bottomToolView.update(isEditingCaptions: isEditingCaptions, currentAttachmentItem: currentAttachmentItem)
bottomToolView.update(isEditingCaptions: isEditingCaptions,
currentAttachmentItem: currentAttachmentItem,
shouldHideControls: shouldHideControls)
} }
// MARK: - Navigation Bar // MARK: - Navigation Bar
@ -327,15 +329,6 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
return pageViewController.shouldHideControls return pageViewController.shouldHideControls
} }
private func updateControlVisibility() {
let hasPresentedView = self.presentedViewController != nil
if !shouldHideControls, !isFirstResponder, !hasPresentedView {
becomeFirstResponder()
}
bottomToolView.shouldHideControls = shouldHideControls
}
// MARK: - View Helpers // MARK: - View Helpers
func remove(attachmentItem: SignalAttachmentItem) { func remove(attachmentItem: SignalAttachmentItem) {
@ -411,8 +404,6 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
updateMediaRail() updateMediaRail()
} }
} }
updateContents()
} }
// MARK: - UIPageViewControllerDataSource // MARK: - UIPageViewControllerDataSource
@ -463,6 +454,18 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
return super.viewControllers!.map { $0 as! AttachmentPrepViewController } return super.viewControllers!.map { $0 as! AttachmentPrepViewController }
} }
@objc
public override func setViewControllers(_ viewControllers: [UIViewController]?, direction: UIPageViewController.NavigationDirection, animated: Bool, completion: ((Bool) -> Void)? = nil) {
super.setViewControllers(viewControllers,
direction: direction,
animated: animated) { [weak self] (finished) in
if let completion = completion {
completion(finished)
}
self?.updateContents()
}
}
var currentItem: SignalAttachmentItem! { var currentItem: SignalAttachmentItem! {
get { get {
return currentPageViewController.attachmentItem return currentPageViewController.attachmentItem
@ -682,7 +685,7 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate
} }
func prepViewControllerUpdateControls() { func prepViewControllerUpdateControls() {
updateControlVisibility() updateInputAccessory()
} }
} }

Loading…
Cancel
Save