Compare commits
No commits in common. "6ee1ad24ec8620f5c17416d6141643f0787708ba" and "ca374422db48f381f46be8b5dae52c944e51daf0" have entirely different histories.
6ee1ad24ec
...
ca374422db
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public protocol SheetContainerViewControllerDelegate: class {
|
public protocol SheetContainerViewControllerDelegate {
|
||||||
func sheetContainer(_ sheetContainer: SheetContainerViewController, willSnapToDetent detent: Detent) -> Bool
|
func sheetContainer(_ sheetContainer: SheetContainerViewController, willSnapToDetent detent: Detent) -> Bool
|
||||||
func sheetContainer(_ sheetContainer: SheetContainerViewController, didSnapToDetent detent: Detent)
|
func sheetContainer(_ sheetContainer: SheetContainerViewController, didSnapToDetent detent: Detent)
|
||||||
func sheetContainerContentScrollView(_ sheetContainer: SheetContainerViewController) -> UIScrollView?
|
func sheetContainerContentScrollView(_ sheetContainer: SheetContainerViewController) -> UIScrollView?
|
||||||
|
@ -29,9 +29,9 @@ public extension SheetContainerViewControllerDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class SheetContainerViewController: UIViewController {
|
public class SheetContainerViewController: UIViewController {
|
||||||
|
|
||||||
public weak var delegate: SheetContainerViewControllerDelegate?
|
public var delegate: SheetContainerViewControllerDelegate?
|
||||||
|
|
||||||
public let content: UIViewController
|
public let content: UIViewController
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ open class SheetContainerViewController: UIViewController {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override open func viewDidLoad() {
|
override public func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
dimmingView = UIView()
|
dimmingView = UIView()
|
||||||
|
@ -136,16 +136,16 @@ open class SheetContainerViewController: UIViewController {
|
||||||
let velocity = recognizer.velocity(in: scrollView)
|
let velocity = recognizer.velocity(in: scrollView)
|
||||||
|
|
||||||
let topContentOffset: CGFloat = delegate?.sheetContainer(self, topContentOffsetForScrollView: scrollView) ?? 0
|
let topContentOffset: CGFloat = delegate?.sheetContainer(self, topContentOffsetForScrollView: scrollView) ?? 0
|
||||||
let shouldMoveSheetDown = scrollView.contentOffset.y <= -topContentOffset && velocity.y > 0 // scrolled to top and dragging down
|
let shouldMoveSheetDown = scrollView.contentOffset.y <= topContentOffset && velocity.y > 0 // scrolled to top and dragging down
|
||||||
let shouldMoveSheetUp = topConstraint.constant > topDetent.offset && velocity.y < 0 // not fully expanded and dragging up
|
let shouldMoveSheetUp = topConstraint.constant > topDetent.offset && velocity.y < 0 // not fully expanded and dragging up
|
||||||
|
|
||||||
let shouldMoveSheet = shouldMoveSheetDown || shouldMoveSheetUp
|
let shouldMoveSheet = shouldMoveSheetDown || shouldMoveSheetUp
|
||||||
|
|
||||||
switch recognizer.state {
|
switch recognizer.state {
|
||||||
case .began:
|
case .began:
|
||||||
|
scrollView.bounces = false
|
||||||
scrollViewIsMovingSheet = shouldMoveSheet
|
scrollViewIsMovingSheet = shouldMoveSheet
|
||||||
if shouldMoveSheet {
|
if shouldMoveSheet {
|
||||||
scrollView.bounces = false
|
|
||||||
initialScrollViewContentOffset = scrollView.contentOffset
|
initialScrollViewContentOffset = scrollView.contentOffset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,10 +154,6 @@ open class SheetContainerViewController: UIViewController {
|
||||||
if scrollViewIsMovingSheet {
|
if scrollViewIsMovingSheet {
|
||||||
if initialScrollViewContentOffset == nil {
|
if initialScrollViewContentOffset == nil {
|
||||||
initialScrollViewContentOffset = scrollView.contentOffset
|
initialScrollViewContentOffset = scrollView.contentOffset
|
||||||
|
|
||||||
// if the sheet begins moving part way through the gesture, we need to ignore any translation
|
|
||||||
// that's already taken place, otherwise the sheet will jump when it starts moving
|
|
||||||
recognizer.setTranslation(.zero, in: scrollView)
|
|
||||||
}
|
}
|
||||||
scrollView.setContentOffset(initialScrollViewContentOffset!, animated: false)
|
scrollView.setContentOffset(initialScrollViewContentOffset!, animated: false)
|
||||||
|
|
||||||
|
@ -167,8 +163,8 @@ open class SheetContainerViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
case .ended:
|
case .ended:
|
||||||
|
scrollView.bounces = true
|
||||||
if scrollViewIsMovingSheet {
|
if scrollViewIsMovingSheet {
|
||||||
scrollView.bounces = true
|
|
||||||
scrollView.setContentOffset(initialScrollViewContentOffset!, animated: false)
|
scrollView.setContentOffset(initialScrollViewContentOffset!, animated: false)
|
||||||
springToNearestDetent(verticalVelocity: velocity.y)
|
springToNearestDetent(verticalVelocity: velocity.y)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue