@swmansion/react-native-bottom-sheet 0.5.5 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/lib/module/BottomSheetBase.js +10 -13
  2. package/lib/module/BottomSheetBase.js.map +1 -1
  3. package/lib/module/BottomSheetContext.js.map +1 -1
  4. package/lib/module/BottomSheetFlatList.js +3 -42
  5. package/lib/module/BottomSheetFlatList.js.map +1 -1
  6. package/lib/module/BottomSheetScrollView.js +3 -43
  7. package/lib/module/BottomSheetScrollView.js.map +1 -1
  8. package/lib/module/bottomSheetScrollable.js +35 -0
  9. package/lib/module/bottomSheetScrollable.js.map +1 -0
  10. package/lib/module/index.js +1 -1
  11. package/lib/module/index.js.map +1 -1
  12. package/lib/module/useBottomSheetPanGesture.js +33 -23
  13. package/lib/module/useBottomSheetPanGesture.js.map +1 -1
  14. package/lib/module/useBottomSheetScrollable.js +14 -17
  15. package/lib/module/useBottomSheetScrollable.js.map +1 -1
  16. package/lib/typescript/src/BottomSheetBase.d.ts.map +1 -1
  17. package/lib/typescript/src/BottomSheetContext.d.ts +6 -4
  18. package/lib/typescript/src/BottomSheetContext.d.ts.map +1 -1
  19. package/lib/typescript/src/BottomSheetFlatList.d.ts +7 -12
  20. package/lib/typescript/src/BottomSheetFlatList.d.ts.map +1 -1
  21. package/lib/typescript/src/BottomSheetScrollView.d.ts +7 -14
  22. package/lib/typescript/src/BottomSheetScrollView.d.ts.map +1 -1
  23. package/lib/typescript/src/bottomSheetScrollable.d.ts +9 -0
  24. package/lib/typescript/src/bottomSheetScrollable.d.ts.map +1 -0
  25. package/lib/typescript/src/index.d.ts +3 -3
  26. package/lib/typescript/src/index.d.ts.map +1 -1
  27. package/lib/typescript/src/useBottomSheetPanGesture.d.ts +4 -6
  28. package/lib/typescript/src/useBottomSheetPanGesture.d.ts.map +1 -1
  29. package/lib/typescript/src/useBottomSheetScrollable.d.ts +1 -1
  30. package/lib/typescript/src/useBottomSheetScrollable.d.ts.map +1 -1
  31. package/package.json +2 -1
  32. package/src/BottomSheetBase.tsx +16 -14
  33. package/src/BottomSheetContext.tsx +7 -4
  34. package/src/BottomSheetFlatList.tsx +16 -58
  35. package/src/BottomSheetScrollView.tsx +17 -61
  36. package/src/bottomSheetScrollable.tsx +42 -0
  37. package/src/index.tsx +3 -9
  38. package/src/useBottomSheetPanGesture.ts +44 -53
  39. package/src/useBottomSheetScrollable.ts +16 -23
@@ -5,7 +5,9 @@ import { isWorkletFunction, scheduleOnRN } from 'react-native-worklets';
5
5
  import {
6
6
  type SharedValue,
7
7
  useAnimatedProps,
8
+ useAnimatedRef,
8
9
  useAnimatedScrollHandler,
10
+ useSharedValue,
9
11
  } from 'react-native-reanimated';
10
12
 
11
13
  import { useBottomSheetContext } from './BottomSheetContext';
@@ -16,14 +18,11 @@ export const useBottomSheetScrollable = (
16
18
  baseScrollEnabled: boolean | SharedValue<boolean | undefined> = true,
17
19
  onScroll?: ScrollHandler
18
20
  ) => {
19
- const {
20
- scrollOffset,
21
- scrollableRef,
22
- hasScrollable,
23
- isScrollableGestureActive,
24
- isScrollableLocked,
25
- panGesture,
26
- } = useBottomSheetContext();
21
+ const { isScrollableLocked, registerScrollable, panGesture } =
22
+ useBottomSheetContext();
23
+ const scrollableRef = useAnimatedRef();
24
+ const scrollOffset = useSharedValue(0);
25
+ const isGestureActive = useSharedValue(false);
27
26
  const isWorkletScrollHandler =
28
27
  onScroll !== undefined ? isWorkletFunction(onScroll) : false;
29
28
  const scrollHandler = useAnimatedScrollHandler({
@@ -42,11 +41,11 @@ export const useBottomSheetScrollable = (
42
41
  .simultaneousWithExternalGesture(panGesture)
43
42
  .onStart(() => {
44
43
  'worklet';
45
- isScrollableGestureActive.set(true);
44
+ isGestureActive.set(true);
46
45
  })
47
46
  .onFinalize(() => {
48
47
  'worklet';
49
- isScrollableGestureActive.set(false);
48
+ isGestureActive.set(false);
50
49
  });
51
50
  const animatedProps = useAnimatedProps(() => {
52
51
  const resolvedScrollEnabled =
@@ -58,18 +57,12 @@ export const useBottomSheetScrollable = (
58
57
  };
59
58
  });
60
59
  useEffect(() => {
61
- if (__DEV__ && hasScrollable.value) {
62
- console.warn(
63
- 'Multiple scrollables within a single bottom sheet. Only one `BottomSheetScrollView` ' +
64
- 'or `BottomSheetFlatList` is supported per bottom sheet.'
65
- );
66
- }
67
- hasScrollable.set(true);
68
- return () => {
69
- hasScrollable.set(false);
70
- isScrollableGestureActive.set(false);
71
- isScrollableLocked.set(false);
72
- };
73
- }, [hasScrollable, isScrollableGestureActive, isScrollableLocked]);
60
+ const unregister = registerScrollable({
61
+ ref: scrollableRef,
62
+ scrollOffset,
63
+ isGestureActive,
64
+ });
65
+ return unregister;
66
+ }, [registerScrollable, scrollableRef, scrollOffset, isGestureActive]);
74
67
  return { scrollHandler, scrollableRef, nativeGesture, animatedProps };
75
68
  };