Merge branch 'mkirk/dont-show-caption-for-single'

pull/1/head
Michael Kirk 7 years ago
commit 86b18ddac6

@ -174,7 +174,8 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
self.view.backgroundColor = .black self.view.backgroundColor = .black
disablePagingIfNecessary() // avoid an unpleasant "bounce" which doesn't make sense in the context of a single item.
pagerScrollView?.isScrollEnabled = attachmentItems.count > 1
// Bottom Toolbar // Bottom Toolbar
galleryRailView.delegate = self galleryRailView.delegate = self
@ -253,6 +254,8 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
return return
} }
navigationBar.overrideTheme(type: .clear) navigationBar.overrideTheme(type: .clear)
updateCaptionVisibility()
} }
override public func viewDidAppear(_ animated: Bool) { override public func viewDidAppear(_ animated: Bool) {
@ -313,7 +316,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
lastObservedKeyboardTop = keyboardEndFrame.size.height lastObservedKeyboardTop = keyboardEndFrame.size.height
let keyboardScenario: KeyboardScenario = bottomToolView.isEditingMediaMessage ? .editingMessage : .editingCaption let keyboardScenario: KeyboardScenario = bottomToolView.isEditingMediaMessage ? .editingMessage : .editingCaption
currentPageController.updateCaptionViewBottomInset(keyboardScenario: keyboardScenario) currentPageViewController.updateCaptionViewBottomInset(keyboardScenario: keyboardScenario)
} }
@objc @objc
@ -336,7 +339,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
Logger.debug("\(keyboardStartFrame) -> \(keyboardEndFrame)") Logger.debug("\(keyboardStartFrame) -> \(keyboardEndFrame)")
lastObservedKeyboardTop = UIScreen.main.bounds.height - keyboardEndFrame.size.height lastObservedKeyboardTop = UIScreen.main.bounds.height - keyboardEndFrame.size.height
currentPageController.updateCaptionViewBottomInset(keyboardScenario: .hidden) currentPageViewController.updateCaptionViewBottomInset(keyboardScenario: .hidden)
} }
// MARK: - View Helpers // MARK: - View Helpers
@ -395,24 +398,19 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
button.autoPinEdge(toSuperviewMargin: .trailing) button.autoPinEdge(toSuperviewMargin: .trailing)
} }
var pagerScrollView: UIScrollView? lazy var pagerScrollView: UIScrollView? = {
// This is kind of a hack. Since we don't have first class access to the superview's `scrollView` // This is kind of a hack. Since we don't have first class access to the superview's `scrollView`
// we traverse the view hierarchy until we find it, then disable scrolling if there's only one // we traverse the view hierarchy until we find it.
// item. This avoids an unpleasant "bounce" which doesn't make sense in the context of a single item. let pagerScrollView = view.subviews.first { $0 is UIScrollView } as? UIScrollView
fileprivate func disablePagingIfNecessary() { assert(pagerScrollView != nil)
for view in self.view.subviews {
if let pagerScrollView = view as? UIScrollView {
self.pagerScrollView = pagerScrollView
break
}
}
guard let pagerScrollView = self.pagerScrollView else { return pagerScrollView
owsFailDebug("pagerScrollView was unexpectedly nil") }()
return
}
pagerScrollView.isScrollEnabled = attachmentItems.count > 1 func updateCaptionVisibility() {
for pageViewController in pageViewControllers {
pageViewController.updateCaptionVisibility(attachmentCount: attachments.count)
}
} }
// MARK: - UIPageViewControllerDelegate // MARK: - UIPageViewControllerDelegate
@ -493,13 +491,17 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
return nextPage return nextPage
} }
public var currentViewController: AttachmentPrepViewController { public var currentPageViewController: AttachmentPrepViewController {
return viewControllers!.first as! AttachmentPrepViewController return pageViewControllers.first!
}
public var pageViewControllers: [AttachmentPrepViewController] {
return super.viewControllers!.map { $0 as! AttachmentPrepViewController }
} }
var currentItem: SignalAttachmentItem! { var currentItem: SignalAttachmentItem! {
get { get {
return currentViewController.attachmentItem return currentPageViewController.attachmentItem
} }
set { set {
setCurrentItem(newValue, direction: .forward, animated: false) setCurrentItem(newValue, direction: .forward, animated: false)
@ -517,6 +519,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
Logger.debug("cache miss.") Logger.debug("cache miss.")
let viewController = AttachmentPrepViewController(attachmentItem: item) let viewController = AttachmentPrepViewController(attachmentItem: item)
viewController.prepDelegate = self viewController.prepDelegate = self
viewController.updateCaptionVisibility(attachmentCount: attachments.count)
cachedPages[item] = viewController cachedPages[item] = viewController
return viewController return viewController
@ -596,23 +599,19 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
} }
extension AttachmentApprovalViewController: MediaMessageTextToolbarDelegate { extension AttachmentApprovalViewController: MediaMessageTextToolbarDelegate {
var currentPageController: AttachmentPrepViewController {
return viewControllers!.first as! AttachmentPrepViewController
}
func mediaMessageTextToolbarDidBeginEditing(_ mediaMessageTextToolbar: MediaMessageTextToolbar) { func mediaMessageTextToolbarDidBeginEditing(_ mediaMessageTextToolbar: MediaMessageTextToolbar) {
currentPageController.setAttachmentViewScale(.compact, animated: true) currentPageViewController.setAttachmentViewScale(.compact, animated: true)
} }
func mediaMessageTextToolbarDidEndEditing(_ mediaMessageTextToolbar: MediaMessageTextToolbar) { func mediaMessageTextToolbarDidEndEditing(_ mediaMessageTextToolbar: MediaMessageTextToolbar) {
currentPageController.setAttachmentViewScale(.fullsize, animated: true) currentPageViewController.setAttachmentViewScale(.fullsize, animated: true)
} }
func mediaMessageTextToolbarDidTapSend(_ mediaMessageTextToolbar: MediaMessageTextToolbar) { func mediaMessageTextToolbarDidTapSend(_ mediaMessageTextToolbar: MediaMessageTextToolbar) {
// Toolbar flickers in and out if there are errors // Toolbar flickers in and out if there are errors
// and remains visible momentarily after share extension is dismissed. // and remains visible momentarily after share extension is dismissed.
// It's easiest to just hide it at this point since we're done with it. // It's easiest to just hide it at this point since we're done with it.
currentViewController.shouldAllowAttachmentViewResizing = false currentPageViewController.shouldAllowAttachmentViewResizing = false
mediaMessageTextToolbar.isUserInteractionEnabled = false mediaMessageTextToolbar.isUserInteractionEnabled = false
mediaMessageTextToolbar.isHidden = true mediaMessageTextToolbar.isHidden = true
@ -694,7 +693,7 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate
} }
func enablePaging() { func enablePaging() {
self.pagerScrollView?.panGestureRecognizer.isEnabled = true pagerScrollView?.panGestureRecognizer.isEnabled = true
} }
} }
@ -790,6 +789,22 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
func updateCaptionVisibility(attachmentCount: Int) {
if attachmentCount > 1 {
captionView.isHidden = false
}
// If we previously had multiple attachments, we'd have shown the caption fields.
//
// Subsequently, if the user had added caption text, then removed the other attachments
// we will continue to show this caption field, so as not to hide any already-entered text.
if let captionText = captionView.captionText, captionText.count > 0 {
captionView.isHidden = false
}
captionView.isHidden = true
}
// MARK: - Subviews // MARK: - Subviews
lazy var captionView: CaptionView = { lazy var captionView: CaptionView = {

Loading…
Cancel
Save