Skip to content

Commit 2962a2d

Browse files
committed
fix: updated the enable content panning gesture logic
1 parent cb750f6 commit 2962a2d

7 files changed

+94
-44
lines changed

src/components/bottomSheet/BottomSheet.tsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
378378
keyboardBehavior,
379379
]);
380380
const animatedScrollableState = useDerivedValue(() => {
381+
/**
382+
* if user had disabled content panning gesture, then we unlock
383+
* the scrollable state.
384+
*/
385+
if (!enableContentPanningGesture) {
386+
return SCROLLABLE_STATE.UNLOCKED;
387+
}
388+
381389
/**
382390
* if scrollable override state is set, then we just return its value.
383391
*/
@@ -414,6 +422,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
414422

415423
return SCROLLABLE_STATE.LOCKED;
416424
}, [
425+
enableContentPanningGesture,
417426
animatedAnimationState.value,
418427
animatedKeyboardState.value,
419428
animatedScrollableOverrideState.value,
@@ -1821,6 +1830,10 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
18211830
},
18221831
});
18231832
}
1833+
1834+
const DraggableView = enableContentPanningGesture
1835+
? BottomSheetDraggableView
1836+
: Animated.View;
18241837
return (
18251838
<BottomSheetProvider value={externalContextVariables}>
18261839
<BottomSheetInternalProvider value={internalContextVariables}>
@@ -1858,7 +1871,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
18581871
accessibilityRole={_providedAccessibilityRole ?? undefined}
18591872
accessibilityLabel={_providedAccessibilityLabel ?? undefined}
18601873
>
1861-
<BottomSheetDraggableView
1874+
<DraggableView
18621875
key="BottomSheetRootDraggableView"
18631876
style={contentContainerStyle}
18641877
>
@@ -1869,7 +1882,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
18691882
footerComponent={footerComponent}
18701883
/>
18711884
)}
1872-
</BottomSheetDraggableView>
1885+
</DraggableView>
18731886
</Animated.View>
18741887
<BottomSheetHandleContainer
18751888
key="BottomSheetHandleContainer"

src/components/bottomSheetRefreshControl/BottomSheetRefreshControl.android.tsx

+32-15
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ function BottomSheetRefreshControlComponent({
2323
}: BottomSheetRefreshControlProps) {
2424
//#region hooks
2525
const draggableGesture = useContext(BottomSheetDraggableContext);
26-
const { animatedScrollableState } = useBottomSheetInternal();
26+
const { animatedScrollableState, enableContentPanningGesture } =
27+
useBottomSheetInternal();
2728
//#endregion
2829

29-
if (!draggableGesture) {
30+
if (!draggableGesture && enableContentPanningGesture) {
3031
throw "'BottomSheetRefreshControl' cannot be used out of the BottomSheet!";
3132
}
3233

@@ -38,24 +39,40 @@ function BottomSheetRefreshControlComponent({
3839
[animatedScrollableState.value]
3940
);
4041

41-
const gesture = useMemo(() => {
42-
return Gesture.Simultaneous(
43-
Gesture.Native().shouldCancelWhenOutside(false),
44-
scrollableGesture,
42+
const gesture = useMemo(
43+
() =>
4544
draggableGesture
46-
);
47-
}, [draggableGesture, scrollableGesture]);
45+
? Gesture.Native()
46+
// @ts-ignore
47+
.simultaneousWithExternalGesture(
48+
draggableGesture,
49+
scrollableGesture
50+
)
51+
.shouldCancelWhenOutside(true)
52+
: undefined,
53+
[draggableGesture, scrollableGesture]
54+
);
55+
4856
//#endregion
4957

5058
// render
59+
if (gesture) {
60+
return (
61+
<GestureDetector gesture={gesture}>
62+
<AnimatedRefreshControl
63+
{...rest}
64+
onRefresh={onRefresh}
65+
animatedProps={animatedProps}
66+
/>
67+
</GestureDetector>
68+
);
69+
}
5170
return (
52-
<GestureDetector gesture={gesture}>
53-
<AnimatedRefreshControl
54-
{...rest}
55-
onRefresh={onRefresh}
56-
animatedProps={animatedProps}
57-
/>
58-
</GestureDetector>
71+
<AnimatedRefreshControl
72+
{...rest}
73+
onRefresh={onRefresh}
74+
animatedProps={animatedProps}
75+
/>
5976
);
6077
}
6178

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import {
3+
GestureDetector,
4+
type SimultaneousGesture,
5+
} from 'react-native-gesture-handler';
6+
7+
interface BottomSheetDraggableScrollableProps {
8+
scrollableGesture?: SimultaneousGesture;
9+
children: React.ReactNode;
10+
}
11+
12+
export function BottomSheetDraggableScrollable({
13+
scrollableGesture,
14+
children,
15+
}: BottomSheetDraggableScrollableProps) {
16+
if (scrollableGesture) {
17+
return (
18+
<GestureDetector gesture={scrollableGesture}>{children}</GestureDetector>
19+
);
20+
}
21+
22+
return children;
23+
}

src/components/bottomSheetScrollable/ScrollableContainer.android.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React, { forwardRef } from 'react';
2-
import {
3-
GestureDetector,
4-
type SimultaneousGesture,
5-
} from 'react-native-gesture-handler';
2+
import type { SimultaneousGesture } from 'react-native-gesture-handler';
63
import BottomSheetRefreshControl from '../bottomSheetRefreshControl';
4+
import { BottomSheetDraggableScrollable } from './BottomSheetDraggableScrollable';
75
import { styles } from './styles';
86

97
interface ScrollableContainerProps {
@@ -35,17 +33,17 @@ export const ScrollableContainer = forwardRef<any, ScrollableContainerProps>(
3533
ref
3634
) {
3735
const Scrollable = (
38-
<GestureDetector gesture={nativeGesture}>
36+
<BottomSheetDraggableScrollable scrollableGesture={nativeGesture}>
3937
<ScrollableComponent ref={ref} {...rest} />
40-
</GestureDetector>
38+
</BottomSheetDraggableScrollable>
4139
);
4240

4341
return onRefresh ? (
4442
<BottomSheetRefreshControl
43+
scrollableGesture={nativeGesture}
4544
refreshing={refreshing}
4645
progressViewOffset={progressViewOffset}
4746
onRefresh={onRefresh}
48-
scrollableGesture={nativeGesture}
4947
style={styles.container}
5048
>
5149
{Scrollable}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React, { type FC, forwardRef } from 'react';
2-
import {
3-
GestureDetector,
4-
type SimultaneousGesture,
5-
} from 'react-native-gesture-handler';
2+
import type { SimultaneousGesture } from 'react-native-gesture-handler';
3+
import { BottomSheetDraggableScrollable } from './BottomSheetDraggableScrollable';
64

75
interface ScrollableContainerProps {
8-
nativeGesture: SimultaneousGesture;
6+
nativeGesture?: SimultaneousGesture;
97
// biome-ignore lint/suspicious/noExplicitAny: 🤷‍♂️
108
ScrollableComponent: FC<any>;
119
}
@@ -16,9 +14,9 @@ export const ScrollableContainer = forwardRef<never, ScrollableContainerProps>(
1614
ref
1715
) {
1816
return (
19-
<GestureDetector gesture={nativeGesture}>
17+
<BottomSheetDraggableScrollable scrollableGesture={nativeGesture}>
2018
<ScrollableComponent ref={ref} {...rest} />
21-
</GestureDetector>
19+
</BottomSheetDraggableScrollable>
2220
);
2321
}
2422
);

src/components/bottomSheetScrollable/ScrollableContainer.web.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React, { type ComponentProps, forwardRef, useCallback } from 'react';
2-
import {
3-
GestureDetector,
4-
type SimultaneousGesture,
5-
} from 'react-native-gesture-handler';
2+
import type { SimultaneousGesture } from 'react-native-gesture-handler';
63
import Animated from 'react-native-reanimated';
4+
import { BottomSheetDraggableScrollable } from './BottomSheetDraggableScrollable';
75

86
interface ScrollableContainerProps {
97
nativeGesture: SimultaneousGesture;
@@ -25,12 +23,12 @@ export const ScrollableContainer = forwardRef<
2523
[animatedProps]
2624
);
2725
return (
28-
<GestureDetector gesture={nativeGesture}>
26+
<BottomSheetDraggableScrollable scrollableGesture={nativeGesture}>
2927
<ScrollableComponent
3028
ref={ref}
3129
{...rest}
3230
renderScrollComponent={renderScrollComponent}
3331
/>
34-
</GestureDetector>
32+
</BottomSheetDraggableScrollable>
3533
);
3634
});

src/components/bottomSheetScrollable/createBottomSheetScrollableComponent.tsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ export function createBottomSheetScrollableComponent<T, P>(
6464
animatedContentHeight,
6565
animatedScrollableState,
6666
enableDynamicSizing,
67+
enableContentPanningGesture,
6768
} = useBottomSheetInternal();
6869
//#endregion
6970

70-
if (!draggableGesture) {
71+
if (!draggableGesture && enableContentPanningGesture) {
7172
throw "'Scrollable' cannot be used out of the BottomSheet!";
7273
}
7374

@@ -83,12 +84,14 @@ export function createBottomSheetScrollableComponent<T, P>(
8384
[animatedScrollableState, showsVerticalScrollIndicator]
8485
);
8586

86-
const nativeGesture = useMemo(
87+
const scrollableGesture = useMemo(
8788
() =>
88-
Gesture.Native()
89-
// @ts-ignore
90-
.simultaneousWithExternalGesture(draggableGesture)
91-
.shouldCancelWhenOutside(false),
89+
draggableGesture
90+
? Gesture.Native()
91+
// @ts-ignore
92+
.simultaneousWithExternalGesture(draggableGesture)
93+
.shouldCancelWhenOutside(false)
94+
: undefined,
9295
[draggableGesture]
9396
);
9497
//#endregion
@@ -144,7 +147,7 @@ export function createBottomSheetScrollableComponent<T, P>(
144147
return (
145148
<ScrollableContainer
146149
ref={scrollableRef}
147-
nativeGesture={nativeGesture}
150+
nativeGesture={scrollableGesture}
148151
animatedProps={scrollableAnimatedProps}
149152
overScrollMode={overScrollMode}
150153
keyboardDismissMode={keyboardDismissMode}

0 commit comments

Comments
 (0)