@jamadd/react-native-template-ui 0.8.3 → 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/lib/module/components/overlay/actionSheet/ActionSheetListView.js +2 -0
- package/lib/module/components/overlay/actionSheet/ActionSheetListView.js.map +1 -1
- package/lib/module/components/overlay/actionSheet/ActionSheetListViewContent.js +1 -0
- package/lib/module/components/overlay/actionSheet/ActionSheetListViewContent.js.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetContentGesture.d.ts +2 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetContentGesture.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetHeader.d.ts +2 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetHeader.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListView.d.ts +1 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListView.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListViewContent.d.ts +1 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetListViewContent.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionList.d.ts +2 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionList.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionListItem.d.ts +2 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptionListItem.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptions.d.ts +2 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetOptions.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollView.d.ts +2 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollView.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollViewContent.d.ts +2 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetScrollViewContent.d.ts.map +1 -1
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetWrap.d.ts +2 -0
- package/lib/typescript/src/components/overlay/actionSheet/ActionSheetWrap.d.ts.map +1 -1
- package/lib/typescript/src/components/view/AnimatedView.d.ts +2 -0
- package/lib/typescript/src/components/view/AnimatedView.d.ts.map +1 -1
- package/lib/typescript/src/hooks/overlay.d.ts +27 -0
- package/lib/typescript/src/hooks/overlay.d.ts.map +1 -1
- package/lib/typescript/src/hooks/switch.d.ts +20 -1
- package/lib/typescript/src/hooks/switch.d.ts.map +1 -1
- package/lib/typescript/src/types/list.d.ts +10 -1
- package/lib/typescript/src/types/list.d.ts.map +1 -1
- package/lib/typescript/src/types/overlay.d.ts +31 -1
- package/lib/typescript/src/types/overlay.d.ts.map +1 -1
- package/lib/typescript/src/utils/overlay/const.d.ts +33 -0
- package/lib/typescript/src/utils/overlay/const.d.ts.map +1 -1
- package/lib/typescript/src/utils/reanimated/func.d.ts +5 -1
- package/lib/typescript/src/utils/reanimated/func.d.ts.map +1 -1
- package/lib/typescript/src/utils/switch/const.d.ts +2 -1
- package/lib/typescript/src/utils/switch/const.d.ts.map +1 -1
- 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,19 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import type { ThemedViewProps } from '../../types/view';
|
|
3
|
+
import Box from './Box';
|
|
4
|
+
|
|
5
|
+
const ThemedView: FC<ThemedViewProps> = ({
|
|
6
|
+
backgroundColor = 'background',
|
|
7
|
+
...props
|
|
8
|
+
}) => {
|
|
9
|
+
return (
|
|
10
|
+
<Box
|
|
11
|
+
backgroundColor={backgroundColor}
|
|
12
|
+
accessible={true}
|
|
13
|
+
role={'group'}
|
|
14
|
+
{...props}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default ThemedView;
|
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|