@@ -371,7 +371,10 @@ public class UBottomSheetCoordinator {
371371 switch recognizer. state {
372372 case . began:
373373 lastY = 0
374- lastContentOffset = scrollView? . contentOffset ?? lastContentOffset
374+ if let scroll = scrollView{
375+ //set last contentOffset y value by adding 'dy' i.e. pre pan gesture happened.
376+ lastContentOffset. y = scroll. contentOffset. y + dy
377+ }
375378 totalTranslationMinY = minSheetPosition!
376379 totalTranslationMaxY = maxSheetPosition!
377380 translate ( with: vel, dy: dy, scrollView: scrollView)
@@ -412,16 +415,17 @@ public class UBottomSheetCoordinator {
412415 case . up where ( container!. frame. minY - minSheetPosition! > tolerance) :
413416 applyTranslation ( dy: dy - lastY)
414417 scroll. contentOffset. y = lastContentOffset. y
415- case . down where scroll. contentOffset. y <= 0 && !scroll. isDecelerating:
418+ case . down where scroll. contentOffset. y <= 0 /* && !scroll.isDecelerating*/ :
416419 applyTranslation ( dy: dy - lastY)
417420 scroll. contentOffset. y = 0
421+ lastContentOffset = . zero
418422 default :
419423 break
420424 }
421- lastContentOffset = scroll. contentOffset
422425 } else {
423426 applyTranslation ( dy: dy - lastY)
424427 }
428+ lastY = dy
425429 }
426430
427431
@@ -500,7 +504,6 @@ public class UBottomSheetCoordinator {
500504 - parameter dy: change in the y direction of pan gesture
501505 */
502506 private func applyTranslation( dy: CGFloat ) {
503- lastY += dy
504507 guard dy != 0 else { return }
505508
506509 let topLimit = minSheetPosition!
@@ -509,13 +512,15 @@ public class UBottomSheetCoordinator {
509512 let oldFrame = container!. frame
510513 var newY = oldFrame. minY
511514
512- if hasExceededTopLimit ( oldFrame. minY, topLimit) {
513- totalTranslationMinY -= dy
515+ if hasExceededTopLimit ( oldFrame. minY+ dy, topLimit) {
516+ let yy = min ( 0 , topLimit - oldFrame. minY)
517+ totalTranslationMinY -= ( dy - yy)
514518 totalTranslationMaxY = maxSheetPosition!
515519 newY = dataSource. rubberBandLogicTop ( totalTranslationMinY, topLimit)
516- } else if hasExceededBottomLimit ( oldFrame. minY, bottomLimit) {
520+ } else if hasExceededBottomLimit ( oldFrame. minY+ dy, bottomLimit) {
521+ let yy = max ( 0 , bottomLimit - oldFrame. minY)
517522 totalTranslationMinY = minSheetPosition!
518- totalTranslationMaxY += dy
523+ totalTranslationMaxY += ( dy - yy )
519524 newY = dataSource. rubberBandLogicBottom ( totalTranslationMaxY, bottomLimit)
520525 } else {
521526 totalTranslationMinY = minSheetPosition!
@@ -609,7 +614,7 @@ public class UBottomSheetCoordinator {
609614 - parameter limit: max sheet y position
610615 */
611616 private func hasExceededBottomLimit( _ constant: CGFloat , _ limit: CGFloat ) -> Bool {
612- return constant > limit
617+ return ( constant - limit) > tolerance
613618 }
614619
615620}
0 commit comments