@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.
- package/lib/module/components/button/AnimatedThemedPressable.js +13 -3
- package/lib/module/components/button/AnimatedThemedPressable.js.map +1 -1
- package/lib/module/components/button/ThemedButton.js +84 -23
- package/lib/module/components/button/ThemedButton.js.map +1 -1
- package/lib/module/components/button/ThemedIconButton.js +62 -16
- package/lib/module/components/button/ThemedIconButton.js.map +1 -1
- package/lib/module/components/button/ThemedIconTextButton.js +118 -29
- package/lib/module/components/button/ThemedIconTextButton.js.map +1 -1
- package/lib/module/components/button/ThemedPressable.js +13 -3
- package/lib/module/components/button/ThemedPressable.js.map +1 -1
- package/lib/module/components/icon/ThemedIcon.js +56 -15
- package/lib/module/components/icon/ThemedIcon.js.map +1 -1
- package/lib/module/components/list/List.js +131 -39
- package/lib/module/components/list/List.js.map +1 -1
- package/lib/module/components/loading/ThemedLoading.js +50 -13
- package/lib/module/components/loading/ThemedLoading.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheet.js +64 -19
- package/lib/module/components/overlay/actionSheet/ActionSheet.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheet.web.js +76 -0
- package/lib/module/components/overlay/actionSheet/ActionSheet.web.js.map +1 -0
- package/lib/module/components/overlay/actionSheet/ActionSheetContentGesture.js +19 -8
- package/lib/module/components/overlay/actionSheet/ActionSheetContentGesture.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheetHeader.js +87 -31
- package/lib/module/components/overlay/actionSheet/ActionSheetHeader.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheetHeader.web.js +113 -0
- package/lib/module/components/overlay/actionSheet/ActionSheetHeader.web.js.map +1 -0
- package/lib/module/components/overlay/actionSheet/ActionSheetListView.js +69 -28
- package/lib/module/components/overlay/actionSheet/ActionSheetListView.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheetListViewContent.js +39 -14
- package/lib/module/components/overlay/actionSheet/ActionSheetListViewContent.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheetOptionList.js +58 -25
- package/lib/module/components/overlay/actionSheet/ActionSheetOptionList.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheetOptionListItem.js +45 -21
- package/lib/module/components/overlay/actionSheet/ActionSheetOptionListItem.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheetOptions.js +75 -32
- package/lib/module/components/overlay/actionSheet/ActionSheetOptions.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheetScrollView.js +72 -30
- package/lib/module/components/overlay/actionSheet/ActionSheetScrollView.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheetScrollViewContent.js +45 -18
- package/lib/module/components/overlay/actionSheet/ActionSheetScrollViewContent.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheetWrap.js +152 -36
- package/lib/module/components/overlay/actionSheet/ActionSheetWrap.js.map +1 -1
- package/lib/module/components/overlay/alert/Alert.js +142 -51
- package/lib/module/components/overlay/alert/Alert.js.map +1 -1
- package/lib/module/components/overlay/alert/AlertButton.js +62 -26
- package/lib/module/components/overlay/alert/AlertButton.js.map +1 -1
- package/lib/module/components/overlay/alert/AlertButtons.js +58 -23
- package/lib/module/components/overlay/alert/AlertButtons.js.map +1 -1
- package/lib/module/components/overlay/alert/AlertContent.js +76 -17
- package/lib/module/components/overlay/alert/AlertContent.js.map +1 -1
- package/lib/module/components/overlay/alert/AlertWrap.js +125 -43
- package/lib/module/components/overlay/alert/AlertWrap.js.map +1 -1
- package/lib/module/components/overlay/modal/ThemedLoadingModal.js +96 -21
- package/lib/module/components/overlay/modal/ThemedLoadingModal.js.map +1 -1
- package/lib/module/components/overlay/modal/ThemedModal.js +76 -23
- package/lib/module/components/overlay/modal/ThemedModal.js.map +1 -1
- package/lib/module/components/overlay/toast/ThemedToast.js +339 -90
- package/lib/module/components/overlay/toast/ThemedToast.js.map +1 -1
- package/lib/module/components/provider/GestureProvider.js +15 -3
- package/lib/module/components/provider/GestureProvider.js.map +1 -1
- package/lib/module/components/provider/InsetsProvider.js +15 -3
- package/lib/module/components/provider/InsetsProvider.js.map +1 -1
- package/lib/module/components/provider/ReactNativeTemplateProviders.js +23 -11
- package/lib/module/components/provider/ReactNativeTemplateProviders.js.map +1 -1
- package/lib/module/components/provider/ThemeProvider.js +15 -3
- package/lib/module/components/provider/ThemeProvider.js.map +1 -1
- package/lib/module/components/separator/ThemedSeparator.js +53 -14
- package/lib/module/components/separator/ThemedSeparator.js.map +1 -1
- package/lib/module/components/slider/Slider.js +625 -137
- package/lib/module/components/slider/Slider.js.map +1 -1
- package/lib/module/components/slider/ThemedSlider.js +178 -54
- package/lib/module/components/slider/ThemedSlider.js.map +1 -1
- package/lib/module/components/slider/ThemedSlider.web.js +206 -0
- package/lib/module/components/slider/ThemedSlider.web.js.map +1 -0
- package/lib/module/components/slider/ThemedSliderStepIndicator.js +40 -15
- package/lib/module/components/slider/ThemedSliderStepIndicator.js.map +1 -1
- package/lib/module/components/switch/ThemedSwitch.js +81 -21
- package/lib/module/components/switch/ThemedSwitch.js.map +1 -1
- package/lib/module/components/text/ThemedIconText.js +124 -35
- package/lib/module/components/text/ThemedIconText.js.map +1 -1
- package/lib/module/components/text/ThemedText.js +15 -3
- package/lib/module/components/text/ThemedText.js.map +1 -1
- package/lib/module/components/view/AnimatedThemedView.js +42 -11
- package/lib/module/components/view/AnimatedThemedView.js.map +1 -1
- package/lib/module/components/view/ThemedScreenWrap.js +144 -39
- package/lib/module/components/view/ThemedScreenWrap.js.map +1 -1
- package/lib/module/components/view/ThemedScreenWrap.web.js +111 -32
- package/lib/module/components/view/ThemedScreenWrap.web.js.map +1 -1
- package/lib/module/components/view/ThemedScrollView.js +126 -38
- package/lib/module/components/view/ThemedScrollView.js.map +1 -1
- package/lib/module/components/view/ThemedView.js +33 -10
- package/lib/module/components/view/ThemedView.js.map +1 -1
- package/lib/module/hooks/button.js +263 -84
- package/lib/module/hooks/button.js.map +1 -1
- package/lib/module/hooks/list.js +50 -10
- package/lib/module/hooks/list.js.map +1 -1
- package/lib/module/hooks/overlay.js +575 -187
- package/lib/module/hooks/overlay.js.map +1 -1
- package/lib/module/hooks/react.js +90 -27
- package/lib/module/hooks/react.js.map +1 -1
- package/lib/module/hooks/reanimated.js.map +1 -1
- package/lib/module/hooks/style.js +43 -18
- package/lib/module/hooks/style.js.map +1 -1
- package/lib/module/hooks/switch.js +182 -43
- package/lib/module/hooks/switch.js.map +1 -1
- package/lib/module/hooks/theme.js +17 -8
- package/lib/module/hooks/theme.js.map +1 -1
- package/lib/module/hooks/view.js +56 -14
- package/lib/module/hooks/view.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/reanimated/func.js +60 -10
- package/lib/module/utils/reanimated/func.js.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheet.web.d.ts +5 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheet.web.d.ts.map +1 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetContentGesture.d.ts +0 -2
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetContentGesture.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetHeader.d.ts +0 -2
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetHeader.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetHeader.web.d.ts +4 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetHeader.web.d.ts.map +1 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListView.d.ts +0 -2
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListView.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListViewContent.d.ts +0 -2
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListViewContent.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionList.d.ts +0 -2
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionList.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionListItem.d.ts +0 -2
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionListItem.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptions.d.ts +0 -2
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptions.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollView.d.ts +0 -2
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollView.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollViewContent.d.ts +0 -2
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollViewContent.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetWrap.d.ts +0 -2
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetWrap.d.ts.map +1 -1
- package/lib/typescript/src/components/slider/Slider.d.ts +3 -2
- package/lib/typescript/src/components/slider/Slider.d.ts.map +1 -1
- package/lib/typescript/src/components/slider/ThemedSlider.d.ts.map +1 -1
- package/lib/typescript/src/components/slider/ThemedSlider.web.d.ts +5 -0
- package/lib/typescript/src/components/slider/ThemedSlider.web.d.ts.map +1 -0
- package/lib/typescript/src/components/slider/ThemedSliderStepIndicator.d.ts +3 -2
- package/lib/typescript/src/components/slider/ThemedSliderStepIndicator.d.ts.map +1 -1
- package/lib/typescript/src/components/view/AnimatedView.d.ts +0 -2
- package/lib/typescript/src/components/view/AnimatedView.d.ts.map +1 -1
- package/lib/typescript/src/hooks/overlay.d.ts +0 -27
- package/lib/typescript/src/hooks/overlay.d.ts.map +1 -1
- package/lib/typescript/src/hooks/switch.d.ts +1 -20
- package/lib/typescript/src/hooks/switch.d.ts.map +1 -1
- package/lib/typescript/src/types/list.d.ts +1 -10
- package/lib/typescript/src/types/list.d.ts.map +1 -1
- package/lib/typescript/src/types/overlay.d.ts +1 -31
- package/lib/typescript/src/types/overlay.d.ts.map +1 -1
- package/lib/typescript/src/utils/overlay/const.d.ts +0 -33
- package/lib/typescript/src/utils/overlay/const.d.ts.map +1 -1
- package/lib/typescript/src/utils/reanimated/func.d.ts +1 -5
- package/lib/typescript/src/utils/reanimated/func.d.ts.map +1 -1
- package/lib/typescript/src/utils/switch/const.d.ts +1 -2
- package/lib/typescript/src/utils/switch/const.d.ts.map +1 -1
- package/package.json +14 -15
- package/src/components/button/AnimatedPressable.tsx +0 -7
- package/src/components/button/AnimatedThemedPressable.tsx +0 -12
- package/src/components/button/ThemedButton.tsx +0 -45
- package/src/components/button/ThemedIconButton.tsx +0 -33
- package/src/components/button/ThemedIconTextButton.tsx +0 -56
- package/src/components/button/ThemedPressable.tsx +0 -12
- package/src/components/icon/ThemedIcon.tsx +0 -31
- package/src/components/list/List.tsx +0 -55
- package/src/components/loading/ThemedLoading.tsx +0 -29
- package/src/components/overlay/actionSheet/ActionSheet.tsx +0 -31
- package/src/components/overlay/actionSheet/ActionSheetContentGesture.tsx +0 -15
- package/src/components/overlay/actionSheet/ActionSheetHeader.tsx +0 -72
- package/src/components/overlay/actionSheet/ActionSheetListView.tsx +0 -54
- package/src/components/overlay/actionSheet/ActionSheetListViewContent.tsx +0 -32
- package/src/components/overlay/actionSheet/ActionSheetOptionList.tsx +0 -51
- package/src/components/overlay/actionSheet/ActionSheetOptionListItem.tsx +0 -43
- package/src/components/overlay/actionSheet/ActionSheetOptions.tsx +0 -61
- package/src/components/overlay/actionSheet/ActionSheetScrollView.tsx +0 -57
- package/src/components/overlay/actionSheet/ActionSheetScrollViewContent.tsx +0 -38
- package/src/components/overlay/actionSheet/ActionSheetWrap.tsx +0 -75
- package/src/components/overlay/alert/Alert.tsx +0 -86
- package/src/components/overlay/alert/AlertButton.tsx +0 -41
- package/src/components/overlay/alert/AlertButtons.tsx +0 -32
- package/src/components/overlay/alert/AlertContent.tsx +0 -60
- package/src/components/overlay/alert/AlertWrap.tsx +0 -93
- package/src/components/overlay/modal/ThemedLoadingModal.tsx +0 -47
- package/src/components/overlay/modal/ThemedModal.tsx +0 -42
- package/src/components/overlay/toast/ThemedToast.tsx +0 -160
- package/src/components/provider/GestureProvider.tsx +0 -9
- package/src/components/provider/InsetsProvider.tsx +0 -11
- package/src/components/provider/ReactNativeTemplateProviders.tsx +0 -20
- package/src/components/provider/ThemeProvider.tsx +0 -8
- package/src/components/separator/ThemedSeparator.tsx +0 -24
- package/src/components/slider/Slider.tsx +0 -229
- package/src/components/slider/ThemedSlider.tsx +0 -103
- package/src/components/slider/ThemedSliderStepIndicator.tsx +0 -24
- package/src/components/switch/ThemedSwitch.tsx +0 -49
- package/src/components/text/Text.tsx +0 -7
- package/src/components/text/ThemedIconText.tsx +0 -58
- package/src/components/text/ThemedText.tsx +0 -7
- package/src/components/view/AnimatedThemedView.tsx +0 -18
- package/src/components/view/AnimatedView.tsx +0 -7
- package/src/components/view/Box.tsx +0 -7
- package/src/components/view/ThemedScreenWrap.tsx +0 -48
- package/src/components/view/ThemedScreenWrap.web.tsx +0 -41
- package/src/components/view/ThemedScrollView.tsx +0 -54
- package/src/components/view/ThemedView.tsx +0 -19
- package/src/hooks/button.ts +0 -152
- package/src/hooks/list.ts +0 -42
- package/src/hooks/overlay.ts +0 -471
- package/src/hooks/react.ts +0 -34
- package/src/hooks/reanimated.ts +0 -6
- package/src/hooks/separator.ts +0 -29
- package/src/hooks/style.ts +0 -79
- package/src/hooks/switch.ts +0 -119
- package/src/hooks/theme.ts +0 -65
- package/src/hooks/view.ts +0 -28
- package/src/index.ts +0 -59
- package/src/test/utils/const.ts +0 -9
- package/src/test/utils/func.ts +0 -55
- package/src/test/utils/testingLib.tsx +0 -17
- package/src/types/button.ts +0 -50
- package/src/types/global.d.ts +0 -5
- package/src/types/icon.ts +0 -21
- package/src/types/list.ts +0 -61
- package/src/types/loading.ts +0 -14
- package/src/types/overlay.ts +0 -216
- package/src/types/provider.ts +0 -6
- package/src/types/react.ts +0 -8
- package/src/types/reanimated.ts +0 -11
- package/src/types/separator.ts +0 -28
- package/src/types/slider.ts +0 -59
- package/src/types/style.ts +0 -26
- package/src/types/switch.ts +0 -31
- package/src/types/text.ts +0 -25
- package/src/types/theme.ts +0 -39
- package/src/types/view.ts +0 -58
- package/src/utils/button/const.ts +0 -10
- package/src/utils/overlay/const.ts +0 -77
- package/src/utils/overlay/func.ts +0 -107
- package/src/utils/reanimated/func.ts +0 -39
- package/src/utils/slider/const.ts +0 -23
- package/src/utils/style/const.ts +0 -4
- package/src/utils/style/func.ts +0 -37
- package/src/utils/switch/const.ts +0 -2
- package/src/utils/theme/const.ts +0 -189
- package/src/utils/theme/restyle.ts +0 -87
package/src/hooks/button.ts
DELETED
|
@@ -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
|
-
}
|
package/src/hooks/overlay.ts
DELETED
|
@@ -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
|
-
}
|
package/src/hooks/react.ts
DELETED
|
@@ -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
|
-
}
|