Skip to content

Commit 8bd3a2c

Browse files
committed
smooth transition to rubber banding when pan fast. scroll view wrong content offset bug fixed when changing pan direction on scrollView pan without removing finger.
1 parent 1e2112b commit 8bd3a2c

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
| 🌒 | Allows adding dimmable background view |
1515
| 📱 | Set sheet content as UIViewController or UINavigationController |
1616
| 📖 | Navigation inside sheet with UINavigationController |
17-
| 🌈 | Add one to many sheet stop positions|
17+
| 🌈 | Add one or more sheet stop positions|
1818
| 🎯 | Change sheet position programmatically |
1919
| 🌀 | Present as many sheet as you want |
2020
| 🚀 | Move multiple sheets simultaneously or seperately |
@@ -71,6 +71,7 @@ Create a UBottomSheetCoordinator from the main view controller. Use the UBottomS
7171
```swift
7272

7373
// parentViewController: main view controller that presents the bottom sheet
74+
// call this within viewWillLayoutSubViews to make sure view frame has measured correctly. see example projects.
7475
let sheetCoordinator = UBottomSheetCoordinator(parent: parentViewController)
7576

7677
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MapsDemoBottomSheetController") as! MapsDemoBottomSheetController

UBottomSheet.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'UBottomSheet'
11-
s.version = '1.0.6'
11+
s.version = '1.0.7'
1212
s.summary = 'Mimics the iPhone Maps App bottom sheet'
1313
s.swift_version = '5.0'
1414

UBottomSheet/Classes/UBottomSheetCoordinator.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)