@jamadd/react-native-template-ui 0.8.4 → 0.8.5
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.
- package/package.json +2 -1
- package/src/components/button/AnimatedPressable.tsx +7 -0
- package/src/components/button/AnimatedThemedPressable.tsx +12 -0
- package/src/components/button/ThemedButton.tsx +45 -0
- package/src/components/button/ThemedIconButton.tsx +33 -0
- package/src/components/button/ThemedIconTextButton.tsx +56 -0
- package/src/components/button/ThemedPressable.tsx +12 -0
- package/src/components/icon/ThemedIcon.tsx +31 -0
- package/src/components/list/List.tsx +55 -0
- package/src/components/loading/ThemedLoading.tsx +29 -0
- package/src/components/overlay/actionSheet/ActionSheet.tsx +31 -0
- package/src/components/overlay/actionSheet/ActionSheetContentGesture.tsx +15 -0
- package/src/components/overlay/actionSheet/ActionSheetHeader.tsx +72 -0
- package/src/components/overlay/actionSheet/ActionSheetListView.tsx +54 -0
- package/src/components/overlay/actionSheet/ActionSheetListViewContent.tsx +32 -0
- package/src/components/overlay/actionSheet/ActionSheetOptionList.tsx +51 -0
- package/src/components/overlay/actionSheet/ActionSheetOptionListItem.tsx +43 -0
- package/src/components/overlay/actionSheet/ActionSheetOptions.tsx +61 -0
- package/src/components/overlay/actionSheet/ActionSheetScrollView.tsx +57 -0
- package/src/components/overlay/actionSheet/ActionSheetScrollViewContent.tsx +38 -0
- package/src/components/overlay/actionSheet/ActionSheetWrap.tsx +75 -0
- package/src/components/overlay/alert/Alert.tsx +86 -0
- package/src/components/overlay/alert/AlertButton.tsx +41 -0
- package/src/components/overlay/alert/AlertButtons.tsx +32 -0
- package/src/components/overlay/alert/AlertContent.tsx +60 -0
- package/src/components/overlay/alert/AlertWrap.tsx +93 -0
- package/src/components/overlay/modal/ThemedLoadingModal.tsx +47 -0
- package/src/components/overlay/modal/ThemedModal.tsx +42 -0
- package/src/components/overlay/toast/ThemedToast.tsx +160 -0
- package/src/components/provider/GestureProvider.tsx +9 -0
- package/src/components/provider/InsetsProvider.tsx +11 -0
- package/src/components/provider/ReactNativeTemplateProviders.tsx +20 -0
- package/src/components/provider/ThemeProvider.tsx +8 -0
- package/src/components/separator/ThemedSeparator.tsx +24 -0
- package/src/components/slider/Slider.tsx +229 -0
- package/src/components/slider/ThemedSlider.tsx +103 -0
- package/src/components/slider/ThemedSliderStepIndicator.tsx +24 -0
- package/src/components/switch/ThemedSwitch.tsx +49 -0
- package/src/components/text/Text.tsx +7 -0
- package/src/components/text/ThemedIconText.tsx +58 -0
- package/src/components/text/ThemedText.tsx +7 -0
- package/src/components/view/AnimatedThemedView.tsx +18 -0
- package/src/components/view/AnimatedView.tsx +7 -0
- package/src/components/view/Box.tsx +7 -0
- package/src/components/view/ThemedScreenWrap.tsx +48 -0
- package/src/components/view/ThemedScreenWrap.web.tsx +41 -0
- package/src/components/view/ThemedScrollView.tsx +54 -0
- package/src/components/view/ThemedView.tsx +19 -0
- package/src/hooks/button.ts +152 -0
- package/src/hooks/list.ts +42 -0
- package/src/hooks/overlay.ts +471 -0
- package/src/hooks/react.ts +34 -0
- package/src/hooks/reanimated.ts +6 -0
- package/src/hooks/separator.ts +29 -0
- package/src/hooks/style.ts +79 -0
- package/src/hooks/switch.ts +119 -0
- package/src/hooks/theme.ts +65 -0
- package/src/hooks/view.ts +28 -0
- package/src/index.ts +59 -0
- package/src/test/utils/const.ts +9 -0
- package/src/test/utils/func.ts +55 -0
- package/src/test/utils/testingLib.tsx +17 -0
- package/src/types/button.ts +50 -0
- package/src/types/global.d.ts +5 -0
- package/src/types/icon.ts +21 -0
- package/src/types/list.ts +61 -0
- package/src/types/loading.ts +14 -0
- package/src/types/overlay.ts +216 -0
- package/src/types/provider.ts +6 -0
- package/src/types/react.ts +8 -0
- package/src/types/reanimated.ts +11 -0
- package/src/types/separator.ts +28 -0
- package/src/types/slider.ts +59 -0
- package/src/types/style.ts +26 -0
- package/src/types/switch.ts +31 -0
- package/src/types/text.ts +25 -0
- package/src/types/theme.ts +39 -0
- package/src/types/view.ts +58 -0
- package/src/utils/button/const.ts +10 -0
- package/src/utils/overlay/const.ts +77 -0
- package/src/utils/overlay/func.ts +107 -0
- package/src/utils/reanimated/func.ts +39 -0
- package/src/utils/slider/const.ts +23 -0
- package/src/utils/style/const.ts +4 -0
- package/src/utils/style/func.ts +37 -0
- package/src/utils/switch/const.ts +2 -0
- package/src/utils/theme/const.ts +189 -0
- package/src/utils/theme/restyle.ts +87 -0
|
@@ -0,0 +1,471 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createElement, type FC } from 'react';
|
|
2
|
+
import type { ThemedSeparatorProps } from '../types/separator';
|
|
3
|
+
import type { ThemeColors } from '../types/theme';
|
|
4
|
+
import { BorderSize } from '../utils/theme/const';
|
|
5
|
+
|
|
6
|
+
// @internal
|
|
7
|
+
let ThemedSeparator: FC<ThemedSeparatorProps> | undefined;
|
|
8
|
+
|
|
9
|
+
export function useThemedSeparator(
|
|
10
|
+
size = BorderSize.S,
|
|
11
|
+
vertical = false,
|
|
12
|
+
backgroundColor: ThemeColors = 'separator',
|
|
13
|
+
style: Omit<
|
|
14
|
+
ThemedSeparatorProps,
|
|
15
|
+
'size' | 'vertical' | 'backgroundColor' | 'bg'
|
|
16
|
+
> = {}
|
|
17
|
+
) {
|
|
18
|
+
const props: ThemedSeparatorProps = {
|
|
19
|
+
size,
|
|
20
|
+
vertical,
|
|
21
|
+
backgroundColor,
|
|
22
|
+
...style,
|
|
23
|
+
};
|
|
24
|
+
ThemedSeparator ??=
|
|
25
|
+
require('../components/separator/ThemedSeparator').default;
|
|
26
|
+
const element = createElement(ThemedSeparator!, props);
|
|
27
|
+
|
|
28
|
+
return element;
|
|
29
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useWindowDimensions as useRNWindowDimensions,
|
|
3
|
+
type ViewStyle,
|
|
4
|
+
} from 'react-native';
|
|
5
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
|
+
import type { InsetsStyleConfig } from '../types/style';
|
|
7
|
+
import { Orientation } from '../utils/style/const';
|
|
8
|
+
import { useThemeSpacing } from './theme';
|
|
9
|
+
|
|
10
|
+
export function useInsetsStyle({
|
|
11
|
+
insets,
|
|
12
|
+
insetTop,
|
|
13
|
+
insetBottom,
|
|
14
|
+
insetLeft,
|
|
15
|
+
insetRight,
|
|
16
|
+
insetsPadding,
|
|
17
|
+
insetPaddingTop,
|
|
18
|
+
insetPaddingBottom,
|
|
19
|
+
insetPaddingLeft,
|
|
20
|
+
insetPaddingRight,
|
|
21
|
+
}: InsetsStyleConfig) {
|
|
22
|
+
const { top, bottom, left, right } = useSafeAreaInsets();
|
|
23
|
+
const spacing = useThemeSpacing();
|
|
24
|
+
|
|
25
|
+
const insetsStyle: Pick<
|
|
26
|
+
ViewStyle,
|
|
27
|
+
'paddingTop' | 'paddingBottom' | 'paddingLeft' | 'paddingRight'
|
|
28
|
+
> = JSON.parse(
|
|
29
|
+
JSON.stringify({
|
|
30
|
+
paddingTop:
|
|
31
|
+
(insetTop ?? insets)
|
|
32
|
+
? top + spacing[insetPaddingTop ?? insetsPadding ?? 'none']
|
|
33
|
+
: undefined,
|
|
34
|
+
paddingBottom:
|
|
35
|
+
(insetBottom ?? insets)
|
|
36
|
+
? bottom + spacing[insetPaddingBottom ?? insetsPadding ?? 'none']
|
|
37
|
+
: undefined,
|
|
38
|
+
paddingLeft:
|
|
39
|
+
(insetLeft ?? insets)
|
|
40
|
+
? left + spacing[insetPaddingLeft ?? insetsPadding ?? 'none']
|
|
41
|
+
: undefined,
|
|
42
|
+
paddingRight:
|
|
43
|
+
(insetRight ?? insets)
|
|
44
|
+
? right + spacing[insetPaddingRight ?? insetsPadding ?? 'none']
|
|
45
|
+
: undefined,
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return insetsStyle;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function useWindowDimensions() {
|
|
53
|
+
return useRNWindowDimensions();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function useWindowDimensionsWidth() {
|
|
57
|
+
return useWindowDimensions().width;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function useWindowDimensionsHeight() {
|
|
61
|
+
return useWindowDimensions().height;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function useWindowDimensionsScale() {
|
|
65
|
+
return useWindowDimensions().scale;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function useWindowDimensionsFontScale() {
|
|
69
|
+
return useWindowDimensions().fontScale;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function useOrientation() {
|
|
73
|
+
const { width, height } = useWindowDimensions();
|
|
74
|
+
|
|
75
|
+
const orientation =
|
|
76
|
+
width > height ? Orientation.Landscape : Orientation.Portrait;
|
|
77
|
+
|
|
78
|
+
return orientation;
|
|
79
|
+
}
|