Skip to content

Commit e805790

Browse files
authored
Fix/beta 1.0 (#27)
* fix: working dentent setting and improved performance * fix: bring back the keyboard avoidance hack * fix: improve example code with viewbuilder * fix: improved keyboard avoidance setup * feat: new example and more Apple modifiers added * fix: quick fix to resolve the apple scroll behaviour for now
1 parent 394c1d0 commit e805790

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Sources/BottomSheet/UIKit Views/UIScrollViewWrapper.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,19 @@ internal struct UIScrollViewWrapper<Content: View>: UIViewRepresentable {
8383
self.representable = representable
8484
}
8585

86-
private func shouldDragSheet(_ scrollViewPosition: CGFloat) -> Bool {
86+
private func shouldDragSheet(_ scrollViewPosition: CGFloat, isFixedHeight: Bool) -> Bool {
8787
// Translation on a scrollview without an overflow get's set to 0 somehow.
8888
// Implemented this check to prevent it from snapping back to the original position.
8989
// Need to dive deeper to figure out why it gets set to 0.
90-
if representable.translation >= limits.max && representable.translation == 0 {
90+
if isFixedHeight && representable.translation == 0 {
91+
if scrollViewPosition > scrollOffset {
92+
scrollOffset = scrollViewPosition
93+
}
94+
95+
return scrollViewPosition < 0
96+
}
97+
98+
if representable.translation >= limits.max {
9199
if scrollViewPosition > scrollOffset {
92100
scrollOffset = scrollViewPosition
93101
}
@@ -99,8 +107,10 @@ internal struct UIScrollViewWrapper<Content: View>: UIViewRepresentable {
99107
}
100108

101109
func scrollViewDidScroll(_ scrollView: UIScrollView) {
110+
let isFixedHeight = scrollView.contentSize.height < scrollView.frame.size.height
111+
102112
guard scrollView.isTracking else { return }
103-
guard shouldDragSheet(scrollView.contentOffset.y) else {
113+
guard shouldDragSheet(scrollView.contentOffset.y, isFixedHeight: isFixedHeight) else {
104114
scrollView.showsVerticalScrollIndicator = true
105115
return
106116
}

0 commit comments

Comments
 (0)