Merge branch 'charlesmchen/imageEditorVsFirstResponder2' into release/2.38.0

pull/2/head
Matthew Chen 5 years ago
commit 033f5fe2df

@ -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
@ -124,6 +120,12 @@ class AttachmentApprovalInputAccessoryView: UIView {
currentCaptionWrapper.isHidden = isEditingCaptions || !hasCurrentCaption currentCaptionWrapper.isHidden = isEditingCaptions || !hasCurrentCaption
attachmentTextToolbar.isHidden = isEditingCaptions attachmentTextToolbar.isHidden = isEditingCaptions
updateFirstResponder()
layoutSubviews()
}
private func updateFirstResponder() {
if (shouldHideControls) { if (shouldHideControls) {
if attachmentCaptionToolbar.textView.isFirstResponder { if attachmentCaptionToolbar.textView.isFirstResponder {
attachmentCaptionToolbar.textView.resignFirstResponder() attachmentCaptionToolbar.textView.resignFirstResponder()
@ -135,17 +137,30 @@ 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;
layoutSubviews()
} }
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 {
updateFirstResponder()
return
}
self.isEditingCaptions = isEditingCaptions self.isEditingCaptions = isEditingCaptions
self.currentAttachmentItem = currentAttachmentItem self.currentAttachmentItem = currentAttachmentItem
self.shouldHideControls = shouldHideControls
updateContents() updateContents()
} }
@ -159,6 +174,12 @@ class AttachmentApprovalInputAccessoryView: UIView {
return CGSize.zero return CGSize.zero
} }
} }
public var hasFirstResponder: Bool {
return (isFirstResponder ||
attachmentCaptionToolbar.textView.isFirstResponder ||
attachmentTextToolbar.textView.isFirstResponder)
}
} }
// MARK: - // MARK: -

@ -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,16 @@ 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)
let hasPresentedView = self.presentedViewController != nil
let isToolbarFirstResponder = bottomToolView.hasFirstResponder
if !shouldHideControls, !isFirstResponder, !hasPresentedView, !isToolbarFirstResponder {
becomeFirstResponder()
}
bottomToolView.update(isEditingCaptions: isEditingCaptions,
currentAttachmentItem: currentAttachmentItem,
shouldHideControls: shouldHideControls)
} }
// MARK: - Navigation Bar // MARK: - Navigation Bar
@ -327,15 +335,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 +410,6 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
updateMediaRail() updateMediaRail()
} }
} }
updateContents()
} }
// MARK: - UIPageViewControllerDataSource // MARK: - UIPageViewControllerDataSource
@ -463,6 +460,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 +691,7 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate
} }
func prepViewControllerUpdateControls() { func prepViewControllerUpdateControls() {
updateControlVisibility() updateInputAccessory()
} }
} }

Loading…
Cancel
Save