@shaquillehinds/react-native-bottom-sheet 0.0.1

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 (187) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +880 -0
  3. package/lib/commonjs/BottomSheet/animations/drag.animation.js +72 -0
  4. package/lib/commonjs/BottomSheet/animations/drag.animation.js.map +1 -0
  5. package/lib/commonjs/BottomSheet/components/BottomSheet.js +92 -0
  6. package/lib/commonjs/BottomSheet/components/BottomSheet.js.map +1 -0
  7. package/lib/commonjs/BottomSheet/components/BottomSheetFlatlist.js +38 -0
  8. package/lib/commonjs/BottomSheet/components/BottomSheetFlatlist.js.map +1 -0
  9. package/lib/commonjs/BottomSheet/components/BottomSheetModal.js +34 -0
  10. package/lib/commonjs/BottomSheet/components/BottomSheetModal.js.map +1 -0
  11. package/lib/commonjs/BottomSheet/components/BottomSheetScrollView.js +37 -0
  12. package/lib/commonjs/BottomSheet/components/BottomSheetScrollView.js.map +1 -0
  13. package/lib/commonjs/BottomSheet/config/bottomSheet.constants.js +35 -0
  14. package/lib/commonjs/BottomSheet/config/bottomSheet.constants.js.map +1 -0
  15. package/lib/commonjs/BottomSheet/config/bottomSheet.styles.js +42 -0
  16. package/lib/commonjs/BottomSheet/config/bottomSheet.styles.js.map +1 -0
  17. package/lib/commonjs/BottomSheet/config/bottomSheet.types.js +14 -0
  18. package/lib/commonjs/BottomSheet/config/bottomSheet.types.js.map +1 -0
  19. package/lib/commonjs/BottomSheet/controller/bottomFlatlist.controller.js +69 -0
  20. package/lib/commonjs/BottomSheet/controller/bottomFlatlist.controller.js.map +1 -0
  21. package/lib/commonjs/BottomSheet/controller/bottomScrollView.controller.js +41 -0
  22. package/lib/commonjs/BottomSheet/controller/bottomScrollView.controller.js.map +1 -0
  23. package/lib/commonjs/BottomSheet/controller/bottomSheet.controller.js +216 -0
  24. package/lib/commonjs/BottomSheet/controller/bottomSheet.controller.js.map +1 -0
  25. package/lib/commonjs/BottomSheet/controller/callbacks.controller.js +135 -0
  26. package/lib/commonjs/BottomSheet/controller/callbacks.controller.js.map +1 -0
  27. package/lib/commonjs/BottomSheet/controller/dragAnimation.controller.js +127 -0
  28. package/lib/commonjs/BottomSheet/controller/dragAnimation.controller.js.map +1 -0
  29. package/lib/commonjs/BottomSheet/controller/hooks/useBottomSheetRef.js +60 -0
  30. package/lib/commonjs/BottomSheet/controller/hooks/useBottomSheetRef.js.map +1 -0
  31. package/lib/commonjs/BottomSheet/controller/hooks/useBottomSheetUtils.js +74 -0
  32. package/lib/commonjs/BottomSheet/controller/hooks/useBottomSheetUtils.js.map +1 -0
  33. package/lib/commonjs/BottomSheet/controller/index.js +17 -0
  34. package/lib/commonjs/BottomSheet/controller/index.js.map +1 -0
  35. package/lib/commonjs/BottomSheet/controller/keyboardAnimation.controller.js +88 -0
  36. package/lib/commonjs/BottomSheet/controller/keyboardAnimation.controller.js.map +1 -0
  37. package/lib/commonjs/BottomSheet/controller/scrollContent.controller.js +89 -0
  38. package/lib/commonjs/BottomSheet/controller/scrollContent.controller.js.map +1 -0
  39. package/lib/commonjs/BottomSheet/index.js +130 -0
  40. package/lib/commonjs/BottomSheet/index.js.map +1 -0
  41. package/lib/commonjs/index.js +17 -0
  42. package/lib/commonjs/index.js.map +1 -0
  43. package/lib/commonjs/package.json +1 -0
  44. package/lib/module/BottomSheet/animations/drag.animation.js +68 -0
  45. package/lib/module/BottomSheet/animations/drag.animation.js.map +1 -0
  46. package/lib/module/BottomSheet/components/BottomSheet.js +87 -0
  47. package/lib/module/BottomSheet/components/BottomSheet.js.map +1 -0
  48. package/lib/module/BottomSheet/components/BottomSheetFlatlist.js +32 -0
  49. package/lib/module/BottomSheet/components/BottomSheetFlatlist.js.map +1 -0
  50. package/lib/module/BottomSheet/components/BottomSheetModal.js +30 -0
  51. package/lib/module/BottomSheet/components/BottomSheetModal.js.map +1 -0
  52. package/lib/module/BottomSheet/components/BottomSheetScrollView.js +31 -0
  53. package/lib/module/BottomSheet/components/BottomSheetScrollView.js.map +1 -0
  54. package/lib/module/BottomSheet/config/bottomSheet.constants.js +30 -0
  55. package/lib/module/BottomSheet/config/bottomSheet.constants.js.map +1 -0
  56. package/lib/module/BottomSheet/config/bottomSheet.styles.js +38 -0
  57. package/lib/module/BottomSheet/config/bottomSheet.styles.js.map +1 -0
  58. package/lib/module/BottomSheet/config/bottomSheet.types.js +10 -0
  59. package/lib/module/BottomSheet/config/bottomSheet.types.js.map +1 -0
  60. package/lib/module/BottomSheet/controller/bottomFlatlist.controller.js +64 -0
  61. package/lib/module/BottomSheet/controller/bottomFlatlist.controller.js.map +1 -0
  62. package/lib/module/BottomSheet/controller/bottomScrollView.controller.js +37 -0
  63. package/lib/module/BottomSheet/controller/bottomScrollView.controller.js.map +1 -0
  64. package/lib/module/BottomSheet/controller/bottomSheet.controller.js +212 -0
  65. package/lib/module/BottomSheet/controller/bottomSheet.controller.js.map +1 -0
  66. package/lib/module/BottomSheet/controller/callbacks.controller.js +130 -0
  67. package/lib/module/BottomSheet/controller/callbacks.controller.js.map +1 -0
  68. package/lib/module/BottomSheet/controller/dragAnimation.controller.js +122 -0
  69. package/lib/module/BottomSheet/controller/dragAnimation.controller.js.map +1 -0
  70. package/lib/module/BottomSheet/controller/hooks/useBottomSheetRef.js +56 -0
  71. package/lib/module/BottomSheet/controller/hooks/useBottomSheetRef.js.map +1 -0
  72. package/lib/module/BottomSheet/controller/hooks/useBottomSheetUtils.js +70 -0
  73. package/lib/module/BottomSheet/controller/hooks/useBottomSheetUtils.js.map +1 -0
  74. package/lib/module/BottomSheet/controller/index.js +4 -0
  75. package/lib/module/BottomSheet/controller/index.js.map +1 -0
  76. package/lib/module/BottomSheet/controller/keyboardAnimation.controller.js +84 -0
  77. package/lib/module/BottomSheet/controller/keyboardAnimation.controller.js.map +1 -0
  78. package/lib/module/BottomSheet/controller/scrollContent.controller.js +84 -0
  79. package/lib/module/BottomSheet/controller/scrollContent.controller.js.map +1 -0
  80. package/lib/module/BottomSheet/index.js +112 -0
  81. package/lib/module/BottomSheet/index.js.map +1 -0
  82. package/lib/module/index.js +4 -0
  83. package/lib/module/index.js.map +1 -0
  84. package/lib/module/package.json +1 -0
  85. package/lib/typescript/commonjs/package.json +1 -0
  86. package/lib/typescript/commonjs/src/BottomSheet/animations/drag.animation.d.ts +31 -0
  87. package/lib/typescript/commonjs/src/BottomSheet/animations/drag.animation.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/src/BottomSheet/components/BottomSheet.d.ts +9 -0
  89. package/lib/typescript/commonjs/src/BottomSheet/components/BottomSheet.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/src/BottomSheet/components/BottomSheetFlatlist.d.ts +3 -0
  91. package/lib/typescript/commonjs/src/BottomSheet/components/BottomSheetFlatlist.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/src/BottomSheet/components/BottomSheetModal.d.ts +8 -0
  93. package/lib/typescript/commonjs/src/BottomSheet/components/BottomSheetModal.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/src/BottomSheet/components/BottomSheetScrollView.d.ts +3 -0
  95. package/lib/typescript/commonjs/src/BottomSheet/components/BottomSheetScrollView.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/src/BottomSheet/config/bottomSheet.constants.d.ts +30 -0
  97. package/lib/typescript/commonjs/src/BottomSheet/config/bottomSheet.constants.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/src/BottomSheet/config/bottomSheet.styles.d.ts +37 -0
  99. package/lib/typescript/commonjs/src/BottomSheet/config/bottomSheet.styles.d.ts.map +1 -0
  100. package/lib/typescript/commonjs/src/BottomSheet/config/bottomSheet.types.d.ts +185 -0
  101. package/lib/typescript/commonjs/src/BottomSheet/config/bottomSheet.types.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/src/BottomSheet/controller/bottomFlatlist.controller.d.ts +480 -0
  103. package/lib/typescript/commonjs/src/BottomSheet/controller/bottomFlatlist.controller.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/src/BottomSheet/controller/bottomScrollView.controller.d.ts +338 -0
  105. package/lib/typescript/commonjs/src/BottomSheet/controller/bottomScrollView.controller.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/src/BottomSheet/controller/bottomSheet.controller.d.ts +51 -0
  107. package/lib/typescript/commonjs/src/BottomSheet/controller/bottomSheet.controller.d.ts.map +1 -0
  108. package/lib/typescript/commonjs/src/BottomSheet/controller/callbacks.controller.d.ts +36 -0
  109. package/lib/typescript/commonjs/src/BottomSheet/controller/callbacks.controller.d.ts.map +1 -0
  110. package/lib/typescript/commonjs/src/BottomSheet/controller/dragAnimation.controller.d.ts +27 -0
  111. package/lib/typescript/commonjs/src/BottomSheet/controller/dragAnimation.controller.d.ts.map +1 -0
  112. package/lib/typescript/commonjs/src/BottomSheet/controller/hooks/useBottomSheetRef.d.ts +12 -0
  113. package/lib/typescript/commonjs/src/BottomSheet/controller/hooks/useBottomSheetRef.d.ts.map +1 -0
  114. package/lib/typescript/commonjs/src/BottomSheet/controller/hooks/useBottomSheetUtils.d.ts +40 -0
  115. package/lib/typescript/commonjs/src/BottomSheet/controller/hooks/useBottomSheetUtils.d.ts.map +1 -0
  116. package/lib/typescript/commonjs/src/BottomSheet/controller/index.d.ts +2 -0
  117. package/lib/typescript/commonjs/src/BottomSheet/controller/index.d.ts.map +1 -0
  118. package/lib/typescript/commonjs/src/BottomSheet/controller/keyboardAnimation.controller.d.ts +15 -0
  119. package/lib/typescript/commonjs/src/BottomSheet/controller/keyboardAnimation.controller.d.ts.map +1 -0
  120. package/lib/typescript/commonjs/src/BottomSheet/controller/scrollContent.controller.d.ts +20 -0
  121. package/lib/typescript/commonjs/src/BottomSheet/controller/scrollContent.controller.d.ts.map +1 -0
  122. package/lib/typescript/commonjs/src/BottomSheet/index.d.ts +23 -0
  123. package/lib/typescript/commonjs/src/BottomSheet/index.d.ts.map +1 -0
  124. package/lib/typescript/commonjs/src/index.d.ts +2 -0
  125. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  126. package/lib/typescript/module/package.json +1 -0
  127. package/lib/typescript/module/src/BottomSheet/animations/drag.animation.d.ts +31 -0
  128. package/lib/typescript/module/src/BottomSheet/animations/drag.animation.d.ts.map +1 -0
  129. package/lib/typescript/module/src/BottomSheet/components/BottomSheet.d.ts +9 -0
  130. package/lib/typescript/module/src/BottomSheet/components/BottomSheet.d.ts.map +1 -0
  131. package/lib/typescript/module/src/BottomSheet/components/BottomSheetFlatlist.d.ts +3 -0
  132. package/lib/typescript/module/src/BottomSheet/components/BottomSheetFlatlist.d.ts.map +1 -0
  133. package/lib/typescript/module/src/BottomSheet/components/BottomSheetModal.d.ts +8 -0
  134. package/lib/typescript/module/src/BottomSheet/components/BottomSheetModal.d.ts.map +1 -0
  135. package/lib/typescript/module/src/BottomSheet/components/BottomSheetScrollView.d.ts +3 -0
  136. package/lib/typescript/module/src/BottomSheet/components/BottomSheetScrollView.d.ts.map +1 -0
  137. package/lib/typescript/module/src/BottomSheet/config/bottomSheet.constants.d.ts +30 -0
  138. package/lib/typescript/module/src/BottomSheet/config/bottomSheet.constants.d.ts.map +1 -0
  139. package/lib/typescript/module/src/BottomSheet/config/bottomSheet.styles.d.ts +37 -0
  140. package/lib/typescript/module/src/BottomSheet/config/bottomSheet.styles.d.ts.map +1 -0
  141. package/lib/typescript/module/src/BottomSheet/config/bottomSheet.types.d.ts +185 -0
  142. package/lib/typescript/module/src/BottomSheet/config/bottomSheet.types.d.ts.map +1 -0
  143. package/lib/typescript/module/src/BottomSheet/controller/bottomFlatlist.controller.d.ts +480 -0
  144. package/lib/typescript/module/src/BottomSheet/controller/bottomFlatlist.controller.d.ts.map +1 -0
  145. package/lib/typescript/module/src/BottomSheet/controller/bottomScrollView.controller.d.ts +338 -0
  146. package/lib/typescript/module/src/BottomSheet/controller/bottomScrollView.controller.d.ts.map +1 -0
  147. package/lib/typescript/module/src/BottomSheet/controller/bottomSheet.controller.d.ts +51 -0
  148. package/lib/typescript/module/src/BottomSheet/controller/bottomSheet.controller.d.ts.map +1 -0
  149. package/lib/typescript/module/src/BottomSheet/controller/callbacks.controller.d.ts +36 -0
  150. package/lib/typescript/module/src/BottomSheet/controller/callbacks.controller.d.ts.map +1 -0
  151. package/lib/typescript/module/src/BottomSheet/controller/dragAnimation.controller.d.ts +27 -0
  152. package/lib/typescript/module/src/BottomSheet/controller/dragAnimation.controller.d.ts.map +1 -0
  153. package/lib/typescript/module/src/BottomSheet/controller/hooks/useBottomSheetRef.d.ts +12 -0
  154. package/lib/typescript/module/src/BottomSheet/controller/hooks/useBottomSheetRef.d.ts.map +1 -0
  155. package/lib/typescript/module/src/BottomSheet/controller/hooks/useBottomSheetUtils.d.ts +40 -0
  156. package/lib/typescript/module/src/BottomSheet/controller/hooks/useBottomSheetUtils.d.ts.map +1 -0
  157. package/lib/typescript/module/src/BottomSheet/controller/index.d.ts +2 -0
  158. package/lib/typescript/module/src/BottomSheet/controller/index.d.ts.map +1 -0
  159. package/lib/typescript/module/src/BottomSheet/controller/keyboardAnimation.controller.d.ts +15 -0
  160. package/lib/typescript/module/src/BottomSheet/controller/keyboardAnimation.controller.d.ts.map +1 -0
  161. package/lib/typescript/module/src/BottomSheet/controller/scrollContent.controller.d.ts +20 -0
  162. package/lib/typescript/module/src/BottomSheet/controller/scrollContent.controller.d.ts.map +1 -0
  163. package/lib/typescript/module/src/BottomSheet/index.d.ts +23 -0
  164. package/lib/typescript/module/src/BottomSheet/index.d.ts.map +1 -0
  165. package/lib/typescript/module/src/index.d.ts +2 -0
  166. package/lib/typescript/module/src/index.d.ts.map +1 -0
  167. package/package.json +203 -0
  168. package/src/BottomSheet/animations/drag.animation.ts +86 -0
  169. package/src/BottomSheet/components/BottomSheet.tsx +157 -0
  170. package/src/BottomSheet/components/BottomSheetFlatlist.tsx +46 -0
  171. package/src/BottomSheet/components/BottomSheetModal.tsx +47 -0
  172. package/src/BottomSheet/components/BottomSheetScrollView.tsx +46 -0
  173. package/src/BottomSheet/config/bottomSheet.constants.ts +31 -0
  174. package/src/BottomSheet/config/bottomSheet.styles.ts +42 -0
  175. package/src/BottomSheet/config/bottomSheet.types.ts +246 -0
  176. package/src/BottomSheet/controller/bottomFlatlist.controller.ts +87 -0
  177. package/src/BottomSheet/controller/bottomScrollView.controller.ts +43 -0
  178. package/src/BottomSheet/controller/bottomSheet.controller.ts +238 -0
  179. package/src/BottomSheet/controller/callbacks.controller.ts +222 -0
  180. package/src/BottomSheet/controller/dragAnimation.controller.ts +211 -0
  181. package/src/BottomSheet/controller/hooks/useBottomSheetRef.ts +73 -0
  182. package/src/BottomSheet/controller/hooks/useBottomSheetUtils.ts +75 -0
  183. package/src/BottomSheet/controller/index.ts +1 -0
  184. package/src/BottomSheet/controller/keyboardAnimation.controller.ts +148 -0
  185. package/src/BottomSheet/controller/scrollContent.controller.ts +120 -0
  186. package/src/BottomSheet/index.tsx +139 -0
  187. package/src/index.tsx +1 -0
@@ -0,0 +1,148 @@
1
+ import { useCallback, useRef } from 'react';
2
+ import { runOnUI, type SharedValue, withTiming } from 'react-native-reanimated';
3
+ import {
4
+ closeKeyboardTimingConfig,
5
+ openKeyboardTimingConfig,
6
+ } from '../config/bottomSheet.constants';
7
+ import { type KeyboardEvent, type TextInput } from 'react-native';
8
+ import {
9
+ isAndroid,
10
+ isIOS,
11
+ useKeyboardListeners,
12
+ wait,
13
+ } from '@shaquillehinds/react-native-essentials';
14
+
15
+ type UseKeyboardAnimationProps = {
16
+ avoidKeyboard?: boolean;
17
+ screenHeight: number;
18
+ inputsForKeyboardToAvoid?: React.RefObject<TextInput>[];
19
+ keyboardHeight: SharedValue<number>;
20
+ translationY: SharedValue<number>;
21
+ prevTranslationY: SharedValue<number>;
22
+ modalContentTranslateY: SharedValue<number>;
23
+ setDisableLayoutAnimation: (bool: boolean) => void;
24
+ };
25
+
26
+ export function keyboardAnimationController(props: UseKeyboardAnimationProps) {
27
+ const {
28
+ translationY,
29
+ prevTranslationY,
30
+ modalContentTranslateY,
31
+ keyboardHeight,
32
+ } = props;
33
+
34
+ const keyboardHeightRef = useRef(0);
35
+
36
+ const setKeyboardHeight = useCallback((height: number) => {
37
+ keyboardHeight.value = height;
38
+ keyboardHeightRef.current = height;
39
+ }, []);
40
+
41
+ const adjustForKeyboardHeight = useCallback(
42
+ (
43
+ currentKeyboardHeight: number,
44
+ previousKeyboardHeight: number,
45
+ screenHeight: number
46
+ ) => {
47
+ 'worklet';
48
+ const maxModalY = screenHeight * -1;
49
+ if (currentKeyboardHeight > 10) {
50
+ if (translationY.value <= maxModalY) {
51
+ modalContentTranslateY.value = withTiming(
52
+ -currentKeyboardHeight,
53
+ openKeyboardTimingConfig
54
+ );
55
+ } else {
56
+ const maxGap = maxModalY - translationY.value;
57
+ const height = translationY.value - currentKeyboardHeight;
58
+ if (height < maxModalY) {
59
+ const modalShift = translationY.value + maxGap;
60
+ translationY.value = withTiming(
61
+ modalShift,
62
+ openKeyboardTimingConfig
63
+ );
64
+ prevTranslationY.value = modalShift;
65
+ modalContentTranslateY.value = withTiming(
66
+ -currentKeyboardHeight - maxGap,
67
+ openKeyboardTimingConfig
68
+ );
69
+ } else {
70
+ translationY.value = withTiming(height, openKeyboardTimingConfig);
71
+ prevTranslationY.value = height;
72
+ }
73
+ }
74
+ } else {
75
+ const newTranslationY =
76
+ translationY.value +
77
+ (previousKeyboardHeight + modalContentTranslateY.value);
78
+ translationY.value = withTiming(
79
+ newTranslationY,
80
+ closeKeyboardTimingConfig
81
+ );
82
+ prevTranslationY.value = newTranslationY;
83
+ modalContentTranslateY.value = withTiming(0, closeKeyboardTimingConfig);
84
+ }
85
+ },
86
+ []
87
+ );
88
+
89
+ const keyBoardShowListener = useCallback(
90
+ async (e: KeyboardEvent, shouldAdjust?: boolean) => {
91
+ await wait(10);
92
+ if (keyboardHeightRef.current) return;
93
+ setKeyboardHeight(e.endCoordinates.height);
94
+ if (!shouldAdjust) return;
95
+ if (
96
+ props.inputsForKeyboardToAvoid &&
97
+ !props.inputsForKeyboardToAvoid.find((input) => {
98
+ return input.current?.isFocused();
99
+ })
100
+ )
101
+ return;
102
+ props.setDisableLayoutAnimation(true);
103
+ runOnUI(adjustForKeyboardHeight)(
104
+ keyboardHeightRef.current,
105
+ 0,
106
+ props.screenHeight
107
+ );
108
+ },
109
+ [props.screenHeight]
110
+ );
111
+
112
+ const keyboardHideListener = useCallback(
113
+ async (shouldAdjust?: boolean) => {
114
+ if (!keyboardHeightRef.current) return;
115
+ const previousKeyboardHeight = keyboardHeightRef.current;
116
+ setKeyboardHeight(0);
117
+ if (!shouldAdjust) return;
118
+ props.setDisableLayoutAnimation(false);
119
+ runOnUI(adjustForKeyboardHeight)(
120
+ keyboardHeightRef.current,
121
+ previousKeyboardHeight,
122
+ props.screenHeight
123
+ );
124
+ },
125
+ [props.screenHeight]
126
+ );
127
+
128
+ const shouldAdjustForKeyboard = !!(
129
+ props.avoidKeyboard || props.inputsForKeyboardToAvoid?.length
130
+ );
131
+ useKeyboardListeners({
132
+ listeners: {
133
+ keyboardWillShow: (e) => {
134
+ isIOS && keyBoardShowListener(e, shouldAdjustForKeyboard);
135
+ },
136
+ keyboardWillHide: () => {
137
+ isIOS && keyboardHideListener(shouldAdjustForKeyboard);
138
+ },
139
+ keyboardDidShow: (e) => {
140
+ isAndroid && keyBoardShowListener(e, shouldAdjustForKeyboard);
141
+ },
142
+ keyboardDidHide: async () => {
143
+ isAndroid && keyboardHideListener(shouldAdjustForKeyboard);
144
+ },
145
+ },
146
+ subscribeCondition: () => true,
147
+ });
148
+ }
@@ -0,0 +1,120 @@
1
+ //$lf-ignore
2
+ import {
3
+ runOnJS,
4
+ useSharedValue,
5
+ type SharedValue,
6
+ } from 'react-native-reanimated';
7
+ import type {
8
+ GestureStateChangeEvent,
9
+ GestureUpdateEvent,
10
+ PanGestureHandlerEventPayload,
11
+ } from 'react-native-gesture-handler';
12
+ import type { DragGestureProps } from '@shaquillehinds/react-native-essentials';
13
+ import type { ScrollComponentRef } from '../config/bottomSheet.types';
14
+ import { useCallback } from 'react';
15
+
16
+ type ScrollContentControllerType = {
17
+ scrollY: SharedValue<number>;
18
+ maxScrollOffset: SharedValue<number>;
19
+ inverted: SharedValue<boolean>;
20
+ scrollActive: SharedValue<boolean>;
21
+ onDragStartGesture: (
22
+ e: GestureStateChangeEvent<PanGestureHandlerEventPayload>
23
+ ) => void;
24
+ onDragEndGesture: (
25
+ e: GestureStateChangeEvent<PanGestureHandlerEventPayload>
26
+ ) => void;
27
+ onDragGesture: (e: GestureUpdateEvent<PanGestureHandlerEventPayload>) => void;
28
+ scrollableComponentRef?: ScrollComponentRef;
29
+ };
30
+
31
+ export function scrollContentController({
32
+ scrollActive,
33
+ scrollY,
34
+ onDragStartGesture,
35
+ onDragEndGesture,
36
+ onDragGesture,
37
+ maxScrollOffset,
38
+ inverted,
39
+ scrollableComponentRef,
40
+ }: ScrollContentControllerType) {
41
+ const enableScroll = (scrollEnabled: boolean, timeout?: number) => {
42
+ if (timeout)
43
+ setTimeout(
44
+ () =>
45
+ scrollableComponentRef?.current?.setNativeProps({ scrollEnabled }),
46
+ timeout
47
+ );
48
+ else scrollableComponentRef?.current?.setNativeProps({ scrollEnabled });
49
+ };
50
+ const dragEnabled = useSharedValue(false);
51
+ const initDragPos = useSharedValue(0);
52
+ const beginDragInit = useSharedValue(false);
53
+
54
+ const scrollEnabled = useSharedValue(true);
55
+
56
+ const onBeginScroll: DragGestureProps['onDragStart'] = useCallback((e) => {
57
+ 'worklet';
58
+ const maxPositionFromTopToEnableScroll = 15;
59
+ const isPositionFarFromTop = inverted.value
60
+ ? scrollY.value < maxScrollOffset.value - maxPositionFromTopToEnableScroll
61
+ : scrollY.value > maxPositionFromTopToEnableScroll;
62
+
63
+ if (isPositionFarFromTop) {
64
+ scrollActive.value = true;
65
+ } else {
66
+ beginDragInit.value = true;
67
+ onDragStartGesture(e);
68
+ }
69
+ }, []);
70
+ const onUpdateScroll: DragGestureProps['onDrag'] = useCallback(
71
+ (e) => {
72
+ 'worklet';
73
+ if (scrollActive.value) return;
74
+ if (dragEnabled.value) {
75
+ if (scrollEnabled.value) {
76
+ if (e.translationY < initDragPos.value) {
77
+ scrollEnabled.value = false;
78
+ runOnJS(enableScroll)(false);
79
+ }
80
+ initDragPos.value = e.translationY;
81
+ }
82
+ return onDragGesture(e);
83
+ }
84
+ if (beginDragInit.value) {
85
+ beginDragInit.value = false;
86
+ return;
87
+ }
88
+ if (
89
+ e.translationY > -400 &&
90
+ (inverted.value
91
+ ? Math.round(scrollY.value) >= Math.round(maxScrollOffset.value)
92
+ : scrollY.value <= 0)
93
+ ) {
94
+ if (!dragEnabled.value) {
95
+ initDragPos.value = e.translationY;
96
+ dragEnabled.value = true;
97
+ onDragGesture(e);
98
+ }
99
+ } else if (scrollY.value > 0) {
100
+ scrollActive.value = true;
101
+ }
102
+ },
103
+ [enableScroll]
104
+ );
105
+ const onEndScroll: NonNullable<DragGestureProps['onDragEnd']> = useCallback(
106
+ (e) => {
107
+ 'worklet';
108
+ if (!scrollActive.value) {
109
+ onDragEndGesture(e);
110
+ runOnJS(enableScroll)(true);
111
+ } else runOnJS(enableScroll)(true);
112
+ scrollActive.value = false;
113
+ dragEnabled.value = false;
114
+ scrollEnabled.value = true;
115
+ },
116
+ [enableScroll]
117
+ );
118
+
119
+ return { onBeginScroll, onUpdateScroll, onEndScroll };
120
+ }
@@ -0,0 +1,139 @@
1
+ import {
2
+ createContext,
3
+ forwardRef,
4
+ useContext,
5
+ type PropsWithChildren,
6
+ } from 'react';
7
+ import { BottomSheetModal as BottomSheetModalComponent } from './components/BottomSheetModal';
8
+ import {
9
+ type BottomSheetProps,
10
+ type BottomSheetModalProps,
11
+ type BottomModalRefObject,
12
+ type BottomSheetRefObject,
13
+ type BottomModalContextProps,
14
+ } from './config/bottomSheet.types';
15
+ import { BottomSheet as BottomSheetComponent } from './components/BottomSheet';
16
+ import { BottomSheetFlatlist } from './components/BottomSheetFlatlist';
17
+ import { BottomSheetScrollView } from './components/BottomSheetScrollView';
18
+ import { bottomSheetController } from './controller';
19
+ import { useBottomSheetRef as useBottomSheetRefs } from './controller/hooks/useBottomSheetRef';
20
+ import { animateCloseTimingConfig } from './config/bottomSheet.constants';
21
+ import {
22
+ usePortalComponent,
23
+ ComponentMounter,
24
+ ModalWrapper,
25
+ } from '@shaquillehinds/react-native-essentials';
26
+
27
+ export const BottomModalContext = createContext<BottomModalContextProps | null>(
28
+ null
29
+ );
30
+
31
+ const BottomSheetModal = forwardRef(
32
+ (
33
+ props: PropsWithChildren<BottomSheetModalProps>,
34
+ ref: BottomModalRefObject
35
+ ) => {
36
+ const { mounterRef, sheetRef, modalRef } = useBottomSheetRefs({
37
+ ref,
38
+ showModal: props.showModal,
39
+ setShowModal: props.setShowModal,
40
+ });
41
+ const Modal = (
42
+ <BottomModalContext.Provider value={{ modalRef }}>
43
+ <ComponentMounter
44
+ ref={mounterRef}
45
+ showComponent={props.showModal}
46
+ setShowComponent={props.setShowModal}
47
+ unMountDelayInMilliSeconds={animateCloseTimingConfig.duration}
48
+ onComponentShow={props.onModalShow}
49
+ onComponentClose={props.onModalClose}
50
+ component={
51
+ <BottomSheetModalComponent
52
+ {...props}
53
+ _unMounter={() => mounterRef.current?.unMountComponent()}
54
+ ref={sheetRef}
55
+ />
56
+ }
57
+ />
58
+ </BottomModalContext.Provider>
59
+ );
60
+ const portal = usePortalComponent({
61
+ Component: Modal,
62
+ name: 'smooth-bottom-modal',
63
+ disable: props.disablePortal || props.useNativeModal,
64
+ CustomPortalContext: props.CustomPortalContext,
65
+ });
66
+ if (portal && !props.disablePortal && !props.useNativeModal) {
67
+ return <></>;
68
+ } else {
69
+ return Modal;
70
+ }
71
+ }
72
+ );
73
+
74
+ const BottomSheetControl = forwardRef(
75
+ (props: PropsWithChildren<BottomSheetProps>, ref: BottomSheetRefObject) => {
76
+ const controller = bottomSheetController(props);
77
+ return (
78
+ <ModalWrapper enableBackgroundContentPress>
79
+ <BottomSheetComponent {...props} controller={controller} ref={ref} />
80
+ </ModalWrapper>
81
+ );
82
+ }
83
+ );
84
+
85
+ const BottomSheet = forwardRef(
86
+ (
87
+ props: PropsWithChildren<BottomSheetModalProps>,
88
+ ref: BottomModalRefObject
89
+ ) => {
90
+ const { mounterRef, sheetRef, modalRef } = useBottomSheetRefs({
91
+ ref,
92
+ showModal: props.showModal,
93
+ setShowModal: props.setShowModal,
94
+ });
95
+ const Modal = (
96
+ <BottomModalContext.Provider value={{ modalRef }}>
97
+ <ComponentMounter
98
+ ref={mounterRef}
99
+ showComponent={props.showModal}
100
+ setShowComponent={props.setShowModal}
101
+ unMountDelayInMilliSeconds={animateCloseTimingConfig.duration}
102
+ onComponentShow={props.onModalShow}
103
+ onComponentClose={props.onModalClose}
104
+ component={
105
+ <BottomSheetControl
106
+ {...props}
107
+ _unMounter={() => mounterRef.current?.unMountComponent()}
108
+ ref={sheetRef}
109
+ />
110
+ }
111
+ />
112
+ </BottomModalContext.Provider>
113
+ );
114
+ const portal = usePortalComponent({
115
+ Component: Modal,
116
+ name: 'smooth-bottom-modal',
117
+ disable: props.disablePortal || props.useNativeModal,
118
+ CustomPortalContext: props.CustomPortalContext,
119
+ });
120
+ if (portal && !props.disablePortal && !props.useNativeModal) {
121
+ return <></>;
122
+ } else {
123
+ return Modal;
124
+ }
125
+ }
126
+ );
127
+
128
+ const useBottomSheetRef = () => {
129
+ const context = useContext(BottomModalContext);
130
+ return { modalRef: context?.modalRef };
131
+ };
132
+
133
+ export {
134
+ BottomSheet,
135
+ BottomSheetModal,
136
+ BottomSheetFlatlist,
137
+ BottomSheetScrollView,
138
+ useBottomSheetRef,
139
+ };
package/src/index.tsx ADDED
@@ -0,0 +1 @@
1
+ export * from './BottomSheet';