|
|
|
@ -56,6 +56,8 @@ public class SheetContainerViewController: UIViewController {
|
|
|
|
|
var contentScrollView: UIScrollView? {
|
|
|
|
|
delegate?.sheetContainerContentScrollView(self) ?? content.view as? UIScrollView
|
|
|
|
|
}
|
|
|
|
|
var initialScrollViewContentOffset: CGPoint?
|
|
|
|
|
var scrollViewIsMovingSheet = false
|
|
|
|
|
|
|
|
|
|
public init(content: UIViewController) {
|
|
|
|
|
self.content = content
|
|
|
|
@ -100,6 +102,10 @@ public class SheetContainerViewController: UIViewController {
|
|
|
|
|
panGesture.delegate = self
|
|
|
|
|
content.view.addGestureRecognizer(panGesture)
|
|
|
|
|
|
|
|
|
|
contentScrollViewChanged()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public func contentScrollViewChanged() {
|
|
|
|
|
if let scrollView = contentScrollView {
|
|
|
|
|
scrollView.panGestureRecognizer.addTarget(self, action: #selector(scrollViewPanGestureRecognized))
|
|
|
|
|
}
|
|
|
|
@ -134,14 +140,23 @@ public class SheetContainerViewController: UIViewController {
|
|
|
|
|
let shouldMoveSheetUp = topConstraint.constant > topDetent.offset && velocity.y < 0 // not fully expanded and dragging up
|
|
|
|
|
|
|
|
|
|
let shouldMoveSheet = shouldMoveSheetDown || shouldMoveSheetUp
|
|
|
|
|
if shouldMoveSheet {
|
|
|
|
|
scrollView.bounces = false
|
|
|
|
|
scrollView.setContentOffset(CGPoint(x: 0, y: topContentOffset), animated: false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch recognizer.state {
|
|
|
|
|
case .changed:
|
|
|
|
|
case .began:
|
|
|
|
|
scrollView.bounces = false
|
|
|
|
|
scrollViewIsMovingSheet = shouldMoveSheet
|
|
|
|
|
if shouldMoveSheet {
|
|
|
|
|
initialScrollViewContentOffset = scrollView.contentOffset
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case .changed:
|
|
|
|
|
scrollViewIsMovingSheet = scrollViewIsMovingSheet || shouldMoveSheet
|
|
|
|
|
if scrollViewIsMovingSheet {
|
|
|
|
|
if initialScrollViewContentOffset == nil {
|
|
|
|
|
initialScrollViewContentOffset = scrollView.contentOffset
|
|
|
|
|
}
|
|
|
|
|
scrollView.setContentOffset(initialScrollViewContentOffset!, animated: false)
|
|
|
|
|
|
|
|
|
|
let translation = recognizer.translation(in: scrollView)
|
|
|
|
|
setTopOffset(topConstraint.constant + translation.y)
|
|
|
|
|
recognizer.setTranslation(.zero, in: scrollView)
|
|
|
|
@ -149,9 +164,12 @@ public class SheetContainerViewController: UIViewController {
|
|
|
|
|
|
|
|
|
|
case .ended:
|
|
|
|
|
scrollView.bounces = true
|
|
|
|
|
if shouldMoveSheet {
|
|
|
|
|
if scrollViewIsMovingSheet {
|
|
|
|
|
scrollView.setContentOffset(initialScrollViewContentOffset!, animated: false)
|
|
|
|
|
springToNearestDetent(verticalVelocity: velocity.y)
|
|
|
|
|
}
|
|
|
|
|
scrollViewIsMovingSheet = false
|
|
|
|
|
initialScrollViewContentOffset = nil
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
@ -165,8 +183,8 @@ public class SheetContainerViewController: UIViewController {
|
|
|
|
|
if offset < topOffset {
|
|
|
|
|
let smoothed = smoothstep(value: offset, from: topOffset, to: 0)
|
|
|
|
|
offset = topOffset - smoothed * maximumStretchDistance
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topConstraint.constant = offset
|
|
|
|
|
dimmingView.alpha = lerp(offset, min: topOffset, max: bottomDetent.offset, from: maximumDimmingAlpha, to: minimumDimmingAlpha)
|
|
|
|
|
}
|
|
|
|
|