dont initializer pagerScrollView as sideEffect

pull/1/head
Michael Kirk 7 years ago
parent f9b1b2f360
commit 6fdd5d1001

@ -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
@ -395,25 +396,14 @@ 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
}
// MARK: - UIPageViewControllerDelegate // MARK: - UIPageViewControllerDelegate
@ -694,7 +684,7 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate
} }
func enablePaging() { func enablePaging() {
self.pagerScrollView?.panGestureRecognizer.isEnabled = true pagerScrollView?.panGestureRecognizer.isEnabled = true
} }
} }

Loading…
Cancel
Save