@jamadd/react-native-template-ui 0.8.5 → 0.8.7

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 (248) hide show
  1. package/lib/module/components/button/AnimatedThemedPressable.js +13 -3
  2. package/lib/module/components/button/AnimatedThemedPressable.js.map +1 -1
  3. package/lib/module/components/button/ThemedButton.js +84 -23
  4. package/lib/module/components/button/ThemedButton.js.map +1 -1
  5. package/lib/module/components/button/ThemedIconButton.js +62 -16
  6. package/lib/module/components/button/ThemedIconButton.js.map +1 -1
  7. package/lib/module/components/button/ThemedIconTextButton.js +118 -29
  8. package/lib/module/components/button/ThemedIconTextButton.js.map +1 -1
  9. package/lib/module/components/button/ThemedPressable.js +13 -3
  10. package/lib/module/components/button/ThemedPressable.js.map +1 -1
  11. package/lib/module/components/icon/ThemedIcon.js +56 -15
  12. package/lib/module/components/icon/ThemedIcon.js.map +1 -1
  13. package/lib/module/components/list/List.js +131 -39
  14. package/lib/module/components/list/List.js.map +1 -1
  15. package/lib/module/components/loading/ThemedLoading.js +50 -13
  16. package/lib/module/components/loading/ThemedLoading.js.map +1 -1
  17. package/lib/module/components/overlay/actionSheet/ActionSheet.js +64 -19
  18. package/lib/module/components/overlay/actionSheet/ActionSheet.js.map +1 -1
  19. package/lib/module/components/overlay/actionSheet/ActionSheet.web.js +76 -0
  20. package/lib/module/components/overlay/actionSheet/ActionSheet.web.js.map +1 -0
  21. package/lib/module/components/overlay/actionSheet/ActionSheetContentGesture.js +19 -8
  22. package/lib/module/components/overlay/actionSheet/ActionSheetContentGesture.js.map +1 -1
  23. package/lib/module/components/overlay/actionSheet/ActionSheetHeader.js +87 -31
  24. package/lib/module/components/overlay/actionSheet/ActionSheetHeader.js.map +1 -1
  25. package/lib/module/components/overlay/actionSheet/ActionSheetHeader.web.js +113 -0
  26. package/lib/module/components/overlay/actionSheet/ActionSheetHeader.web.js.map +1 -0
  27. package/lib/module/components/overlay/actionSheet/ActionSheetListView.js +69 -28
  28. package/lib/module/components/overlay/actionSheet/ActionSheetListView.js.map +1 -1
  29. package/lib/module/components/overlay/actionSheet/ActionSheetListViewContent.js +39 -14
  30. package/lib/module/components/overlay/actionSheet/ActionSheetListViewContent.js.map +1 -1
  31. package/lib/module/components/overlay/actionSheet/ActionSheetOptionList.js +58 -25
  32. package/lib/module/components/overlay/actionSheet/ActionSheetOptionList.js.map +1 -1
  33. package/lib/module/components/overlay/actionSheet/ActionSheetOptionListItem.js +45 -21
  34. package/lib/module/components/overlay/actionSheet/ActionSheetOptionListItem.js.map +1 -1
  35. package/lib/module/components/overlay/actionSheet/ActionSheetOptions.js +75 -32
  36. package/lib/module/components/overlay/actionSheet/ActionSheetOptions.js.map +1 -1
  37. package/lib/module/components/overlay/actionSheet/ActionSheetScrollView.js +72 -30
  38. package/lib/module/components/overlay/actionSheet/ActionSheetScrollView.js.map +1 -1
  39. package/lib/module/components/overlay/actionSheet/ActionSheetScrollViewContent.js +45 -18
  40. package/lib/module/components/overlay/actionSheet/ActionSheetScrollViewContent.js.map +1 -1
  41. package/lib/module/components/overlay/actionSheet/ActionSheetWrap.js +152 -36
  42. package/lib/module/components/overlay/actionSheet/ActionSheetWrap.js.map +1 -1
  43. package/lib/module/components/overlay/alert/Alert.js +142 -51
  44. package/lib/module/components/overlay/alert/Alert.js.map +1 -1
  45. package/lib/module/components/overlay/alert/AlertButton.js +62 -26
  46. package/lib/module/components/overlay/alert/AlertButton.js.map +1 -1
  47. package/lib/module/components/overlay/alert/AlertButtons.js +58 -23
  48. package/lib/module/components/overlay/alert/AlertButtons.js.map +1 -1
  49. package/lib/module/components/overlay/alert/AlertContent.js +76 -17
  50. package/lib/module/components/overlay/alert/AlertContent.js.map +1 -1
  51. package/lib/module/components/overlay/alert/AlertWrap.js +125 -43
  52. package/lib/module/components/overlay/alert/AlertWrap.js.map +1 -1
  53. package/lib/module/components/overlay/modal/ThemedLoadingModal.js +96 -21
  54. package/lib/module/components/overlay/modal/ThemedLoadingModal.js.map +1 -1
  55. package/lib/module/components/overlay/modal/ThemedModal.js +76 -23
  56. package/lib/module/components/overlay/modal/ThemedModal.js.map +1 -1
  57. package/lib/module/components/overlay/toast/ThemedToast.js +339 -90
  58. package/lib/module/components/overlay/toast/ThemedToast.js.map +1 -1
  59. package/lib/module/components/provider/GestureProvider.js +15 -3
  60. package/lib/module/components/provider/GestureProvider.js.map +1 -1
  61. package/lib/module/components/provider/InsetsProvider.js +15 -3
  62. package/lib/module/components/provider/InsetsProvider.js.map +1 -1
  63. package/lib/module/components/provider/ReactNativeTemplateProviders.js +23 -11
  64. package/lib/module/components/provider/ReactNativeTemplateProviders.js.map +1 -1
  65. package/lib/module/components/provider/ThemeProvider.js +15 -3
  66. package/lib/module/components/provider/ThemeProvider.js.map +1 -1
  67. package/lib/module/components/separator/ThemedSeparator.js +53 -14
  68. package/lib/module/components/separator/ThemedSeparator.js.map +1 -1
  69. package/lib/module/components/slider/Slider.js +625 -137
  70. package/lib/module/components/slider/Slider.js.map +1 -1
  71. package/lib/module/components/slider/ThemedSlider.js +178 -54
  72. package/lib/module/components/slider/ThemedSlider.js.map +1 -1
  73. package/lib/module/components/slider/ThemedSlider.web.js +206 -0
  74. package/lib/module/components/slider/ThemedSlider.web.js.map +1 -0
  75. package/lib/module/components/slider/ThemedSliderStepIndicator.js +40 -15
  76. package/lib/module/components/slider/ThemedSliderStepIndicator.js.map +1 -1
  77. package/lib/module/components/switch/ThemedSwitch.js +81 -21
  78. package/lib/module/components/switch/ThemedSwitch.js.map +1 -1
  79. package/lib/module/components/text/ThemedIconText.js +124 -35
  80. package/lib/module/components/text/ThemedIconText.js.map +1 -1
  81. package/lib/module/components/text/ThemedText.js +15 -3
  82. package/lib/module/components/text/ThemedText.js.map +1 -1
  83. package/lib/module/components/view/AnimatedThemedView.js +42 -11
  84. package/lib/module/components/view/AnimatedThemedView.js.map +1 -1
  85. package/lib/module/components/view/ThemedScreenWrap.js +144 -39
  86. package/lib/module/components/view/ThemedScreenWrap.js.map +1 -1
  87. package/lib/module/components/view/ThemedScreenWrap.web.js +111 -32
  88. package/lib/module/components/view/ThemedScreenWrap.web.js.map +1 -1
  89. package/lib/module/components/view/ThemedScrollView.js +126 -38
  90. package/lib/module/components/view/ThemedScrollView.js.map +1 -1
  91. package/lib/module/components/view/ThemedView.js +33 -10
  92. package/lib/module/components/view/ThemedView.js.map +1 -1
  93. package/lib/module/hooks/button.js +263 -84
  94. package/lib/module/hooks/button.js.map +1 -1
  95. package/lib/module/hooks/list.js +50 -10
  96. package/lib/module/hooks/list.js.map +1 -1
  97. package/lib/module/hooks/overlay.js +575 -187
  98. package/lib/module/hooks/overlay.js.map +1 -1
  99. package/lib/module/hooks/react.js +90 -27
  100. package/lib/module/hooks/react.js.map +1 -1
  101. package/lib/module/hooks/reanimated.js.map +1 -1
  102. package/lib/module/hooks/style.js +43 -18
  103. package/lib/module/hooks/style.js.map +1 -1
  104. package/lib/module/hooks/switch.js +182 -43
  105. package/lib/module/hooks/switch.js.map +1 -1
  106. package/lib/module/hooks/theme.js +17 -8
  107. package/lib/module/hooks/theme.js.map +1 -1
  108. package/lib/module/hooks/view.js +56 -14
  109. package/lib/module/hooks/view.js.map +1 -1
  110. package/lib/module/index.js +2 -2
  111. package/lib/module/index.js.map +1 -1
  112. package/lib/module/utils/reanimated/func.js +60 -10
  113. package/lib/module/utils/reanimated/func.js.map +1 -1
  114. package/lib/typescript/src/components/overlay/actionSheet/ActionSheet.web.d.ts +5 -0
  115. package/lib/typescript/src/components/overlay/actionSheet/ActionSheet.web.d.ts.map +1 -0
  116. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetContentGesture.d.ts +0 -2
  117. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetContentGesture.d.ts.map +1 -1
  118. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetHeader.d.ts +0 -2
  119. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetHeader.d.ts.map +1 -1
  120. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetHeader.web.d.ts +4 -0
  121. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetHeader.web.d.ts.map +1 -0
  122. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListView.d.ts +0 -2
  123. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListView.d.ts.map +1 -1
  124. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListViewContent.d.ts +0 -2
  125. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListViewContent.d.ts.map +1 -1
  126. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionList.d.ts +0 -2
  127. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionList.d.ts.map +1 -1
  128. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionListItem.d.ts +0 -2
  129. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionListItem.d.ts.map +1 -1
  130. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptions.d.ts +0 -2
  131. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptions.d.ts.map +1 -1
  132. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollView.d.ts +0 -2
  133. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollView.d.ts.map +1 -1
  134. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollViewContent.d.ts +0 -2
  135. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollViewContent.d.ts.map +1 -1
  136. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetWrap.d.ts +0 -2
  137. package/lib/typescript/src/components/overlay/actionSheet/ActionSheetWrap.d.ts.map +1 -1
  138. package/lib/typescript/src/components/slider/Slider.d.ts +3 -2
  139. package/lib/typescript/src/components/slider/Slider.d.ts.map +1 -1
  140. package/lib/typescript/src/components/slider/ThemedSlider.d.ts.map +1 -1
  141. package/lib/typescript/src/components/slider/ThemedSlider.web.d.ts +5 -0
  142. package/lib/typescript/src/components/slider/ThemedSlider.web.d.ts.map +1 -0
  143. package/lib/typescript/src/components/slider/ThemedSliderStepIndicator.d.ts +3 -2
  144. package/lib/typescript/src/components/slider/ThemedSliderStepIndicator.d.ts.map +1 -1
  145. package/lib/typescript/src/components/view/AnimatedView.d.ts +0 -2
  146. package/lib/typescript/src/components/view/AnimatedView.d.ts.map +1 -1
  147. package/lib/typescript/src/hooks/overlay.d.ts +0 -27
  148. package/lib/typescript/src/hooks/overlay.d.ts.map +1 -1
  149. package/lib/typescript/src/hooks/switch.d.ts +1 -20
  150. package/lib/typescript/src/hooks/switch.d.ts.map +1 -1
  151. package/lib/typescript/src/types/list.d.ts +1 -10
  152. package/lib/typescript/src/types/list.d.ts.map +1 -1
  153. package/lib/typescript/src/types/overlay.d.ts +1 -31
  154. package/lib/typescript/src/types/overlay.d.ts.map +1 -1
  155. package/lib/typescript/src/utils/overlay/const.d.ts +0 -33
  156. package/lib/typescript/src/utils/overlay/const.d.ts.map +1 -1
  157. package/lib/typescript/src/utils/reanimated/func.d.ts +1 -5
  158. package/lib/typescript/src/utils/reanimated/func.d.ts.map +1 -1
  159. package/lib/typescript/src/utils/switch/const.d.ts +1 -2
  160. package/lib/typescript/src/utils/switch/const.d.ts.map +1 -1
  161. package/package.json +14 -15
  162. package/src/components/button/AnimatedPressable.tsx +0 -7
  163. package/src/components/button/AnimatedThemedPressable.tsx +0 -12
  164. package/src/components/button/ThemedButton.tsx +0 -45
  165. package/src/components/button/ThemedIconButton.tsx +0 -33
  166. package/src/components/button/ThemedIconTextButton.tsx +0 -56
  167. package/src/components/button/ThemedPressable.tsx +0 -12
  168. package/src/components/icon/ThemedIcon.tsx +0 -31
  169. package/src/components/list/List.tsx +0 -55
  170. package/src/components/loading/ThemedLoading.tsx +0 -29
  171. package/src/components/overlay/actionSheet/ActionSheet.tsx +0 -31
  172. package/src/components/overlay/actionSheet/ActionSheetContentGesture.tsx +0 -15
  173. package/src/components/overlay/actionSheet/ActionSheetHeader.tsx +0 -72
  174. package/src/components/overlay/actionSheet/ActionSheetListView.tsx +0 -54
  175. package/src/components/overlay/actionSheet/ActionSheetListViewContent.tsx +0 -32
  176. package/src/components/overlay/actionSheet/ActionSheetOptionList.tsx +0 -51
  177. package/src/components/overlay/actionSheet/ActionSheetOptionListItem.tsx +0 -43
  178. package/src/components/overlay/actionSheet/ActionSheetOptions.tsx +0 -61
  179. package/src/components/overlay/actionSheet/ActionSheetScrollView.tsx +0 -57
  180. package/src/components/overlay/actionSheet/ActionSheetScrollViewContent.tsx +0 -38
  181. package/src/components/overlay/actionSheet/ActionSheetWrap.tsx +0 -75
  182. package/src/components/overlay/alert/Alert.tsx +0 -86
  183. package/src/components/overlay/alert/AlertButton.tsx +0 -41
  184. package/src/components/overlay/alert/AlertButtons.tsx +0 -32
  185. package/src/components/overlay/alert/AlertContent.tsx +0 -60
  186. package/src/components/overlay/alert/AlertWrap.tsx +0 -93
  187. package/src/components/overlay/modal/ThemedLoadingModal.tsx +0 -47
  188. package/src/components/overlay/modal/ThemedModal.tsx +0 -42
  189. package/src/components/overlay/toast/ThemedToast.tsx +0 -160
  190. package/src/components/provider/GestureProvider.tsx +0 -9
  191. package/src/components/provider/InsetsProvider.tsx +0 -11
  192. package/src/components/provider/ReactNativeTemplateProviders.tsx +0 -20
  193. package/src/components/provider/ThemeProvider.tsx +0 -8
  194. package/src/components/separator/ThemedSeparator.tsx +0 -24
  195. package/src/components/slider/Slider.tsx +0 -229
  196. package/src/components/slider/ThemedSlider.tsx +0 -103
  197. package/src/components/slider/ThemedSliderStepIndicator.tsx +0 -24
  198. package/src/components/switch/ThemedSwitch.tsx +0 -49
  199. package/src/components/text/Text.tsx +0 -7
  200. package/src/components/text/ThemedIconText.tsx +0 -58
  201. package/src/components/text/ThemedText.tsx +0 -7
  202. package/src/components/view/AnimatedThemedView.tsx +0 -18
  203. package/src/components/view/AnimatedView.tsx +0 -7
  204. package/src/components/view/Box.tsx +0 -7
  205. package/src/components/view/ThemedScreenWrap.tsx +0 -48
  206. package/src/components/view/ThemedScreenWrap.web.tsx +0 -41
  207. package/src/components/view/ThemedScrollView.tsx +0 -54
  208. package/src/components/view/ThemedView.tsx +0 -19
  209. package/src/hooks/button.ts +0 -152
  210. package/src/hooks/list.ts +0 -42
  211. package/src/hooks/overlay.ts +0 -471
  212. package/src/hooks/react.ts +0 -34
  213. package/src/hooks/reanimated.ts +0 -6
  214. package/src/hooks/separator.ts +0 -29
  215. package/src/hooks/style.ts +0 -79
  216. package/src/hooks/switch.ts +0 -119
  217. package/src/hooks/theme.ts +0 -65
  218. package/src/hooks/view.ts +0 -28
  219. package/src/index.ts +0 -59
  220. package/src/test/utils/const.ts +0 -9
  221. package/src/test/utils/func.ts +0 -55
  222. package/src/test/utils/testingLib.tsx +0 -17
  223. package/src/types/button.ts +0 -50
  224. package/src/types/global.d.ts +0 -5
  225. package/src/types/icon.ts +0 -21
  226. package/src/types/list.ts +0 -61
  227. package/src/types/loading.ts +0 -14
  228. package/src/types/overlay.ts +0 -216
  229. package/src/types/provider.ts +0 -6
  230. package/src/types/react.ts +0 -8
  231. package/src/types/reanimated.ts +0 -11
  232. package/src/types/separator.ts +0 -28
  233. package/src/types/slider.ts +0 -59
  234. package/src/types/style.ts +0 -26
  235. package/src/types/switch.ts +0 -31
  236. package/src/types/text.ts +0 -25
  237. package/src/types/theme.ts +0 -39
  238. package/src/types/view.ts +0 -58
  239. package/src/utils/button/const.ts +0 -10
  240. package/src/utils/overlay/const.ts +0 -77
  241. package/src/utils/overlay/func.ts +0 -107
  242. package/src/utils/reanimated/func.ts +0 -39
  243. package/src/utils/slider/const.ts +0 -23
  244. package/src/utils/style/const.ts +0 -4
  245. package/src/utils/style/func.ts +0 -37
  246. package/src/utils/switch/const.ts +0 -2
  247. package/src/utils/theme/const.ts +0 -189
  248. package/src/utils/theme/restyle.ts +0 -87
@@ -1,152 +0,0 @@
1
- import { useRestyle } from '@shopify/restyle';
2
- import { useCallback, useEffect, useMemo, useRef } from 'react';
3
- import type {
4
- AnimatedPressableProps,
5
- AnimatedThemedPressableProps,
6
- OnPressDelayConfig,
7
- PressableOnPress,
8
- PressableProps,
9
- ThemedPressableProps,
10
- } from '../types/button';
11
- import type { Timeout } from '../types/react';
12
- import { ButtonScaleRatio, OnPressDelayType } from '../utils/button/const';
13
- import { composeStyles } from '../utils/style/func';
14
- import {
15
- animatedThemedPressableRestyleFuncs,
16
- themedPressableRestyleFuncs,
17
- } from '../utils/theme/restyle';
18
-
19
- export function useDelayedOnPress(
20
- onPress: PressableOnPress | null,
21
- onPressDelayConfig?: OnPressDelayConfig
22
- ) {
23
- const onPressTimestamp = useRef(0);
24
- const debounceTimeout = useRef<Timeout>(undefined);
25
- const clearDebounceTimeout = useCallback(() => {
26
- if (debounceTimeout.current) {
27
- clearTimeout(debounceTimeout.current);
28
- }
29
- }, [debounceTimeout]);
30
- useEffect(() => {
31
- return () => {
32
- clearDebounceTimeout();
33
- };
34
- }, []);
35
-
36
- return useMemo<PressableOnPress>(() => {
37
- const tempOnPress =
38
- onPress ??
39
- (() => {
40
- console.warn('onPress is not defined');
41
- });
42
- if (!onPressDelayConfig) {
43
- return tempOnPress;
44
- }
45
-
46
- const { type, wait } = onPressDelayConfig;
47
- switch (type) {
48
- case OnPressDelayType.Debounce:
49
- return (event) => {
50
- clearDebounceTimeout();
51
- debounceTimeout.current = setTimeout(() => {
52
- tempOnPress(event);
53
- }, wait);
54
- };
55
- case OnPressDelayType.Throttle:
56
- return (event) => {
57
- if (onPressTimestamp.current > Date.now()) {
58
- return;
59
- }
60
-
61
- tempOnPress(event);
62
- onPressTimestamp.current = Date.now() + wait;
63
- };
64
- default:
65
- return tempOnPress;
66
- }
67
- }, [
68
- onPress,
69
- onPressDelayConfig,
70
- onPressTimestamp,
71
- debounceTimeout,
72
- clearDebounceTimeout,
73
- ]);
74
- }
75
-
76
- function usePressableProps({
77
- onPress,
78
- scaleRatio = ButtonScaleRatio.None,
79
- onPressDelayConfig,
80
- style,
81
- }: Pick<
82
- PressableProps,
83
- 'onPress' | 'scaleRatio' | 'onPressDelayConfig' | 'style'
84
- >) {
85
- const pressableOnPress = useDelayedOnPress(
86
- onPress ?? null,
87
- onPressDelayConfig
88
- );
89
-
90
- const styleCb: PressableProps['style'] =
91
- typeof style === 'function' || scaleRatio === ButtonScaleRatio.None
92
- ? style
93
- : ({ pressed }) =>
94
- composeStyles(
95
- { transform: [{ scale: pressed ? scaleRatio : 1 }] },
96
- style
97
- );
98
- const pressableProps: PressableProps = {
99
- onPress: pressableOnPress,
100
- style: styleCb,
101
- };
102
-
103
- return pressableProps;
104
- }
105
-
106
- export function useThemedPressable({
107
- onPress,
108
- scaleRatio,
109
- onPressDelayConfig,
110
- ...props
111
- }: ThemedPressableProps) {
112
- const { style, ...restyle } = useRestyle(themedPressableRestyleFuncs, props);
113
- const pressableProps = usePressableProps({
114
- onPress,
115
- scaleRatio,
116
- onPressDelayConfig,
117
- style,
118
- });
119
-
120
- const themedPressableProps: ThemedPressableProps = {
121
- ...restyle,
122
- ...pressableProps,
123
- };
124
-
125
- return themedPressableProps;
126
- }
127
-
128
- export function useAnimatedThemedPressable({
129
- onPress,
130
- onPressDelayConfig,
131
- animatedStyle,
132
- ...props
133
- }: AnimatedThemedPressableProps) {
134
- const { style, ...restyle } = useRestyle(
135
- animatedThemedPressableRestyleFuncs,
136
- props
137
- );
138
- const pressableProps = usePressableProps({
139
- onPress,
140
- scaleRatio: ButtonScaleRatio.None,
141
- onPressDelayConfig,
142
- style,
143
- });
144
-
145
- const animatedThemedPressableProps: Omit<AnimatedPressableProps, 'key'> = {
146
- ...restyle,
147
- ...pressableProps,
148
- style: [pressableProps.style, animatedStyle],
149
- };
150
-
151
- return animatedThemedPressableProps;
152
- }
package/src/hooks/list.ts DELETED
@@ -1,42 +0,0 @@
1
- import { useRef } from 'react';
2
- import type {
3
- ListItemSeparatorComponent,
4
- ListItemSeparatorProps,
5
- ListRef,
6
- } from '../types/list';
7
- import { useThemedSeparator } from './separator';
8
-
9
- export function useListRef<T>() {
10
- return useRef<ListRef<T>>(null);
11
- }
12
-
13
- export function useListItemSeparatorComponent(
14
- props: ListItemSeparatorProps = {},
15
- hideForLeadingItemTypes: string[] = [],
16
- hideForTrailingItemTypes: string[] = []
17
- ) {
18
- const ThemedSeparator = useThemedSeparator(
19
- props.size,
20
- props.vertical,
21
- props.backgroundColor,
22
- props.style
23
- );
24
-
25
- const ListItemSeparatorComponent: ListItemSeparatorComponent = ({
26
- leadingItem,
27
- trailingItem,
28
- }) => {
29
- if (
30
- (typeof leadingItem === 'object' &&
31
- hideForLeadingItemTypes.includes(leadingItem.type)) ||
32
- (typeof trailingItem === 'object' &&
33
- hideForTrailingItemTypes.includes(trailingItem.type))
34
- ) {
35
- return null;
36
- }
37
-
38
- return ThemedSeparator;
39
- };
40
-
41
- return ListItemSeparatorComponent;
42
- }
@@ -1,471 +0,0 @@
1
- import { useContext, useEffect, useLayoutEffect, useState } from 'react';
2
- import type { ScrollView } from 'react-native';
3
- import { Gesture } from 'react-native-gesture-handler';
4
- import {
5
- makeMutable,
6
- useAnimatedRef,
7
- useScrollOffset,
8
- useSharedValue,
9
- withTiming,
10
- } from 'react-native-reanimated';
11
- import { scheduleOnRN } from 'react-native-worklets';
12
- import type { ListAnimatedRefObj, ListRef } from '../types/list';
13
- import type {
14
- ActionSheetContextVal,
15
- ActionSheetListViewProps,
16
- ActionSheetOption,
17
- ActionSheetOptionListProps,
18
- ActionSheetOptions,
19
- ActionSheetScrollViewProps,
20
- OverlayDismissActionSheetResult,
21
- OverlayOnDismiss,
22
- } from '../types/overlay';
23
- import type { ScrollViewAnimatedRefObj } from '../types/view';
24
- import {
25
- ActionSheetContext,
26
- actionSheetDismissDuration,
27
- actionSheetHeaderIconSize,
28
- actionSheetHeaderPadding,
29
- actionSheetOpenDuration,
30
- actionSheetOptionListItemPadding,
31
- actionSheetOptionListItemTextVariant,
32
- actionSheetSnapDuration,
33
- overlayDismissResultDefaultText,
34
- OverlayDismissResultType,
35
- } from '../utils/overlay/const';
36
- import {
37
- getActionSheetContext,
38
- getActionSheetExpandableHeight,
39
- getActionSheetExpandableInitHeight,
40
- getActionSheetExpandableSnapHeight,
41
- getActionSheetHeight,
42
- getActionSheetSnapHeight,
43
- } from '../utils/overlay/func';
44
- import { updateSharedValWithTiming } from '../utils/reanimated/func';
45
- import { useInsetsStyle, useWindowDimensionsHeight } from './style';
46
- import { useThemeSpacing, useThemeTextVariants } from './theme';
47
- import { useViewRef } from './view';
48
-
49
- /** @internal */
50
- export function useActionSheetContext() {
51
- return useContext(ActionSheetContext);
52
- }
53
-
54
- /** @internal */
55
- function useActionSheet(actionSheetVisible: boolean) {
56
- const windowHeight = useWindowDimensionsHeight();
57
- const headerViewRef = useViewRef();
58
- const [height, setHeight] = useState(0);
59
- const translateYSharedVal = useSharedValue(windowHeight);
60
- const heightSharedVal = useSharedValue(0);
61
- const expandableHeightSharedVal = useSharedValue(0);
62
- const { expandable } = getActionSheetContext();
63
- useEffect(() => {
64
- if (
65
- actionSheetVisible &&
66
- height &&
67
- translateYSharedVal.get() === windowHeight
68
- ) {
69
- const tempHeight = expandable
70
- ? getActionSheetExpandableInitHeight()
71
- : height;
72
- heightSharedVal.set(tempHeight);
73
- expandableHeightSharedVal.set(tempHeight);
74
- translateYSharedVal.set(height);
75
- updateSharedValWithTiming(translateYSharedVal, 0, {
76
- duration: actionSheetOpenDuration,
77
- });
78
- }
79
- }, [actionSheetVisible, height]);
80
-
81
- const updateHeight = (tempHeight: number) => {
82
- setHeight(
83
- expandable
84
- ? getActionSheetExpandableHeight()
85
- : getActionSheetHeight(tempHeight)
86
- );
87
- };
88
-
89
- const actionSheet = {
90
- headerViewRef,
91
- height,
92
- translateYSharedVal,
93
- heightSharedVal,
94
- expandableHeightSharedVal,
95
- updateHeight,
96
- };
97
-
98
- return actionSheet;
99
- }
100
-
101
- /** @internal */
102
- export function useActionSheetOnDismiss(force = true) {
103
- const windowHeight = useWindowDimensionsHeight();
104
- const {
105
- title,
106
- expandable,
107
- onDismiss,
108
- height,
109
- translateYSharedVal,
110
- heightSharedVal,
111
- expandableHeightSharedVal,
112
- } = useActionSheetContext();
113
- const actionSheetOnDismiss = (text = overlayDismissResultDefaultText) => {
114
- if (!height || !heightSharedVal || !translateYSharedVal) {
115
- return;
116
- }
117
-
118
- const tempTranslateYSharedVal =
119
- translateYSharedVal ?? makeMutable(windowHeight);
120
- const toVal = expandable
121
- ? getActionSheetExpandableSnapHeight(heightSharedVal.get(), force)
122
- : getActionSheetSnapHeight(
123
- height,
124
- translateYSharedVal?.get() ?? windowHeight,
125
- force
126
- );
127
- const dismissActionSheet = toVal === (expandable ? 0 : height);
128
- const animationConfig: Parameters<typeof withTiming>['1'] = {
129
- duration: dismissActionSheet
130
- ? actionSheetDismissDuration
131
- : actionSheetSnapDuration,
132
- };
133
- const cb = () => {
134
- if (!dismissActionSheet) {
135
- expandableHeightSharedVal?.set(toVal);
136
-
137
- return;
138
- }
139
-
140
- onDismiss?.({
141
- resultType: OverlayDismissResultType.ActionSheet,
142
- title,
143
- text,
144
- });
145
- };
146
- if (expandable && !dismissActionSheet) {
147
- updateSharedValWithTiming(heightSharedVal, toVal, animationConfig, cb);
148
- } else {
149
- updateSharedValWithTiming(
150
- tempTranslateYSharedVal,
151
- dismissActionSheet ? windowHeight : toVal,
152
- animationConfig,
153
- cb
154
- );
155
- }
156
- };
157
-
158
- return actionSheetOnDismiss;
159
- }
160
-
161
- /** @internal */
162
- export function useActionSheetGesture(contentGesture: boolean = false) {
163
- const onDismiss = useActionSheetOnDismiss(false);
164
-
165
- const {
166
- expandable,
167
- translateYSharedVal,
168
- heightSharedVal,
169
- contentOffsetSharedVal,
170
- } = getActionSheetContext();
171
- const actionSheetGesture = Gesture.Pan()
172
- .onChange(({ changeY }) => {
173
- if (!contentGesture || !contentOffsetSharedVal?.get()) {
174
- if (expandable) {
175
- heightSharedVal?.set(heightSharedVal.get() - changeY);
176
- } else {
177
- translateYSharedVal?.set(
178
- Math.max(translateYSharedVal!.get() + changeY, 0)
179
- );
180
- }
181
- }
182
- })
183
- .onEnd(() => {
184
- scheduleOnRN(onDismiss);
185
- });
186
-
187
- return actionSheetGesture;
188
- }
189
-
190
- /** @internal */
191
- export function useActionSheetHeaderMinHeight() {
192
- const themeSpacing = useThemeSpacing();
193
-
194
- const actionSheetHeaderMinHeight =
195
- actionSheetHeaderIconSize + themeSpacing[actionSheetHeaderPadding] * 2;
196
-
197
- return actionSheetHeaderMinHeight;
198
- }
199
-
200
- /** @internal */
201
- export function useActionSheetContentGesture() {
202
- const gesture = useActionSheetGesture(true);
203
-
204
- const scrollGesture = Gesture.Native().shouldActivateOnStart(true);
205
- const { contentOffsetSharedVal } = getActionSheetContext();
206
- const actionSheetContentGesture = Gesture.Simultaneous(
207
- scrollGesture,
208
- gesture.activeOffsetY(contentOffsetSharedVal?.get() ?? 0)
209
- );
210
-
211
- return actionSheetContentGesture;
212
- }
213
-
214
- export function useActionSheetListViewAnimatedRef<T>() {
215
- return useAnimatedRef<ListRef<T>>();
216
- }
217
-
218
- export function useActionSheetScrollViewAnimatedRef() {
219
- return useAnimatedRef<ScrollView>();
220
- }
221
-
222
- /** @interal */
223
- export function useActionSheetListViewRefAndOffset<T>(
224
- refObj?: ListAnimatedRefObj<T>
225
- ) {
226
- const listViewListAnimatedRefObj = useActionSheetListViewAnimatedRef<T>();
227
- const contentOffsetSharedVal = useScrollOffset(
228
- refObj ?? listViewListAnimatedRefObj
229
- );
230
-
231
- const actionSheetListViewAnimatedRef = {
232
- listViewListAnimatedRefObj: refObj ?? listViewListAnimatedRefObj,
233
- contentOffsetSharedVal,
234
- };
235
-
236
- return actionSheetListViewAnimatedRef;
237
- }
238
-
239
- /** @interal */
240
- export function useActionSheetScrollViewRefAndOffset(
241
- refObj?: ScrollViewAnimatedRefObj
242
- ) {
243
- const scrollViewAnimatedRefObj = useActionSheetScrollViewAnimatedRef();
244
- const contentOffsetSharedVal = useScrollOffset(
245
- refObj ?? scrollViewAnimatedRefObj
246
- );
247
-
248
- const actionSheetScrollViewAnimatedRef = {
249
- scrollViewAnimatedRefObj: refObj ?? scrollViewAnimatedRefObj,
250
- contentOffsetSharedVal,
251
- };
252
-
253
- return actionSheetScrollViewAnimatedRef;
254
- }
255
-
256
- /** @internal */
257
- export function useActionSheetVisible(visible = true) {
258
- const [actionSheetVisible, setActionSheetVisible] = useState(visible);
259
- useLayoutEffect(() => {
260
- setActionSheetVisible(visible);
261
- }, [visible]);
262
-
263
- return { actionSheetVisible, setActionSheetVisible };
264
- }
265
-
266
- /** @internal */
267
- export function useActionSheetOpts(
268
- title: string | undefined,
269
- expandable: boolean | undefined,
270
- options: ActionSheetOptions,
271
- optionListProps: ActionSheetOptionListProps | undefined,
272
- onDismiss: OverlayOnDismiss<OverlayDismissActionSheetResult> | undefined,
273
- dismissable: boolean | undefined,
274
- actionSheetVisible: boolean
275
- ) {
276
- const {
277
- headerViewRef,
278
- height,
279
- translateYSharedVal,
280
- heightSharedVal,
281
- expandableHeightSharedVal,
282
- updateHeight,
283
- } = useActionSheet(actionSheetVisible);
284
- const { listViewListAnimatedRefObj, contentOffsetSharedVal } =
285
- useActionSheetListViewRefAndOffset<ActionSheetOption>(optionListProps?.ref);
286
-
287
- const { itemSize, insetsStyle } = useActionSheetOptItemSize(optionListProps);
288
- useLayoutEffect(() => {
289
- if (!actionSheetVisible) {
290
- return;
291
- }
292
-
293
- headerViewRef.current?.measureInWindow((_x, _y, _width, headerHeight) => {
294
- const contentHeight =
295
- options.length * itemSize +
296
- ((insetsStyle.paddingBottom ?? 0) as number);
297
- updateHeight(headerHeight + contentHeight);
298
- });
299
- }, [actionSheetVisible]);
300
-
301
- const actionSheetContextVal: ActionSheetContextVal = {
302
- title,
303
- expandable,
304
- onDismiss,
305
- dismissable,
306
- headerViewRef,
307
- contentAnimatedRefObj: listViewListAnimatedRefObj,
308
- height,
309
- translateYSharedVal,
310
- heightSharedVal,
311
- expandableHeightSharedVal,
312
- contentOffsetSharedVal,
313
- };
314
-
315
- return actionSheetContextVal;
316
- }
317
-
318
- /** @internal */
319
- export function useActionSheetOptItemSize(
320
- {
321
- insets,
322
- insetTop,
323
- insetBottom,
324
- insetLeft,
325
- insetRight,
326
- insetsPadding,
327
- insetPaddingTop,
328
- insetPaddingBottom,
329
- insetPaddingLeft,
330
- insetPaddingRight,
331
- }: ActionSheetOptionListProps = {
332
- insetBottom: true,
333
- insetPaddingBottom: 'm',
334
- }
335
- ) {
336
- const themeSpacing = useThemeSpacing();
337
- const themeTextVariants = useThemeTextVariants();
338
- const insetsStyle = useInsetsStyle({
339
- insets,
340
- insetTop,
341
- insetBottom,
342
- insetLeft,
343
- insetRight,
344
- insetsPadding,
345
- insetPaddingTop,
346
- insetPaddingBottom,
347
- insetPaddingLeft,
348
- insetPaddingRight,
349
- });
350
-
351
- const actionSheetOptionItemSize = {
352
- itemSize:
353
- themeSpacing[actionSheetOptionListItemPadding] * 2 +
354
- themeTextVariants[actionSheetOptionListItemTextVariant].lineHeight,
355
- insetsStyle,
356
- };
357
-
358
- return actionSheetOptionItemSize;
359
- }
360
-
361
- /** @internal */
362
- export function useActionSheetScrollView(
363
- title: string | undefined,
364
- expandable: boolean | undefined,
365
- scrollViewProps: ActionSheetScrollViewProps['scrollViewProps'] | undefined,
366
- onDismiss: OverlayOnDismiss<OverlayDismissActionSheetResult> | undefined,
367
- dismissable: boolean | undefined,
368
- actionSheetVisible: boolean
369
- ) {
370
- const {
371
- headerViewRef,
372
- height,
373
- translateYSharedVal,
374
- heightSharedVal,
375
- expandableHeightSharedVal,
376
- updateHeight,
377
- } = useActionSheet(actionSheetVisible);
378
- const { scrollViewAnimatedRefObj, contentOffsetSharedVal } =
379
- useActionSheetScrollViewRefAndOffset(scrollViewProps?.ref);
380
- const [headerHeight, setHeaderHeight] = useState(0);
381
- const [contentHeight, setContentHeight] = useState(0);
382
- useLayoutEffect(() => {
383
- if (!actionSheetVisible) {
384
- return;
385
- }
386
-
387
- headerViewRef.current?.measureInWindow(
388
- (_x, _y, _width, headerViewHeight) => {
389
- setHeaderHeight(headerViewHeight);
390
- }
391
- );
392
- }, [actionSheetVisible]);
393
- useEffect(() => {
394
- if (headerHeight && contentHeight) {
395
- updateHeight(headerHeight + contentHeight);
396
- }
397
- }, [headerHeight, contentHeight]);
398
-
399
- const actionSheetContextVal: ActionSheetContextVal = {
400
- title,
401
- expandable,
402
- onDismiss,
403
- dismissable,
404
- headerViewRef,
405
- contentAnimatedRefObj: scrollViewAnimatedRefObj,
406
- height,
407
- setContentHeight,
408
- translateYSharedVal,
409
- heightSharedVal,
410
- expandableHeightSharedVal,
411
- contentOffsetSharedVal,
412
- };
413
-
414
- return actionSheetContextVal;
415
- }
416
-
417
- /** @internal */
418
- export function useActionSheetListView(
419
- title: string | undefined,
420
- expandable: boolean | undefined,
421
- listProps: ActionSheetListViewProps['listProps'] | undefined,
422
- onDismiss: OverlayOnDismiss<OverlayDismissActionSheetResult> | undefined,
423
- dismissable: boolean | undefined,
424
- actionSheetVisible: boolean
425
- ) {
426
- const {
427
- headerViewRef,
428
- height,
429
- translateYSharedVal,
430
- heightSharedVal,
431
- expandableHeightSharedVal,
432
- updateHeight,
433
- } = useActionSheet(actionSheetVisible);
434
- const { listViewListAnimatedRefObj, contentOffsetSharedVal } =
435
- useActionSheetListViewRefAndOffset(listProps?.ref);
436
- const [headerHeight, setHeaderHeight] = useState(0);
437
- const [contentHeight, setContentHeight] = useState(0);
438
- useLayoutEffect(() => {
439
- if (!actionSheetVisible) {
440
- return;
441
- }
442
-
443
- headerViewRef.current?.measureInWindow(
444
- (_x, _y, _width, headerViewHeight) => {
445
- setHeaderHeight(headerViewHeight);
446
- }
447
- );
448
- }, [actionSheetVisible]);
449
- useEffect(() => {
450
- if (headerHeight && contentHeight) {
451
- updateHeight(headerHeight + contentHeight);
452
- }
453
- }, [headerHeight, contentHeight]);
454
-
455
- const actionSheetContextVal: ActionSheetContextVal = {
456
- title,
457
- expandable,
458
- onDismiss,
459
- dismissable,
460
- headerViewRef,
461
- contentAnimatedRefObj: listViewListAnimatedRefObj,
462
- height,
463
- setContentHeight,
464
- translateYSharedVal,
465
- heightSharedVal,
466
- expandableHeightSharedVal,
467
- contentOffsetSharedVal,
468
- };
469
-
470
- return actionSheetContextVal;
471
- }
@@ -1,34 +0,0 @@
1
- import { useDeferredValue, useEffect, useRef, useState } from 'react';
2
-
3
- export function useTimeout() {
4
- const timeoutRef = useRef<number>(null);
5
- const clearTimeoutRef = () => {
6
- if (timeoutRef.current) {
7
- clearTimeout(timeoutRef.current);
8
- timeoutRef.current = null;
9
- }
10
- };
11
- useEffect(() => clearTimeoutRef, []);
12
-
13
- return { timeoutRef, clearTimeoutRef };
14
- }
15
-
16
- export function useInterval() {
17
- const intervalRef = useRef<number>(null);
18
- const clearIntervalRef = () => {
19
- if (intervalRef.current) {
20
- clearInterval(intervalRef.current);
21
- intervalRef.current = null;
22
- }
23
- };
24
- useEffect(() => clearIntervalRef, []);
25
-
26
- return { intervalRef, clearIntervalRef };
27
- }
28
-
29
- export function useDeferredState<T>(initialState?: T) {
30
- const [state, setState] = useState<T | undefined>(initialState);
31
- const deferredState = useDeferredValue(state);
32
-
33
- return { state, setState, deferredState };
34
- }
@@ -1,6 +0,0 @@
1
- import { useSharedValue } from 'react-native-reanimated';
2
- import type { AnimationValue } from '../types/reanimated';
3
-
4
- export function useAnimationSharedVal() {
5
- return useSharedValue<AnimationValue>(0);
6
- }