@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,29 @@
|
|
|
1
|
+
import { createElement, type FC } from 'react';
|
|
2
|
+
import type { ThemedSeparatorProps } from '../types/separator';
|
|
3
|
+
import type { ThemeColors } from '../types/theme';
|
|
4
|
+
import { BorderSize } from '../utils/theme/const';
|
|
5
|
+
|
|
6
|
+
// @internal
|
|
7
|
+
let ThemedSeparator: FC<ThemedSeparatorProps> | undefined;
|
|
8
|
+
|
|
9
|
+
export function useThemedSeparator(
|
|
10
|
+
size = BorderSize.S,
|
|
11
|
+
vertical = false,
|
|
12
|
+
backgroundColor: ThemeColors = 'separator',
|
|
13
|
+
style: Omit<
|
|
14
|
+
ThemedSeparatorProps,
|
|
15
|
+
'size' | 'vertical' | 'backgroundColor' | 'bg'
|
|
16
|
+
> = {}
|
|
17
|
+
) {
|
|
18
|
+
const props: ThemedSeparatorProps = {
|
|
19
|
+
size,
|
|
20
|
+
vertical,
|
|
21
|
+
backgroundColor,
|
|
22
|
+
...style,
|
|
23
|
+
};
|
|
24
|
+
ThemedSeparator ??=
|
|
25
|
+
require('../components/separator/ThemedSeparator').default;
|
|
26
|
+
const element = createElement(ThemedSeparator!, props);
|
|
27
|
+
|
|
28
|
+
return element;
|
|
29
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useWindowDimensions as useRNWindowDimensions,
|
|
3
|
+
type ViewStyle,
|
|
4
|
+
} from 'react-native';
|
|
5
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
|
+
import type { InsetsStyleConfig } from '../types/style';
|
|
7
|
+
import { Orientation } from '../utils/style/const';
|
|
8
|
+
import { useThemeSpacing } from './theme';
|
|
9
|
+
|
|
10
|
+
export function useInsetsStyle({
|
|
11
|
+
insets,
|
|
12
|
+
insetTop,
|
|
13
|
+
insetBottom,
|
|
14
|
+
insetLeft,
|
|
15
|
+
insetRight,
|
|
16
|
+
insetsPadding,
|
|
17
|
+
insetPaddingTop,
|
|
18
|
+
insetPaddingBottom,
|
|
19
|
+
insetPaddingLeft,
|
|
20
|
+
insetPaddingRight,
|
|
21
|
+
}: InsetsStyleConfig) {
|
|
22
|
+
const { top, bottom, left, right } = useSafeAreaInsets();
|
|
23
|
+
const spacing = useThemeSpacing();
|
|
24
|
+
|
|
25
|
+
const insetsStyle: Pick<
|
|
26
|
+
ViewStyle,
|
|
27
|
+
'paddingTop' | 'paddingBottom' | 'paddingLeft' | 'paddingRight'
|
|
28
|
+
> = JSON.parse(
|
|
29
|
+
JSON.stringify({
|
|
30
|
+
paddingTop:
|
|
31
|
+
(insetTop ?? insets)
|
|
32
|
+
? top + spacing[insetPaddingTop ?? insetsPadding ?? 'none']
|
|
33
|
+
: undefined,
|
|
34
|
+
paddingBottom:
|
|
35
|
+
(insetBottom ?? insets)
|
|
36
|
+
? bottom + spacing[insetPaddingBottom ?? insetsPadding ?? 'none']
|
|
37
|
+
: undefined,
|
|
38
|
+
paddingLeft:
|
|
39
|
+
(insetLeft ?? insets)
|
|
40
|
+
? left + spacing[insetPaddingLeft ?? insetsPadding ?? 'none']
|
|
41
|
+
: undefined,
|
|
42
|
+
paddingRight:
|
|
43
|
+
(insetRight ?? insets)
|
|
44
|
+
? right + spacing[insetPaddingRight ?? insetsPadding ?? 'none']
|
|
45
|
+
: undefined,
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return insetsStyle;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function useWindowDimensions() {
|
|
53
|
+
return useRNWindowDimensions();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function useWindowDimensionsWidth() {
|
|
57
|
+
return useWindowDimensions().width;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function useWindowDimensionsHeight() {
|
|
61
|
+
return useWindowDimensions().height;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function useWindowDimensionsScale() {
|
|
65
|
+
return useWindowDimensions().scale;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function useWindowDimensionsFontScale() {
|
|
69
|
+
return useWindowDimensions().fontScale;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function useOrientation() {
|
|
73
|
+
const { width, height } = useWindowDimensions();
|
|
74
|
+
|
|
75
|
+
const orientation =
|
|
76
|
+
width > height ? Orientation.Landscape : Orientation.Portrait;
|
|
77
|
+
|
|
78
|
+
return orientation;
|
|
79
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
interpolate,
|
|
4
|
+
interpolateColor,
|
|
5
|
+
useAnimatedStyle,
|
|
6
|
+
type SharedValue,
|
|
7
|
+
} from 'react-native-reanimated';
|
|
8
|
+
import type { PressableOnPress } from '../types/button';
|
|
9
|
+
import type { AnimationValue } from '../types/reanimated';
|
|
10
|
+
import type { ThemedSwitchProps } from '../types/switch';
|
|
11
|
+
import { updateSharedValWithTiming } from '../utils/reanimated/func';
|
|
12
|
+
import { switchAnimationDuration } from '../utils/switch/const';
|
|
13
|
+
import { BorderSize, SwitchSize } from '../utils/theme/const';
|
|
14
|
+
import { useDelayedOnPress } from './button';
|
|
15
|
+
import { useAnimationSharedVal } from './reanimated';
|
|
16
|
+
import { useThemeColors, useThemeSpacing } from './theme';
|
|
17
|
+
|
|
18
|
+
/** @internal */
|
|
19
|
+
export function useThemedSwitch(
|
|
20
|
+
onPress: ThemedSwitchProps['onPress'],
|
|
21
|
+
enabled: ThemedSwitchProps['enabled'] = false,
|
|
22
|
+
size: ThemedSwitchProps['size'] = SwitchSize.M,
|
|
23
|
+
onPressDelayConfig?: ThemedSwitchProps['onPressDelayConfig'],
|
|
24
|
+
customEnableAnimation?: ThemedSwitchProps['customEnableAnimation'],
|
|
25
|
+
customDisableAnimation?: ThemedSwitchProps['customDisableAnimation'],
|
|
26
|
+
customColors?: ThemedSwitchProps['customColors']
|
|
27
|
+
) {
|
|
28
|
+
const { xxxs } = useThemeSpacing();
|
|
29
|
+
const colors = useThemeColors();
|
|
30
|
+
const enabledSharedVal = useAnimationSharedVal();
|
|
31
|
+
const pressableOnPress: PressableOnPress = () => {
|
|
32
|
+
onPress(enabledSharedVal.get() > 0.5);
|
|
33
|
+
};
|
|
34
|
+
const delayedOnPress = useDelayedOnPress(
|
|
35
|
+
pressableOnPress,
|
|
36
|
+
onPressDelayConfig
|
|
37
|
+
);
|
|
38
|
+
const handleAnimation = (toVal: AnimationValue, cb?: () => void) => {
|
|
39
|
+
if (customEnableAnimation && toVal) {
|
|
40
|
+
customEnableAnimation(enabledSharedVal, toVal, cb);
|
|
41
|
+
} else if (customDisableAnimation && !toVal) {
|
|
42
|
+
customDisableAnimation(enabledSharedVal, toVal, cb);
|
|
43
|
+
} else {
|
|
44
|
+
updateSharedValWithTiming(
|
|
45
|
+
enabledSharedVal as SharedValue<number>,
|
|
46
|
+
toVal,
|
|
47
|
+
{ duration: switchAnimationDuration },
|
|
48
|
+
cb
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const toggleSwitch: PressableOnPress = (event) => {
|
|
53
|
+
handleAnimation(enabledSharedVal.get() > 0.5 ? 0 : 1, () => {
|
|
54
|
+
delayedOnPress(event);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const trackAnimatedStyle = useAnimatedStyle(() => {
|
|
58
|
+
const padding = xxxs;
|
|
59
|
+
const borderWidth = BorderSize.S;
|
|
60
|
+
const borderColor = colors.themePri;
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
width: size * 2 + padding * 2 + borderWidth * 2,
|
|
64
|
+
padding,
|
|
65
|
+
borderWidth,
|
|
66
|
+
borderColor: interpolateColor(
|
|
67
|
+
enabledSharedVal.get(),
|
|
68
|
+
[0, 1],
|
|
69
|
+
[
|
|
70
|
+
customColors?.border ? colors[customColors.border] : borderColor,
|
|
71
|
+
customColors?.borderEnabled
|
|
72
|
+
? colors[customColors.borderEnabled]
|
|
73
|
+
: borderColor,
|
|
74
|
+
]
|
|
75
|
+
),
|
|
76
|
+
backgroundColor: interpolateColor(
|
|
77
|
+
enabledSharedVal.get(),
|
|
78
|
+
[0, 1],
|
|
79
|
+
[
|
|
80
|
+
customColors?.background
|
|
81
|
+
? colors[customColors.background]
|
|
82
|
+
: colors.background,
|
|
83
|
+
customColors?.backgroundEnabled
|
|
84
|
+
? colors[customColors.backgroundEnabled]
|
|
85
|
+
: borderColor,
|
|
86
|
+
]
|
|
87
|
+
),
|
|
88
|
+
};
|
|
89
|
+
}, [size, customColors, xxxs, colors, enabledSharedVal]);
|
|
90
|
+
const thumbAnimatedStyle = useAnimatedStyle(
|
|
91
|
+
() => ({
|
|
92
|
+
backgroundColor: interpolateColor(
|
|
93
|
+
enabledSharedVal.get(),
|
|
94
|
+
[0, 1],
|
|
95
|
+
[
|
|
96
|
+
customColors?.thumb ? colors[customColors.thumb] : colors.themePri,
|
|
97
|
+
customColors?.thumbEnabled
|
|
98
|
+
? colors[customColors.thumbEnabled]
|
|
99
|
+
: colors.background,
|
|
100
|
+
]
|
|
101
|
+
),
|
|
102
|
+
transform: [
|
|
103
|
+
{ translateX: interpolate(enabledSharedVal.get(), [0, 1], [0, size]) },
|
|
104
|
+
],
|
|
105
|
+
}),
|
|
106
|
+
[size, customColors, colors, enabledSharedVal]
|
|
107
|
+
);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
handleAnimation(enabled ? 1 : 0);
|
|
110
|
+
}, [enabled]);
|
|
111
|
+
|
|
112
|
+
const switchProps = {
|
|
113
|
+
toggleSwitch,
|
|
114
|
+
trackAnimatedStyle,
|
|
115
|
+
thumbAnimatedStyle,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
return switchProps;
|
|
119
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useResponsiveProp,
|
|
3
|
+
useTheme as useRestyleTheme,
|
|
4
|
+
type PropValue,
|
|
5
|
+
type ResponsiveValue,
|
|
6
|
+
} from '@shopify/restyle';
|
|
7
|
+
import { useColorScheme, type ColorSchemeName } from 'react-native';
|
|
8
|
+
import type { Theme, ThemeBreakpoints } from '../types/theme';
|
|
9
|
+
import { darkTheme, lightTheme } from '../utils/theme/const';
|
|
10
|
+
|
|
11
|
+
export function useTheme(): Theme {
|
|
12
|
+
return useRestyleTheme<Theme>();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useThemeColors(): Theme['colors'] {
|
|
16
|
+
return useTheme().colors;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useThemeSpacing(): Theme['spacing'] {
|
|
20
|
+
return useTheme().spacing;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function useThemeBreakpoints(): Theme['breakpoints'] {
|
|
24
|
+
return useTheme().breakpoints;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useThemeBreakpointValues<T extends PropValue>(
|
|
28
|
+
propValue: ResponsiveValue<T, Theme['breakpoints']>
|
|
29
|
+
) {
|
|
30
|
+
return useResponsiveProp(propValue);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function useThemeBreakpoint() {
|
|
34
|
+
const responsiveVal: ResponsiveValue<PropValue, Theme['breakpoints']> = {
|
|
35
|
+
smallPhone: 'smallPhone',
|
|
36
|
+
phone: 'phone',
|
|
37
|
+
smallTablet: 'smallTablet',
|
|
38
|
+
tablet: 'tablet',
|
|
39
|
+
desktop: 'desktop',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return useThemeBreakpointValues(responsiveVal) as ThemeBreakpoints;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function useThemeZIndices(): Theme['zIndices'] {
|
|
46
|
+
return useTheme().zIndices;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useThemeBorderRadii(): Theme['borderRadii'] {
|
|
50
|
+
return useTheme().borderRadii;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useThemeTextVariants(): Theme['textVariants'] {
|
|
54
|
+
return useTheme().textVariants;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function useIsDarkColorScheme(overrideColorScheme?: ColorSchemeName) {
|
|
58
|
+
const colorScheme = useColorScheme();
|
|
59
|
+
|
|
60
|
+
return (overrideColorScheme ?? colorScheme) === 'dark';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function useColorSchemeTheme(overrideColorScheme?: ColorSchemeName) {
|
|
64
|
+
return useIsDarkColorScheme(overrideColorScheme) ? darkTheme : lightTheme;
|
|
65
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useRestyle } from '@shopify/restyle';
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import type { View } from 'react-native';
|
|
4
|
+
import type { AnimatedThemedViewProps, AnimatedViewProps } from '../types/view';
|
|
5
|
+
import { animatedThemedViewRestyleFuncs } from '../utils/theme/restyle';
|
|
6
|
+
|
|
7
|
+
export function useViewRef() {
|
|
8
|
+
return useRef<View>(null);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useAnimatedThemedView({
|
|
12
|
+
animatedStyle,
|
|
13
|
+
...props
|
|
14
|
+
}: AnimatedThemedViewProps) {
|
|
15
|
+
const { style, ...restyle } = useRestyle(
|
|
16
|
+
animatedThemedViewRestyleFuncs,
|
|
17
|
+
props
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const animatedThemedViewProps: AnimatedViewProps = {
|
|
21
|
+
...restyle,
|
|
22
|
+
style: [style, animatedStyle],
|
|
23
|
+
accessible: true,
|
|
24
|
+
role: 'group',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return animatedThemedViewProps;
|
|
28
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export { default as AnimatedThemedPressable } from './components/button/AnimatedThemedPressable';
|
|
2
|
+
export { default as ThemedButton } from './components/button/ThemedButton';
|
|
3
|
+
export { default as ThemedIconButton } from './components/button/ThemedIconButton';
|
|
4
|
+
export { default as ThemedIconTextButton } from './components/button/ThemedIconTextButton';
|
|
5
|
+
export { default as ThemedPressable } from './components/button/ThemedPressable';
|
|
6
|
+
export { default as ThemedIcon } from './components/icon/ThemedIcon';
|
|
7
|
+
export { default as List } from './components/list/List';
|
|
8
|
+
export { default as ThemedLoading } from './components/loading/ThemedLoading';
|
|
9
|
+
export { default as ActionSheet } from './components/overlay/actionSheet/ActionSheet';
|
|
10
|
+
export { default as Alert } from './components/overlay/alert/Alert';
|
|
11
|
+
export { default as ThemedLoadingModal } from './components/overlay/modal/ThemedLoadingModal';
|
|
12
|
+
export { default as ThemedModal } from './components/overlay/modal/ThemedModal';
|
|
13
|
+
export { default as ThemedToast } from './components/overlay/toast/ThemedToast';
|
|
14
|
+
export { default as GestureProvider } from './components/provider/GestureProvider';
|
|
15
|
+
export { default as InsetsProvider } from './components/provider/InsetsProvider';
|
|
16
|
+
export { default as ReactNativeTemplateProviders } from './components/provider/ReactNativeTemplateProviders';
|
|
17
|
+
export { default as ThemeProvider } from './components/provider/ThemeProvider';
|
|
18
|
+
export { default as ThemedSeparator } from './components/separator/ThemedSeparator';
|
|
19
|
+
export { default as ThemedSlider } from './components/slider/ThemedSlider';
|
|
20
|
+
export { default as ThemedSwitch } from './components/switch/ThemedSwitch';
|
|
21
|
+
export { default as ThemedIconText } from './components/text/ThemedIconText';
|
|
22
|
+
export { default as ThemedText } from './components/text/ThemedText';
|
|
23
|
+
export { default as AnimatedThemedView } from './components/view/AnimatedThemedView';
|
|
24
|
+
export { default as ThemedScreenWrap } from './components/view/ThemedScreenWrap';
|
|
25
|
+
export { default as ThemedScrollView } from './components/view/ThemedScrollView';
|
|
26
|
+
export { default as ThemedView } from './components/view/ThemedView';
|
|
27
|
+
|
|
28
|
+
export * from './hooks/button';
|
|
29
|
+
export * from './hooks/list';
|
|
30
|
+
export * from './hooks/overlay';
|
|
31
|
+
export * from './hooks/react';
|
|
32
|
+
export * from './hooks/reanimated';
|
|
33
|
+
export * from './hooks/separator';
|
|
34
|
+
export * from './hooks/style';
|
|
35
|
+
export * from './hooks/theme';
|
|
36
|
+
export * from './hooks/view';
|
|
37
|
+
|
|
38
|
+
export * from './types/button';
|
|
39
|
+
export * from './types/icon';
|
|
40
|
+
export * from './types/list';
|
|
41
|
+
export * from './types/loading';
|
|
42
|
+
export * from './types/overlay';
|
|
43
|
+
export * from './types/provider';
|
|
44
|
+
export * from './types/react';
|
|
45
|
+
export * from './types/reanimated';
|
|
46
|
+
export * from './types/separator';
|
|
47
|
+
export * from './types/slider';
|
|
48
|
+
export * from './types/style';
|
|
49
|
+
export * from './types/switch';
|
|
50
|
+
export * from './types/text';
|
|
51
|
+
export * from './types/theme';
|
|
52
|
+
export * from './types/view';
|
|
53
|
+
|
|
54
|
+
export * from './utils/button/const';
|
|
55
|
+
export * from './utils/overlay/const';
|
|
56
|
+
export * from './utils/slider/const';
|
|
57
|
+
export * from './utils/style/const';
|
|
58
|
+
export * from './utils/style/func';
|
|
59
|
+
export * from './utils/theme/const';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createElement, type FC } from 'react';
|
|
2
|
+
import ReactNativeTemplateProviders from '../../components/provider/ReactNativeTemplateProviders';
|
|
3
|
+
import type { ReactNativeTemplateProvidersProps } from '../../types/provider';
|
|
4
|
+
import { lightTheme } from '../../utils/theme/const';
|
|
5
|
+
|
|
6
|
+
export const wrapper: FC<ReactNativeTemplateProvidersProps> = ({
|
|
7
|
+
theme = lightTheme,
|
|
8
|
+
children,
|
|
9
|
+
}) => createElement(ReactNativeTemplateProviders, { theme, children });
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { renderHookAsync } from '@testing-library/react-native';
|
|
2
|
+
import { useTheme } from '../../hooks/theme';
|
|
3
|
+
import { wrapper } from './const';
|
|
4
|
+
|
|
5
|
+
async function getTheme() {
|
|
6
|
+
return (await renderHookAsync(() => useTheme(), { wrapper })).result.current;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function getThemeColors() {
|
|
10
|
+
return (await getTheme()).colors;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function getThemeSpacing() {
|
|
14
|
+
return (await getTheme()).spacing;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function getThemeBreakpoints() {
|
|
18
|
+
return (await getTheme()).breakpoints;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function getThemeZIndices() {
|
|
22
|
+
return (await getTheme()).zIndices;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function getThemeBorderRadii() {
|
|
26
|
+
return (await getTheme()).borderRadii;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function getThemeTextVariants() {
|
|
30
|
+
return (await getTheme()).textVariants;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function hexToRgb(hex: string) {
|
|
34
|
+
// Remove the '#' if present
|
|
35
|
+
const cleanHex = hex.startsWith('#') ? hex.slice(1) : hex;
|
|
36
|
+
|
|
37
|
+
let r, g, b;
|
|
38
|
+
let a = '1';
|
|
39
|
+
if (cleanHex.length === 3) {
|
|
40
|
+
r = parseInt(cleanHex.charAt(0) + cleanHex.charAt(0), 16);
|
|
41
|
+
g = parseInt(cleanHex.charAt(1) + cleanHex.charAt(1), 16);
|
|
42
|
+
b = parseInt(cleanHex.charAt(2) + cleanHex.charAt(2), 16);
|
|
43
|
+
} else if (cleanHex.length === 6) {
|
|
44
|
+
r = parseInt(cleanHex.substring(0, 2), 16);
|
|
45
|
+
g = parseInt(cleanHex.substring(2, 4), 16);
|
|
46
|
+
b = parseInt(cleanHex.substring(4, 6), 16);
|
|
47
|
+
} else if (cleanHex.length === 8) {
|
|
48
|
+
r = parseInt(cleanHex.substring(0, 2), 16);
|
|
49
|
+
g = parseInt(cleanHex.substring(2, 4), 16);
|
|
50
|
+
b = parseInt(cleanHex.substring(4, 6), 16);
|
|
51
|
+
a = (parseInt(cleanHex.substring(6, 8), 16) / 255).toFixed(2); // Convert 0-255 to 0-1
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
55
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
render as testRender,
|
|
3
|
+
renderAsync as testRenderAsync,
|
|
4
|
+
} from '@testing-library/react-native';
|
|
5
|
+
import { wrapper } from './const';
|
|
6
|
+
|
|
7
|
+
const customTestRender: typeof testRender = (ui, options) =>
|
|
8
|
+
testRender(ui, { wrapper, ...options });
|
|
9
|
+
|
|
10
|
+
const customTestRenderAsync: typeof testRenderAsync = async (ui, options) =>
|
|
11
|
+
await testRenderAsync(ui, { wrapper, ...options });
|
|
12
|
+
|
|
13
|
+
// re-export everything
|
|
14
|
+
export * from '@testing-library/react-native';
|
|
15
|
+
|
|
16
|
+
// override render method
|
|
17
|
+
export { customTestRender as render, customTestRenderAsync as renderAsync };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ComponentProps, PropsWithChildren } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
GestureResponderEvent,
|
|
4
|
+
PressableProps as RNPressableProps,
|
|
5
|
+
} from 'react-native';
|
|
6
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
7
|
+
import type AnimatedPressable from '../components/button/AnimatedPressable';
|
|
8
|
+
import type { ButtonScaleRatio, OnPressDelayType } from '../utils/button/const';
|
|
9
|
+
import type { CustomThemedIconProps } from './icon';
|
|
10
|
+
import type { CustomThemedTextProps, IconTextProps } from './text';
|
|
11
|
+
import type { ThemeViewProps } from './theme';
|
|
12
|
+
import type { ThemedViewProps, ViewRefObj } from './view';
|
|
13
|
+
|
|
14
|
+
export type PressableOnPress = (
|
|
15
|
+
event: GestureResponderEvent
|
|
16
|
+
) => void | SharedValue<(event: GestureResponderEvent) => void>;
|
|
17
|
+
|
|
18
|
+
export type OnPressDelayConfig<T = OnPressDelayType> = {
|
|
19
|
+
type: T;
|
|
20
|
+
wait: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type PressableProps = Omit<RNPressableProps, 'onPress'> &
|
|
24
|
+
Required<Pick<RNPressableProps, 'onPress'>> & {
|
|
25
|
+
scaleRatio?: ButtonScaleRatio | number;
|
|
26
|
+
onPressDelayConfig?: OnPressDelayConfig;
|
|
27
|
+
ref?: ViewRefObj;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type ThemedPressableProps = PressableProps & ThemeViewProps;
|
|
31
|
+
|
|
32
|
+
export type AnimatedPressableProps = ComponentProps<typeof AnimatedPressable>;
|
|
33
|
+
|
|
34
|
+
export type AnimatedThemedPressableProps = Omit<
|
|
35
|
+
ThemedPressableProps,
|
|
36
|
+
'ref' | 'scaleRatio'
|
|
37
|
+
> &
|
|
38
|
+
Omit<AnimatedPressableProps, 'key' | 'style'> & {
|
|
39
|
+
animatedStyle?: AnimatedPressableProps['style'];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type ButtonProps = PropsWithChildren<Omit<ThemedPressableProps, 'children'>>;
|
|
43
|
+
|
|
44
|
+
export type ThemedButtonProps = ButtonProps & CustomThemedTextProps;
|
|
45
|
+
|
|
46
|
+
export type ThemedIconButtonProps = ButtonProps & CustomThemedIconProps;
|
|
47
|
+
|
|
48
|
+
export type ThemedIconTextButtonProps = PropsWithChildren<
|
|
49
|
+
ButtonProps & IconTextProps & { iconTextProps?: ThemedViewProps }
|
|
50
|
+
>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IconName, IconSize } from '@jamadd/react-native-template-icons';
|
|
2
|
+
import type { TextStyle } from 'react-native';
|
|
3
|
+
import type { StyleOrStyleProp } from './style';
|
|
4
|
+
import type { ThemeBaseProps, ThemeColors } from './theme';
|
|
5
|
+
|
|
6
|
+
export type IconProps = {
|
|
7
|
+
name: IconName;
|
|
8
|
+
size?: IconSize | number;
|
|
9
|
+
color?: ThemeColors;
|
|
10
|
+
style?: StyleOrStyleProp<TextStyle>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type ThemedIconProps = IconProps & ThemeBaseProps;
|
|
14
|
+
|
|
15
|
+
export type CustomThemedIconProps = {
|
|
16
|
+
iconName: ThemedIconProps['name'];
|
|
17
|
+
iconSize?: ThemedIconProps['size'];
|
|
18
|
+
iconColor?: ThemedIconProps['color'];
|
|
19
|
+
iconStyle?: ThemedIconProps['style'];
|
|
20
|
+
iconProps?: Omit<ThemedIconProps, 'name' | 'size' | 'color' | 'style'>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FlashListProps,
|
|
3
|
+
FlashListRef,
|
|
4
|
+
ListRenderItemInfo,
|
|
5
|
+
} from '@shopify/flash-list';
|
|
6
|
+
import type { ComponentType, FC, RefObject } from 'react';
|
|
7
|
+
import type { ViewStyle } from 'react-native';
|
|
8
|
+
import type { AnimatedRef } from 'react-native-reanimated';
|
|
9
|
+
import type { ThemedSeparatorProps } from './separator';
|
|
10
|
+
import type { InsetsStyleConfig } from './style';
|
|
11
|
+
import type { ThemeColors } from './theme';
|
|
12
|
+
import type { PropsWithRequiredChildren } from './view';
|
|
13
|
+
|
|
14
|
+
export type ListRef<T> = FlashListRef<T>;
|
|
15
|
+
|
|
16
|
+
export type ListRefObj<T> = RefObject<ListRef<T> | null>;
|
|
17
|
+
|
|
18
|
+
export type ListAnimatedRefObj<T> = AnimatedRef<ListRef<T>>;
|
|
19
|
+
|
|
20
|
+
export type ListItemProps<T> = ListRenderItemInfo<T>;
|
|
21
|
+
|
|
22
|
+
export type ListKeyExtractor<T> = (item: T, index: number) => string;
|
|
23
|
+
|
|
24
|
+
export type ListGetItemType<T> = (
|
|
25
|
+
item: T,
|
|
26
|
+
index: number,
|
|
27
|
+
extraData?: any
|
|
28
|
+
) => string | number | undefined;
|
|
29
|
+
|
|
30
|
+
export type ListProps<T> = Omit<
|
|
31
|
+
FlashListProps<T>,
|
|
32
|
+
'data' | 'renderItem' | 'keyExtractor'
|
|
33
|
+
> &
|
|
34
|
+
InsetsStyleConfig & {
|
|
35
|
+
ref?: ListRefObj<T> | ListAnimatedRefObj<T>;
|
|
36
|
+
data: T[];
|
|
37
|
+
Item: ComponentType<ListItemProps<T>>;
|
|
38
|
+
keyExtractor: ListKeyExtractor<T>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type ListItemSeparatorProps = Partial<
|
|
42
|
+
Pick<ThemedSeparatorProps, 'size' | 'vertical'> & {
|
|
43
|
+
backgroundColor: ThemeColors;
|
|
44
|
+
style: Omit<
|
|
45
|
+
ThemedSeparatorProps,
|
|
46
|
+
'size' | 'vertical' | 'backgroundColor' | 'bg'
|
|
47
|
+
>;
|
|
48
|
+
}
|
|
49
|
+
>;
|
|
50
|
+
|
|
51
|
+
/** @internal */
|
|
52
|
+
export type ListItemSeparatorComponent = FC<{
|
|
53
|
+
leadingItem?: { type: string };
|
|
54
|
+
trailingItem?: { type: string };
|
|
55
|
+
}>;
|
|
56
|
+
|
|
57
|
+
export type ListCellRendererComponentProps = PropsWithRequiredChildren<{
|
|
58
|
+
onLayout: () => void;
|
|
59
|
+
index: number;
|
|
60
|
+
style: ViewStyle;
|
|
61
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ActivityIndicatorProps } from 'react-native';
|
|
2
|
+
import type { ThemeBaseProps, ThemeColorProps } from './theme';
|
|
3
|
+
|
|
4
|
+
export type LoadingProps = Omit<ActivityIndicatorProps, 'color'> & {
|
|
5
|
+
color?: ThemeColorProps['color'];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ThemedLoadingProps = LoadingProps & ThemeBaseProps;
|
|
9
|
+
|
|
10
|
+
export type CustomThemedLoadingProps = {
|
|
11
|
+
loadingSize?: ThemedLoadingProps['size'];
|
|
12
|
+
loadingColor?: ThemedLoadingProps['color'];
|
|
13
|
+
loadingProps?: Omit<ThemedLoadingProps, 'size' | 'color'>;
|
|
14
|
+
};
|