@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,58 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import type { ThemedIconTextProps } from '../../types/text';
|
|
3
|
+
import ThemedIcon from '../icon/ThemedIcon';
|
|
4
|
+
import ThemedView from '../view/ThemedView';
|
|
5
|
+
import ThemedText from './ThemedText';
|
|
6
|
+
|
|
7
|
+
const ThemedIconText: FC<ThemedIconTextProps> = ({
|
|
8
|
+
flip = false,
|
|
9
|
+
iconName,
|
|
10
|
+
iconSize,
|
|
11
|
+
iconColor,
|
|
12
|
+
iconStyle,
|
|
13
|
+
iconProps,
|
|
14
|
+
text,
|
|
15
|
+
textVariant,
|
|
16
|
+
textFontSize,
|
|
17
|
+
textFontWeight,
|
|
18
|
+
textColor,
|
|
19
|
+
textStyle,
|
|
20
|
+
textProps,
|
|
21
|
+
...props
|
|
22
|
+
}) => {
|
|
23
|
+
const themedText = (
|
|
24
|
+
<ThemedText
|
|
25
|
+
numberOfLines={1}
|
|
26
|
+
variant={textVariant}
|
|
27
|
+
fontSize={textFontSize}
|
|
28
|
+
fontWeight={textFontWeight}
|
|
29
|
+
color={textColor}
|
|
30
|
+
style={textStyle}
|
|
31
|
+
{...textProps}
|
|
32
|
+
>
|
|
33
|
+
{text}
|
|
34
|
+
</ThemedText>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<ThemedView
|
|
39
|
+
flexDirection={'row'}
|
|
40
|
+
alignItems={'center'}
|
|
41
|
+
gap={'s'}
|
|
42
|
+
backgroundColor={'transparent'}
|
|
43
|
+
{...props}
|
|
44
|
+
>
|
|
45
|
+
{flip && themedText}
|
|
46
|
+
<ThemedIcon
|
|
47
|
+
name={iconName}
|
|
48
|
+
size={iconSize}
|
|
49
|
+
color={iconColor}
|
|
50
|
+
style={iconStyle}
|
|
51
|
+
{...iconProps}
|
|
52
|
+
/>
|
|
53
|
+
{!flip && themedText}
|
|
54
|
+
</ThemedView>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default ThemedIconText;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import { useAnimatedThemedView } from '../../hooks/view';
|
|
3
|
+
import type { AnimatedThemedViewProps } from '../../types/view';
|
|
4
|
+
import AnimatedView from './AnimatedView';
|
|
5
|
+
|
|
6
|
+
const AnimatedThemedView: FC<AnimatedThemedViewProps> = ({
|
|
7
|
+
backgroundColor = 'background',
|
|
8
|
+
...props
|
|
9
|
+
}) => {
|
|
10
|
+
const animatedThemedViewProps = useAnimatedThemedView({
|
|
11
|
+
backgroundColor,
|
|
12
|
+
...props,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return <AnimatedView {...animatedThemedViewProps} />;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default AnimatedThemedView;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useEffect, type FC } from 'react';
|
|
2
|
+
import type { ViewStyle } from 'react-native';
|
|
3
|
+
import { useInsetsStyle } from '../../hooks/style';
|
|
4
|
+
import type { ThemedScreenWrapProps } from '../../types/view';
|
|
5
|
+
import { composeStyles } from '../../utils/style/func';
|
|
6
|
+
import ThemedView from './ThemedView';
|
|
7
|
+
|
|
8
|
+
const ThemedScreenWrap: FC<ThemedScreenWrapProps> = ({
|
|
9
|
+
effectSetup,
|
|
10
|
+
effectCleanup,
|
|
11
|
+
effectDependencies = [],
|
|
12
|
+
style: themedScreenWrapStyle,
|
|
13
|
+
insets,
|
|
14
|
+
insetTop,
|
|
15
|
+
insetBottom,
|
|
16
|
+
insetLeft,
|
|
17
|
+
insetRight,
|
|
18
|
+
insetsPadding,
|
|
19
|
+
insetPaddingTop,
|
|
20
|
+
insetPaddingBottom,
|
|
21
|
+
insetPaddingLeft,
|
|
22
|
+
insetPaddingRight,
|
|
23
|
+
...props
|
|
24
|
+
}) => {
|
|
25
|
+
const insetsStyle = useInsetsStyle({
|
|
26
|
+
insets,
|
|
27
|
+
insetTop,
|
|
28
|
+
insetBottom,
|
|
29
|
+
insetLeft,
|
|
30
|
+
insetRight,
|
|
31
|
+
insetsPadding,
|
|
32
|
+
insetPaddingTop,
|
|
33
|
+
insetPaddingBottom,
|
|
34
|
+
insetPaddingLeft,
|
|
35
|
+
insetPaddingRight,
|
|
36
|
+
});
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
effectSetup?.();
|
|
39
|
+
|
|
40
|
+
return effectCleanup;
|
|
41
|
+
}, effectDependencies);
|
|
42
|
+
|
|
43
|
+
const style = composeStyles<ViewStyle>(themedScreenWrapStyle, insetsStyle);
|
|
44
|
+
|
|
45
|
+
return <ThemedView flex={1} style={style} {...props} />;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default ThemedScreenWrap;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import type { ViewStyle } from 'react-native';
|
|
3
|
+
import { useInsetsStyle, useWindowDimensionsHeight } from '../../hooks/style';
|
|
4
|
+
import type { ThemedScreenWrapProps } from '../../types/view';
|
|
5
|
+
import { composeStyles } from '../../utils/style/func';
|
|
6
|
+
import ThemedView from './ThemedView';
|
|
7
|
+
|
|
8
|
+
const ThemedScreenWrap: FC<ThemedScreenWrapProps> = ({
|
|
9
|
+
style: themedScreenWrapStyle,
|
|
10
|
+
insets,
|
|
11
|
+
insetTop,
|
|
12
|
+
insetBottom,
|
|
13
|
+
insetLeft,
|
|
14
|
+
insetRight,
|
|
15
|
+
insetsPadding,
|
|
16
|
+
insetPaddingTop,
|
|
17
|
+
insetPaddingBottom,
|
|
18
|
+
insetPaddingLeft,
|
|
19
|
+
insetPaddingRight,
|
|
20
|
+
...props
|
|
21
|
+
}) => {
|
|
22
|
+
const height = useWindowDimensionsHeight();
|
|
23
|
+
const insetsStyle = useInsetsStyle({
|
|
24
|
+
insets,
|
|
25
|
+
insetTop,
|
|
26
|
+
insetBottom,
|
|
27
|
+
insetLeft,
|
|
28
|
+
insetRight,
|
|
29
|
+
insetsPadding,
|
|
30
|
+
insetPaddingTop,
|
|
31
|
+
insetPaddingBottom,
|
|
32
|
+
insetPaddingLeft,
|
|
33
|
+
insetPaddingRight,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const style = composeStyles<ViewStyle>(themedScreenWrapStyle, insetsStyle);
|
|
37
|
+
|
|
38
|
+
return <ThemedView height={height} style={style} {...props} />;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default ThemedScreenWrap;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useRestyle } from '@shopify/restyle';
|
|
2
|
+
import type { FC } from 'react';
|
|
3
|
+
import { ScrollView } from 'react-native';
|
|
4
|
+
import { useInsetsStyle } from '../../hooks/style';
|
|
5
|
+
import type { ThemedScrollViewProps } from '../../types/view';
|
|
6
|
+
import { composeStyles } from '../../utils/style/func';
|
|
7
|
+
import { themedScrollViewRestyleFuncs } from '../../utils/theme/restyle';
|
|
8
|
+
|
|
9
|
+
const ThemedScrollView: FC<ThemedScrollViewProps> = ({
|
|
10
|
+
insets,
|
|
11
|
+
insetTop,
|
|
12
|
+
insetBottom = true,
|
|
13
|
+
insetLeft,
|
|
14
|
+
insetRight,
|
|
15
|
+
insetsPadding,
|
|
16
|
+
insetPaddingTop,
|
|
17
|
+
insetPaddingBottom = 'm',
|
|
18
|
+
insetPaddingLeft,
|
|
19
|
+
insetPaddingRight,
|
|
20
|
+
...props
|
|
21
|
+
}) => {
|
|
22
|
+
const { contentContainerStyle: restyleContentContainerStyle, ...restyles } =
|
|
23
|
+
useRestyle(themedScrollViewRestyleFuncs, props);
|
|
24
|
+
const insetsStyle = useInsetsStyle({
|
|
25
|
+
insets,
|
|
26
|
+
insetTop,
|
|
27
|
+
insetBottom,
|
|
28
|
+
insetLeft,
|
|
29
|
+
insetRight,
|
|
30
|
+
insetsPadding,
|
|
31
|
+
insetPaddingTop,
|
|
32
|
+
insetPaddingBottom,
|
|
33
|
+
insetPaddingLeft,
|
|
34
|
+
insetPaddingRight,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const contentContainerStyle = composeStyles(
|
|
38
|
+
restyleContentContainerStyle,
|
|
39
|
+
insetsStyle
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<ScrollView
|
|
44
|
+
showsVerticalScrollIndicator={__DEV__}
|
|
45
|
+
showsHorizontalScrollIndicator={__DEV__}
|
|
46
|
+
contentContainerStyle={contentContainerStyle}
|
|
47
|
+
accessible={true}
|
|
48
|
+
role={'group'}
|
|
49
|
+
{...restyles}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default ThemedScrollView;
|
|
@@ -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
|
+
}
|