@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.
Files changed (88) hide show
  1. package/package.json +2 -1
  2. package/src/components/button/AnimatedPressable.tsx +7 -0
  3. package/src/components/button/AnimatedThemedPressable.tsx +12 -0
  4. package/src/components/button/ThemedButton.tsx +45 -0
  5. package/src/components/button/ThemedIconButton.tsx +33 -0
  6. package/src/components/button/ThemedIconTextButton.tsx +56 -0
  7. package/src/components/button/ThemedPressable.tsx +12 -0
  8. package/src/components/icon/ThemedIcon.tsx +31 -0
  9. package/src/components/list/List.tsx +55 -0
  10. package/src/components/loading/ThemedLoading.tsx +29 -0
  11. package/src/components/overlay/actionSheet/ActionSheet.tsx +31 -0
  12. package/src/components/overlay/actionSheet/ActionSheetContentGesture.tsx +15 -0
  13. package/src/components/overlay/actionSheet/ActionSheetHeader.tsx +72 -0
  14. package/src/components/overlay/actionSheet/ActionSheetListView.tsx +54 -0
  15. package/src/components/overlay/actionSheet/ActionSheetListViewContent.tsx +32 -0
  16. package/src/components/overlay/actionSheet/ActionSheetOptionList.tsx +51 -0
  17. package/src/components/overlay/actionSheet/ActionSheetOptionListItem.tsx +43 -0
  18. package/src/components/overlay/actionSheet/ActionSheetOptions.tsx +61 -0
  19. package/src/components/overlay/actionSheet/ActionSheetScrollView.tsx +57 -0
  20. package/src/components/overlay/actionSheet/ActionSheetScrollViewContent.tsx +38 -0
  21. package/src/components/overlay/actionSheet/ActionSheetWrap.tsx +75 -0
  22. package/src/components/overlay/alert/Alert.tsx +86 -0
  23. package/src/components/overlay/alert/AlertButton.tsx +41 -0
  24. package/src/components/overlay/alert/AlertButtons.tsx +32 -0
  25. package/src/components/overlay/alert/AlertContent.tsx +60 -0
  26. package/src/components/overlay/alert/AlertWrap.tsx +93 -0
  27. package/src/components/overlay/modal/ThemedLoadingModal.tsx +47 -0
  28. package/src/components/overlay/modal/ThemedModal.tsx +42 -0
  29. package/src/components/overlay/toast/ThemedToast.tsx +160 -0
  30. package/src/components/provider/GestureProvider.tsx +9 -0
  31. package/src/components/provider/InsetsProvider.tsx +11 -0
  32. package/src/components/provider/ReactNativeTemplateProviders.tsx +20 -0
  33. package/src/components/provider/ThemeProvider.tsx +8 -0
  34. package/src/components/separator/ThemedSeparator.tsx +24 -0
  35. package/src/components/slider/Slider.tsx +229 -0
  36. package/src/components/slider/ThemedSlider.tsx +103 -0
  37. package/src/components/slider/ThemedSliderStepIndicator.tsx +24 -0
  38. package/src/components/switch/ThemedSwitch.tsx +49 -0
  39. package/src/components/text/Text.tsx +7 -0
  40. package/src/components/text/ThemedIconText.tsx +58 -0
  41. package/src/components/text/ThemedText.tsx +7 -0
  42. package/src/components/view/AnimatedThemedView.tsx +18 -0
  43. package/src/components/view/AnimatedView.tsx +7 -0
  44. package/src/components/view/Box.tsx +7 -0
  45. package/src/components/view/ThemedScreenWrap.tsx +48 -0
  46. package/src/components/view/ThemedScreenWrap.web.tsx +41 -0
  47. package/src/components/view/ThemedScrollView.tsx +54 -0
  48. package/src/components/view/ThemedView.tsx +19 -0
  49. package/src/hooks/button.ts +152 -0
  50. package/src/hooks/list.ts +42 -0
  51. package/src/hooks/overlay.ts +471 -0
  52. package/src/hooks/react.ts +34 -0
  53. package/src/hooks/reanimated.ts +6 -0
  54. package/src/hooks/separator.ts +29 -0
  55. package/src/hooks/style.ts +79 -0
  56. package/src/hooks/switch.ts +119 -0
  57. package/src/hooks/theme.ts +65 -0
  58. package/src/hooks/view.ts +28 -0
  59. package/src/index.ts +59 -0
  60. package/src/test/utils/const.ts +9 -0
  61. package/src/test/utils/func.ts +55 -0
  62. package/src/test/utils/testingLib.tsx +17 -0
  63. package/src/types/button.ts +50 -0
  64. package/src/types/global.d.ts +5 -0
  65. package/src/types/icon.ts +21 -0
  66. package/src/types/list.ts +61 -0
  67. package/src/types/loading.ts +14 -0
  68. package/src/types/overlay.ts +216 -0
  69. package/src/types/provider.ts +6 -0
  70. package/src/types/react.ts +8 -0
  71. package/src/types/reanimated.ts +11 -0
  72. package/src/types/separator.ts +28 -0
  73. package/src/types/slider.ts +59 -0
  74. package/src/types/style.ts +26 -0
  75. package/src/types/switch.ts +31 -0
  76. package/src/types/text.ts +25 -0
  77. package/src/types/theme.ts +39 -0
  78. package/src/types/view.ts +58 -0
  79. package/src/utils/button/const.ts +10 -0
  80. package/src/utils/overlay/const.ts +77 -0
  81. package/src/utils/overlay/func.ts +107 -0
  82. package/src/utils/reanimated/func.ts +39 -0
  83. package/src/utils/slider/const.ts +23 -0
  84. package/src/utils/style/const.ts +4 -0
  85. package/src/utils/style/func.ts +37 -0
  86. package/src/utils/switch/const.ts +2 -0
  87. package/src/utils/theme/const.ts +189 -0
  88. package/src/utils/theme/restyle.ts +87 -0
@@ -0,0 +1,107 @@
1
+ import { use as reactUse } from 'react';
2
+ import { getWindowDimensionsHeight } from '../style/func';
3
+ import {
4
+ ActionSheetContext,
5
+ ActionSheetExpandableHeightRatio,
6
+ actionSheetMaxHeightRatio,
7
+ AlertContext,
8
+ } from './const';
9
+
10
+ export function getAlertContext() {
11
+ return reactUse(AlertContext);
12
+ }
13
+
14
+ function getActionSheetExpandableHeightByRatio(
15
+ ratio: ActionSheetExpandableHeightRatio
16
+ ) {
17
+ return getWindowDimensionsHeight() * ratio;
18
+ }
19
+
20
+ export function getActionSheetMaxHeight(expandable: boolean = false) {
21
+ return expandable
22
+ ? getActionSheetExpandableHeightByRatio(
23
+ ActionSheetExpandableHeightRatio.Top
24
+ )
25
+ : getWindowDimensionsHeight() * actionSheetMaxHeightRatio;
26
+ }
27
+
28
+ export function getActionSheetHeight(height: number) {
29
+ return Math.min(height, getActionSheetMaxHeight());
30
+ }
31
+
32
+ export function getActionSheetExpandableHeight() {
33
+ return getActionSheetMaxHeight(true);
34
+ }
35
+
36
+ export function getActionSheetExpandableInitHeight() {
37
+ return getActionSheetExpandableHeightByRatio(
38
+ ActionSheetExpandableHeightRatio.Middle
39
+ );
40
+ }
41
+
42
+ function getActionSheetDismiss(height: number, currentHeight: number) {
43
+ return height / 2 < currentHeight;
44
+ }
45
+
46
+ function getActionSheetExpandableDismiss(currentHight: number) {
47
+ return (
48
+ currentHight <
49
+ getActionSheetExpandableHeightByRatio(
50
+ ActionSheetExpandableHeightRatio.Bottom
51
+ ) /
52
+ 2
53
+ );
54
+ }
55
+
56
+ export function getActionSheetSnapHeight(
57
+ height: number,
58
+ currentHeight: number,
59
+ forceDismiss: boolean
60
+ ) {
61
+ return forceDismiss || getActionSheetDismiss(height, currentHeight)
62
+ ? height
63
+ : 0;
64
+ }
65
+
66
+ export function getActionSheetExpandableSnapHeight(
67
+ currentHight: number,
68
+ forceDismiss: boolean
69
+ ) {
70
+ if (forceDismiss || getActionSheetExpandableDismiss(currentHight)) {
71
+ return 0;
72
+ }
73
+
74
+ const height = getWindowDimensionsHeight();
75
+ const topHeight = getActionSheetExpandableHeightByRatio(
76
+ ActionSheetExpandableHeightRatio.Top
77
+ );
78
+ const middleHeight = getActionSheetExpandableHeightByRatio(
79
+ ActionSheetExpandableHeightRatio.Middle
80
+ );
81
+ const bottomHeight = getActionSheetExpandableHeightByRatio(
82
+ ActionSheetExpandableHeightRatio.Bottom
83
+ );
84
+ if (currentHight > middleHeight) {
85
+ return currentHight >
86
+ (height *
87
+ (ActionSheetExpandableHeightRatio.Top +
88
+ ActionSheetExpandableHeightRatio.Middle)) /
89
+ 2
90
+ ? topHeight
91
+ : middleHeight;
92
+ } else if (currentHight > bottomHeight) {
93
+ return currentHight >
94
+ (height *
95
+ (ActionSheetExpandableHeightRatio.Middle +
96
+ ActionSheetExpandableHeightRatio.Bottom)) /
97
+ 2
98
+ ? middleHeight
99
+ : bottomHeight;
100
+ } else {
101
+ return bottomHeight;
102
+ }
103
+ }
104
+
105
+ export function getActionSheetContext() {
106
+ return reactUse(ActionSheetContext);
107
+ }
@@ -0,0 +1,39 @@
1
+ import type {
2
+ SharedValue,
3
+ WithSpringConfig,
4
+ WithTimingConfig,
5
+ } from 'react-native-reanimated';
6
+ import { withSpring, withTiming } from 'react-native-reanimated';
7
+ import { scheduleOnRN } from 'react-native-worklets';
8
+
9
+ /** @internal */
10
+ export function updateSharedValWithTiming(
11
+ sharedVal: SharedValue<number>,
12
+ toVal: number,
13
+ userConfig?: WithTimingConfig,
14
+ cb?: () => void
15
+ ) {
16
+ sharedVal.set(
17
+ withTiming(toVal, userConfig, () => {
18
+ if (cb) {
19
+ scheduleOnRN(cb);
20
+ }
21
+ })
22
+ );
23
+ }
24
+
25
+ /** @internal */
26
+ export function updateSharedValWithSpring(
27
+ sharedVal: SharedValue<number>,
28
+ toVal: number,
29
+ userConfig?: WithSpringConfig,
30
+ cb?: () => void
31
+ ) {
32
+ sharedVal.set(
33
+ withSpring(toVal, userConfig, () => {
34
+ if (cb) {
35
+ scheduleOnRN(cb);
36
+ }
37
+ })
38
+ );
39
+ }
@@ -0,0 +1,23 @@
1
+ import { BorderSize } from '../theme/const';
2
+
3
+ export enum SliderValueDisplayMode {
4
+ None = 'none',
5
+ Top = 'top',
6
+ Bottom = 'bottom',
7
+ }
8
+
9
+ export enum SliderTrackSize {
10
+ S = 8,
11
+ M = 10,
12
+ L = 12,
13
+ }
14
+
15
+ export enum SliderThumbSize {
16
+ S = 20,
17
+ M = 24,
18
+ L = 28,
19
+ }
20
+
21
+ export const sliderThumbDefaultSize = SliderThumbSize.M;
22
+
23
+ export const sliderStepIndicatorDefaultWidth = BorderSize.M;
@@ -0,0 +1,4 @@
1
+ export enum Orientation {
2
+ Portrait = 'portrait',
3
+ Landscape = 'landscape',
4
+ }
@@ -0,0 +1,37 @@
1
+ import { Dimensions, StyleSheet } from 'react-native';
2
+ import type { Style, StyleOrStyleProp } from '../../types/style';
3
+
4
+ export function createStyleSheet<T extends Record<string, Style>>(styles: T) {
5
+ return StyleSheet.create<T>(styles);
6
+ }
7
+
8
+ export function composeStyles<T extends Style>(
9
+ style1?: StyleOrStyleProp<T>,
10
+ style2?: StyleOrStyleProp<T>
11
+ ) {
12
+ return StyleSheet.compose<T, T, T>(style1, style2);
13
+ }
14
+
15
+ export function flattenStyle<T extends Style>(style: StyleOrStyleProp<T>) {
16
+ return StyleSheet.flatten<T>(style);
17
+ }
18
+
19
+ export function getWindowDimensions() {
20
+ return Dimensions.get('window');
21
+ }
22
+
23
+ export function getWindowDimensionsWidth() {
24
+ return getWindowDimensions().width;
25
+ }
26
+
27
+ export function getWindowDimensionsHeight() {
28
+ return getWindowDimensions().height;
29
+ }
30
+
31
+ export function getWindowDimensionsScale() {
32
+ return getWindowDimensions().scale;
33
+ }
34
+
35
+ export function getWindowDimensionsFontScale() {
36
+ return getWindowDimensions().fontScale;
37
+ }
@@ -0,0 +1,2 @@
1
+ /** @internal */
2
+ export const switchAnimationDuration = 250;
@@ -0,0 +1,189 @@
1
+ import { createTheme } from '@shopify/restyle';
2
+ import { StyleSheet } from 'react-native';
3
+
4
+ export enum Palette {
5
+ Transparent = 'transparent',
6
+ ThemePri = '#7ccf6b',
7
+ ThemeSec = '#5aa85a',
8
+ ThemePriT = '#7ccf6b80',
9
+ Black = '#000501',
10
+ BlackT = '#00050180',
11
+ White = '#fafafa',
12
+ WhiteT = '#fafafa80',
13
+ Silver = '#c4c4c4',
14
+ Grey = '#7a7a7a',
15
+ Red = '#ff3b30',
16
+ }
17
+
18
+ export enum Spacing {
19
+ None = 0,
20
+ XXXS = 2,
21
+ XXS = 4,
22
+ XS = 6,
23
+ S = 10,
24
+ M = 16,
25
+ L = 26,
26
+ XL = 42,
27
+ XXL = 68,
28
+ XXXL = 110,
29
+ }
30
+
31
+ export enum FontSize {
32
+ XS = 12,
33
+ S = 16,
34
+ M = 20,
35
+ L = 24,
36
+ XL = 28,
37
+ }
38
+
39
+ /** @internal */
40
+ const FontLineHeightRatio = 1.4;
41
+
42
+ export enum FontLineHeight {
43
+ XS = FontSize.XS * FontLineHeightRatio,
44
+ S = FontSize.S * FontLineHeightRatio,
45
+ M = FontSize.M * FontLineHeightRatio,
46
+ L = FontSize.L * FontLineHeightRatio,
47
+ XL = FontSize.XL * FontLineHeightRatio,
48
+ }
49
+
50
+ export enum SwitchSize {
51
+ S = 16,
52
+ M = 22,
53
+ L = 28,
54
+ }
55
+
56
+ export enum BorderSize {
57
+ None = 0,
58
+ XS = StyleSheet.hairlineWidth,
59
+ S = 1,
60
+ M = 2,
61
+ L = 4,
62
+ XL = 8,
63
+ }
64
+
65
+ export enum BorderRadius {
66
+ None = 0,
67
+ S = 12,
68
+ M = 24,
69
+ L = 36,
70
+ Round = 9999,
71
+ }
72
+
73
+ export enum ZIndex {
74
+ Base = 0,
75
+ Bottom = 1,
76
+ Middle = 2,
77
+ Top = 3,
78
+ }
79
+
80
+ /** @internal */
81
+ const textVariants = {
82
+ textXS: {
83
+ fontSize: FontSize.XS,
84
+ lineHeight: FontLineHeight.XS,
85
+ color: 'text',
86
+ },
87
+ textS: {
88
+ fontSize: FontSize.S,
89
+ lineHeight: FontLineHeight.S,
90
+ color: 'text',
91
+ },
92
+ textM: {
93
+ fontSize: FontSize.M,
94
+ lineHeight: FontLineHeight.M,
95
+ color: 'text',
96
+ },
97
+ textL: {
98
+ fontSize: FontSize.L,
99
+ lineHeight: FontLineHeight.L,
100
+ color: 'text',
101
+ },
102
+ textXL: {
103
+ fontSize: FontSize.XL,
104
+ lineHeight: FontLineHeight.XL,
105
+ color: 'text',
106
+ },
107
+ };
108
+
109
+ export const lightTheme = createTheme({
110
+ colors: {
111
+ transparent: Palette.Transparent,
112
+ themePri: Palette.ThemePri,
113
+ themeSec: Palette.ThemeSec,
114
+ themePriT: Palette.ThemePriT,
115
+ background: Palette.White,
116
+ backgroundOverlay: Palette.BlackT,
117
+ text: Palette.Black,
118
+ textOverlay: Palette.White,
119
+ textButton: Palette.White,
120
+ border: Palette.Grey,
121
+ separator: Palette.Silver,
122
+ err: Palette.Red,
123
+ },
124
+ spacing: {
125
+ none: Spacing.None,
126
+ xxxs: Spacing.XXXS,
127
+ xxs: Spacing.XXS,
128
+ xs: Spacing.XS,
129
+ s: Spacing.S,
130
+ m: Spacing.M,
131
+ l: Spacing.L,
132
+ xl: Spacing.XL,
133
+ xxl: Spacing.XXL,
134
+ xxxl: Spacing.XXXL,
135
+ },
136
+ breakpoints: {
137
+ smallPhone: 0,
138
+ phone: 300,
139
+ smallTablet: 600,
140
+ tablet: 900,
141
+ desktop: 1200,
142
+ },
143
+ zIndices: {
144
+ base: ZIndex.Base,
145
+ bottom: ZIndex.Bottom,
146
+ middle: ZIndex.Middle,
147
+ top: ZIndex.Top,
148
+ },
149
+ borderRadii: {
150
+ none: BorderRadius.None,
151
+ s: BorderRadius.S,
152
+ m: BorderRadius.M,
153
+ l: BorderRadius.L,
154
+ round: BorderRadius.Round,
155
+ },
156
+ textVariants: {
157
+ ...textVariants,
158
+ textXSBold: {
159
+ ...textVariants.textXS,
160
+ fontWeight: 'bold',
161
+ },
162
+ textSBold: {
163
+ ...textVariants.textS,
164
+ fontWeight: 'bold',
165
+ },
166
+ textMBold: {
167
+ ...textVariants.textM,
168
+ fontWeight: 'bold',
169
+ },
170
+ textLBold: {
171
+ ...textVariants.textL,
172
+ fontWeight: 'bold',
173
+ },
174
+ textXLBold: {
175
+ ...textVariants.textXL,
176
+ fontWeight: 'bold',
177
+ },
178
+ defaults: textVariants.textM,
179
+ },
180
+ });
181
+
182
+ export const darkTheme: typeof lightTheme = {
183
+ ...lightTheme,
184
+ colors: {
185
+ ...lightTheme.colors,
186
+ background: Palette.Black,
187
+ text: Palette.White,
188
+ },
189
+ };
@@ -0,0 +1,87 @@
1
+ /** @internal */
2
+ import {
3
+ backgroundColor,
4
+ backgroundColorShorthand,
5
+ border,
6
+ color,
7
+ composeRestyleFunctions,
8
+ layout,
9
+ opacity,
10
+ position,
11
+ shadow,
12
+ spacing,
13
+ spacingShorthand,
14
+ } from '@shopify/restyle';
15
+ import type {
16
+ AnimatedThemedPressableProps,
17
+ ThemedPressableProps,
18
+ } from '../../types/button';
19
+ import type { IconProps, ThemedIconProps } from '../../types/icon';
20
+ import type { LoadingProps, ThemedLoadingProps } from '../../types/loading';
21
+ import type { InsetsStyleConfig } from '../../types/style';
22
+ import type { Theme } from '../../types/theme';
23
+ import type {
24
+ AnimatedThemedViewProps,
25
+ ThemedScrollViewProps,
26
+ } from '../../types/view';
27
+
28
+ const restyleBaseFuncs = [spacing, spacingShorthand, layout, position];
29
+
30
+ const restyleBackgroundFuncs = [backgroundColor, backgroundColorShorthand];
31
+
32
+ const restyleViewFuncs = [
33
+ ...restyleBaseFuncs,
34
+ ...restyleBackgroundFuncs,
35
+ opacity,
36
+ border,
37
+ shadow,
38
+ ];
39
+
40
+ export const themedPressableRestyleFuncs = composeRestyleFunctions<
41
+ Theme,
42
+ Omit<ThemedPressableProps, 'onPress' | 'scaleRatio' | 'onPressDelayConfig'>
43
+ >(restyleViewFuncs);
44
+
45
+ export const animatedThemedPressableRestyleFuncs = composeRestyleFunctions<
46
+ Theme,
47
+ Omit<
48
+ AnimatedThemedPressableProps,
49
+ 'onPress' | 'scaleRatio' | 'onPressDelayConfig' | 'animatedStyle'
50
+ >
51
+ >(restyleViewFuncs);
52
+
53
+ export const themedLoadingRestyleFuncs = composeRestyleFunctions<
54
+ Theme,
55
+ Omit<ThemedLoadingProps, keyof LoadingProps>
56
+ >(restyleBaseFuncs);
57
+
58
+ export const themedLoadingColorRestyleFuncs = composeRestyleFunctions<
59
+ Theme,
60
+ Pick<ThemedLoadingProps, 'color'>
61
+ >([
62
+ // @ts-expect-error
63
+ color,
64
+ ]);
65
+
66
+ export const themedIconRestyleFuncs = composeRestyleFunctions<
67
+ Theme,
68
+ Omit<ThemedIconProps, keyof IconProps>
69
+ >(restyleBaseFuncs);
70
+
71
+ export const themedIconColorRestyleFuncs = composeRestyleFunctions<
72
+ Theme,
73
+ Pick<ThemedIconProps, 'color'>
74
+ >([
75
+ // @ts-expect-error
76
+ color,
77
+ ]);
78
+
79
+ export const animatedThemedViewRestyleFuncs = composeRestyleFunctions<
80
+ Theme,
81
+ Omit<AnimatedThemedViewProps, 'animatedStyle'>
82
+ >(restyleViewFuncs);
83
+
84
+ export const themedScrollViewRestyleFuncs = composeRestyleFunctions<
85
+ Theme,
86
+ Omit<ThemedScrollViewProps, keyof InsetsStyleConfig | 'ref'>
87
+ >(restyleBaseFuncs);