Skip to content

Commit baae67f

Browse files
lsdimagineyayvery
authored andcommitted
When setting scrollable, keep isScrollableLocked value if scrollable is scrolling (#16)
1 parent c1d467d commit baae67f

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

src/components/bottomSheet/BottomSheet.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
299299
animatedScrollableOverrideState,
300300
isScrollableRefreshable,
301301
isScrollableLocked,
302+
isScrollEnded,
302303
setScrollableRef,
303304
removeScrollableRef,
304305
} = useScrollable();
@@ -1109,6 +1110,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
11091110
isContentHeightFixed,
11101111
isScrollableRefreshable,
11111112
isScrollableLocked,
1113+
isScrollEnded,
11121114
shouldHandleKeyboardEvents,
11131115
simultaneousHandlers: _providedSimultaneousHandlers,
11141116
waitFor: _providedWaitFor,
@@ -1145,6 +1147,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
11451147
animatedScrollableContentOffsetY,
11461148
isScrollableRefreshable,
11471149
isScrollableLocked,
1150+
isScrollEnded,
11481151
isContentHeightFixed,
11491152
isInTemporaryPosition,
11501153
enableContentPanningGesture,

src/contexts/internal.ts

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface BottomSheetInternalContextType
6262
animatedScrollableOverrideState: Animated.SharedValue<SCROLLABLE_STATE>;
6363
isScrollableLocked: Animated.SharedValue<boolean>;
6464
isScrollableRefreshable: Animated.SharedValue<boolean>;
65+
isScrollEnded: Animated.SharedValue<boolean>;
6566
isContentHeightFixed: Animated.SharedValue<boolean>;
6667
isInTemporaryPosition: Animated.SharedValue<boolean>;
6768
shouldHandleKeyboardEvents: Animated.SharedValue<boolean>;

src/hooks/useScrollEventsHandlersDefault.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
2626
animatedAnimationState,
2727
animatedScrollableContentOffsetY: rootScrollableContentOffsetY,
2828
isScrollableLocked,
29+
isScrollEnded,
2930
} = useBottomSheetInternal();
3031
const awaitingFirstScroll = useSharedValue(false);
31-
const scrollEnded = useSharedValue(false);
3232
const _lockableScrollableContentOffsetY = useSharedValue(0);
3333

3434
useAnimatedReaction(
@@ -74,7 +74,7 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
7474
}
7575

7676
if (animatedScrollableState.value === SCROLLABLE_STATE.LOCKED) {
77-
if (!(preserveScrollMomentum && scrollEnded.value)) {
77+
if (!(preserveScrollMomentum && isScrollEnded.value)) {
7878
const lockPosition = context.shouldLockInitialPosition
7979
? context.initialContentOffsetY ?? 0
8080
: 0;
@@ -103,7 +103,7 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
103103
rootScrollableContentOffsetY.value = y;
104104
context.initialContentOffsetY = y;
105105
awaitingFirstScroll.value = true;
106-
scrollEnded.value = false;
106+
isScrollEnded.value = false;
107107

108108
if (scrollBuffer) {
109109
if (y <= 0 && (
@@ -152,7 +152,7 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
152152
useWorkletCallback(
153153
({ contentOffset: { y }}, context) => {
154154
awaitingFirstScroll.value = false;
155-
scrollEnded.value = true;
155+
isScrollEnded.value = true;
156156
if (animatedScrollableState.value === SCROLLABLE_STATE.LOCKED) {
157157
const lockPosition = context.shouldLockInitialPosition
158158
? context.initialContentOffsetY ?? 0
@@ -181,7 +181,7 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
181181
useWorkletCallback(
182182
({ contentOffset: { y } }, context) => {
183183
if (animatedScrollableState.value === SCROLLABLE_STATE.LOCKED) {
184-
if (!(preserveScrollMomentum && scrollEnded.value)) {
184+
if (!(preserveScrollMomentum && isScrollEnded.value)) {
185185
const lockPosition = context.shouldLockInitialPosition
186186
? context.initialContentOffsetY ?? 0
187187
: 0;

src/hooks/useScrollable.ts

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const useScrollable = () => {
1919
);
2020
const isScrollableRefreshable = useSharedValue<boolean>(false);
2121
const isScrollableLocked = useSharedValue<boolean>(true);
22+
const isScrollEnded = useSharedValue<boolean>(true);
2223

2324
// callbacks
2425
const setScrollableRef = useCallback((ref: ScrollableRef) => {
@@ -65,6 +66,7 @@ export const useScrollable = () => {
6566
animatedScrollableOverrideState,
6667
isScrollableRefreshable,
6768
isScrollableLocked,
69+
isScrollEnded,
6870
setScrollableRef,
6971
removeScrollableRef,
7072
};

src/hooks/useScrollableSetter.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const useScrollableSetter = (
2525
removeScrollableRef,
2626
animatedContainerHeight,
2727
animatedContentHeight,
28+
isScrollEnded,
2829
} = useBottomSheetInternal();
2930

3031
// callbacks
@@ -33,8 +34,9 @@ export const useScrollableSetter = (
3334
rootScrollableContentOffsetY.value = contentOffsetY.value;
3435
animatedScrollableType.value = type;
3536
isScrollableRefreshable.value = refreshable;
37+
// Keep isScrollableLocked value if the scrollable is still scrolling
3638
// Android scrollview doesn't bounce so we need to set isScrollableLocked so that the sheet can be pulled up/down
37-
isScrollableLocked.value = (!preserveScrollMomentum && !scrollBuffer) || (Platform.OS === 'android' && animatedContentHeight.value <= animatedContainerHeight.value);
39+
isScrollableLocked.value = (!isScrollEnded.value && isScrollableLocked.value) || (!preserveScrollMomentum && !scrollBuffer) || (Platform.OS === 'android' && animatedContentHeight.value <= animatedContainerHeight.value);
3840
isContentHeightFixed.value = false;
3941

4042
// set current scrollable ref

0 commit comments

Comments
 (0)