create-react-native-starter-kit 0.0.0-stage → 1.0.1

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 (211) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +378 -2
  3. package/bin/create-react-native-starter-kit.js +95 -0
  4. package/lib/copy-src.js +127 -0
  5. package/lib/creator.js +211 -0
  6. package/lib/deps.js +58 -0
  7. package/lib/patch-configs.js +318 -0
  8. package/lib/patch-native.js +588 -0
  9. package/package.json +47 -4
  10. package/scripts/sync-template.js +52 -0
  11. package/template/.env.example +3 -0
  12. package/template/patches/react-native-element-dropdown+2.12.4.patch +67 -0
  13. package/template/src/app/App.tsx +25 -0
  14. package/template/src/app/navigation/root.tsx +24 -0
  15. package/template/src/app/navigation/stacks/app.stack.tsx +67 -0
  16. package/template/src/app/navigation/stacks/app.tab.tsx +72 -0
  17. package/template/src/app/navigation/stacks/auth.stack.tsx +56 -0
  18. package/template/src/app/providers.tsx +43 -0
  19. package/template/src/assets/fonts/InterTight-Black.ttf +0 -0
  20. package/template/src/assets/fonts/InterTight-BlackItalic.ttf +0 -0
  21. package/template/src/assets/fonts/InterTight-Bold.ttf +0 -0
  22. package/template/src/assets/fonts/InterTight-BoldItalic.ttf +0 -0
  23. package/template/src/assets/fonts/InterTight-ExtraBold.ttf +0 -0
  24. package/template/src/assets/fonts/InterTight-ExtraBoldItalic.ttf +0 -0
  25. package/template/src/assets/fonts/InterTight-ExtraLight.ttf +0 -0
  26. package/template/src/assets/fonts/InterTight-ExtraLightItalic.ttf +0 -0
  27. package/template/src/assets/fonts/InterTight-Italic.ttf +0 -0
  28. package/template/src/assets/fonts/InterTight-Light.ttf +0 -0
  29. package/template/src/assets/fonts/InterTight-LightItalic.ttf +0 -0
  30. package/template/src/assets/fonts/InterTight-Medium.ttf +0 -0
  31. package/template/src/assets/fonts/InterTight-MediumItalic.ttf +0 -0
  32. package/template/src/assets/fonts/InterTight-Regular.ttf +0 -0
  33. package/template/src/assets/fonts/InterTight-SemiBold.ttf +0 -0
  34. package/template/src/assets/fonts/InterTight-SemiBoldItalic.ttf +0 -0
  35. package/template/src/assets/fonts/InterTight-Thin.ttf +0 -0
  36. package/template/src/assets/fonts/InterTight-ThinItalic.ttf +0 -0
  37. package/template/src/assets/icons/back.svg +3 -0
  38. package/template/src/assets/icons/calendar.svg +3 -0
  39. package/template/src/assets/icons/claim_upload.svg +3 -0
  40. package/template/src/assets/icons/clock.svg +1 -0
  41. package/template/src/assets/icons/downArrow.svg +3 -0
  42. package/template/src/assets/icons/edit.svg +3 -0
  43. package/template/src/assets/icons/eye.svg +4 -0
  44. package/template/src/assets/icons/eyeClose.svg +7 -0
  45. package/template/src/assets/icons/folder.svg +5 -0
  46. package/template/src/assets/icons/home.svg +4 -0
  47. package/template/src/assets/icons/index.ts +35 -0
  48. package/template/src/assets/icons/log_out.svg +4 -0
  49. package/template/src/assets/icons/setting.svg +4 -0
  50. package/template/src/assets/icons/tabs/home/filled_dark.svg +3 -0
  51. package/template/src/assets/icons/tabs/home/filled_light.svg +3 -0
  52. package/template/src/assets/icons/tabs/home/outline.svg +4 -0
  53. package/template/src/assets/icons/tabs/index.ts +31 -0
  54. package/template/src/assets/icons/tabs/profile/filled_dark.svg +6 -0
  55. package/template/src/assets/icons/tabs/profile/filled_light.svg +6 -0
  56. package/template/src/assets/icons/tabs/profile/outline.svg +3 -0
  57. package/template/src/assets/icons/tooltip_dark.svg +1 -0
  58. package/template/src/assets/icons/tooltip_light.svg +1 -0
  59. package/template/src/assets/icons/upArrow.svg +3 -0
  60. package/template/src/assets/images/back.png +0 -0
  61. package/template/src/assets/images/index.ts +7 -0
  62. package/template/src/assets/images/placeholder/profile.png +0 -0
  63. package/template/src/components/shared/AppImage.tsx +190 -0
  64. package/template/src/components/shared/AvatarPicker.tsx +175 -0
  65. package/template/src/components/shared/CustomButton.tsx +273 -0
  66. package/template/src/components/shared/DocumentPicker.tsx +86 -0
  67. package/template/src/components/shared/GlobalLoader.tsx +47 -0
  68. package/template/src/components/shared/Icon.tsx +28 -0
  69. package/template/src/components/shared/PressableIcon.tsx +104 -0
  70. package/template/src/components/shared/bottom-sheet/BaseBottomSheet.tsx +30 -0
  71. package/template/src/components/shared/bottom-sheet/BaseBottomSheetModal.tsx +50 -0
  72. package/template/src/components/shared/bottom-sheet/sheets/ImagePickerSheet.tsx +310 -0
  73. package/template/src/components/shared/bottom-sheet/types.ts +4 -0
  74. package/template/src/components/shared/form-input/FormInput.tsx +140 -0
  75. package/template/src/components/shared/form-input/FormInputRenderer.tsx +82 -0
  76. package/template/src/components/shared/form-input/FullNameInput.tsx +243 -0
  77. package/template/src/components/shared/form-input/formFieldStyles.ts +43 -0
  78. package/template/src/components/shared/form-input/type.ts +188 -0
  79. package/template/src/components/shared/form-input/variants/CountryPhoneVariant.tsx +289 -0
  80. package/template/src/components/shared/form-input/variants/DateTimeVariant.tsx +280 -0
  81. package/template/src/components/shared/form-input/variants/DropdownVariant.tsx +221 -0
  82. package/template/src/components/shared/form-input/variants/TextInputVariant.tsx +300 -0
  83. package/template/src/components/shared/form-input/variants/ToggleVariant.tsx +194 -0
  84. package/template/src/components/shared/modal/BaseModal.tsx +83 -0
  85. package/template/src/components/shared/modal/common/AlertModal.tsx +173 -0
  86. package/template/src/components/shared/navigation/AnimatedTabIcon.tsx +37 -0
  87. package/template/src/components/shared/navigation/HeaderActionButton.tsx +70 -0
  88. package/template/src/components/shared/navigation/HeaderBackButton.tsx +38 -0
  89. package/template/src/components/shared/navigation/StackHeader.tsx +105 -0
  90. package/template/src/components/shared/navigation/tabIconRender.tsx +14 -0
  91. package/template/src/components/shared/offline/OfflineQueryBoundary.tsx +25 -0
  92. package/template/src/components/shared/offline/OfflineState.tsx +229 -0
  93. package/template/src/components/shared/offline/index.ts +6 -0
  94. package/template/src/components/shared/offline/types.ts +15 -0
  95. package/template/src/components/shared/offline/wifi-icon-animation/BrokenWifiAnimation.tsx +116 -0
  96. package/template/src/components/shared/offline/wifi-icon-animation/WifiPiece.tsx +80 -0
  97. package/template/src/components/shared/offline/wifi-icon-animation/geometry.ts +163 -0
  98. package/template/src/components/shared/offline/wifi-icon-animation/useWifiIconAnimationActive.ts +37 -0
  99. package/template/src/components/shared/skelton/BaseSkelton.tsx +71 -0
  100. package/template/src/components/shared/skelton/ShimmerHolder.ts +6 -0
  101. package/template/src/components/shared/skelton/holders/HomeShimmer.tsx +25 -0
  102. package/template/src/components/shared/skelton/holders/index.ts +1 -0
  103. package/template/src/components/shared/skelton/layouts/avatar.layout.ts +18 -0
  104. package/template/src/components/shared/skelton/layouts/home.layout.ts +16 -0
  105. package/template/src/components/shared/skelton/layouts/index.ts +3 -0
  106. package/template/src/components/shared/skelton/layouts/text.layout.ts +18 -0
  107. package/template/src/components/shared/text/CustomText.tsx +85 -0
  108. package/template/src/components/shared/text/ShimmerText.tsx +159 -0
  109. package/template/src/components/shared/text/types.ts +40 -0
  110. package/template/src/constants/device.ts +12 -0
  111. package/template/src/constants/endpoint.ts +11 -0
  112. package/template/src/constants/keyExtractor.ts +6 -0
  113. package/template/src/constants/limits.ts +9 -0
  114. package/template/src/constants/queryKey.ts +3 -0
  115. package/template/src/constants/regex.ts +7 -0
  116. package/template/src/context/NetworkContext.tsx +102 -0
  117. package/template/src/context/ThemeContext.tsx +56 -0
  118. package/template/src/hooks/app/index.ts +2 -0
  119. package/template/src/hooks/app/useGetProfile.ts +38 -0
  120. package/template/src/hooks/app/useUpdateProfile.ts +21 -0
  121. package/template/src/hooks/useAppDispatch.ts +6 -0
  122. package/template/src/hooks/useAppSelector.ts +4 -0
  123. package/template/src/hooks/useDebounce.ts +15 -0
  124. package/template/src/hooks/useDocumentPicker.ts +102 -0
  125. package/template/src/hooks/useImagePicker.ts +83 -0
  126. package/template/src/i18n/i18next.d.ts +9 -0
  127. package/template/src/i18n/index.ts +16 -0
  128. package/template/src/i18n/locales/en.json +274 -0
  129. package/template/src/i18n/locales/ru.json +165 -0
  130. package/template/src/i18n/resources.ts +11 -0
  131. package/template/src/redux/selectors/auth.selectors.ts +4 -0
  132. package/template/src/redux/slice/auth.slice.ts +23 -0
  133. package/template/src/redux/slice/loader.slice.ts +25 -0
  134. package/template/src/redux/slice/settings.slice.ts +26 -0
  135. package/template/src/redux/slice/user.slice.ts +25 -0
  136. package/template/src/screens/app/main-tab/index.tsx +73 -0
  137. package/template/src/screens/app/main-tab/style.ts +0 -0
  138. package/template/src/screens/app/profile-setup/index.tsx +162 -0
  139. package/template/src/screens/app/profile-setup/styles.ts +3 -0
  140. package/template/src/screens/auth/forgot-password/index.tsx +59 -0
  141. package/template/src/screens/auth/forgot-password/styles.ts +0 -0
  142. package/template/src/screens/auth/index.ts +4 -0
  143. package/template/src/screens/auth/login/index.tsx +138 -0
  144. package/template/src/screens/auth/login/styles.ts +3 -0
  145. package/template/src/screens/auth/signup/index.tsx +111 -0
  146. package/template/src/screens/auth/signup/styles.ts +3 -0
  147. package/template/src/screens/auth/verify-email/index.tsx +15 -0
  148. package/template/src/screens/auth/verify-email/styles.ts +3 -0
  149. package/template/src/screens/tab/home/index.tsx +49 -0
  150. package/template/src/screens/tab/home/styles.ts +3 -0
  151. package/template/src/screens/tab/index.ts +2 -0
  152. package/template/src/screens/tab/profile/index.tsx +50 -0
  153. package/template/src/screens/tab/profile/styles.ts +3 -0
  154. package/template/src/services/api/auth/auth.api.ts +22 -0
  155. package/template/src/services/api/auth/auth.endpoints.ts +7 -0
  156. package/template/src/services/api/auth/auth.types.ts +9 -0
  157. package/template/src/services/api/auth/index.ts +3 -0
  158. package/template/src/services/api/axios/axios.instance.ts +15 -0
  159. package/template/src/services/api/axios/axios.interceptors.ts +43 -0
  160. package/template/src/services/api/axios/index.ts +2 -0
  161. package/template/src/services/api/mock/mockAdapter.ts +97 -0
  162. package/template/src/services/api/user/index.ts +2 -0
  163. package/template/src/services/api/user/user.api.ts +67 -0
  164. package/template/src/services/api/user/user.endpoints.ts +0 -0
  165. package/template/src/services/api/user/user.types.ts +0 -0
  166. package/template/src/services/errors/backendErrorCodes.ts +7 -0
  167. package/template/src/services/errors/errorHandler.ts +94 -0
  168. package/template/src/services/errors/firebaseErrorMap.ts +61 -0
  169. package/template/src/services/errors/httpStatusMap.ts +47 -0
  170. package/template/src/services/errors/index.ts +4 -0
  171. package/template/src/services/network/index.ts +1 -0
  172. package/template/src/services/network/onlineManager.ts +22 -0
  173. package/template/src/services/query/index.ts +1 -0
  174. package/template/src/services/query/queryClient.ts +23 -0
  175. package/template/src/services/toast/ToastCard.tsx +137 -0
  176. package/template/src/services/toast/ToastConfig.tsx +32 -0
  177. package/template/src/services/toast/index.ts +3 -0
  178. package/template/src/services/toast/toast.ts +68 -0
  179. package/template/src/storage/mmkvAdapter.ts +3 -0
  180. package/template/src/storage/mmkvInstance.ts +16 -0
  181. package/template/src/store/index.ts +15 -0
  182. package/template/src/store/mmkv.ts +6 -0
  183. package/template/src/store/persist.ts +10 -0
  184. package/template/src/store/rootReducer.ts +26 -0
  185. package/template/src/theme/dark.ts +40 -0
  186. package/template/src/theme/fonts.ts +20 -0
  187. package/template/src/theme/index.ts +6 -0
  188. package/template/src/theme/layout.ts +23 -0
  189. package/template/src/theme/light.ts +41 -0
  190. package/template/src/theme/palette.ts +32 -0
  191. package/template/src/theme/spacing.ts +7 -0
  192. package/template/src/theme/typography.ts +80 -0
  193. package/template/src/types/api.types.ts +34 -0
  194. package/template/src/types/env.d.ts +6 -0
  195. package/template/src/types/index.ts +2 -0
  196. package/template/src/types/navigation.types.ts +94 -0
  197. package/template/src/utils/clearAppSession.ts +10 -0
  198. package/template/src/utils/date.ts +19 -0
  199. package/template/src/utils/documentPickerHandler.ts +96 -0
  200. package/template/src/utils/getFileNameFromUri.ts +18 -0
  201. package/template/src/utils/getInitials.ts +13 -0
  202. package/template/src/utils/hindiText.ts +33 -0
  203. package/template/src/utils/imageCompress.ts +97 -0
  204. package/template/src/utils/imagePickerHandler.ts +200 -0
  205. package/template/src/utils/maskPhone.ts +17 -0
  206. package/template/src/utils/normalize.ts +12 -0
  207. package/template/src/validation/messages.ts +11 -0
  208. package/template/src/validation/rules.ts +44 -0
  209. package/template/src/validation/schema/auth.schema.ts +53 -0
  210. package/template/src/validation/schema/user.schema.ts +46 -0
  211. package/template/src/validation/tValError.ts +13 -0
@@ -0,0 +1,221 @@
1
+ import { useAppTheme } from '@/context/ThemeContext';
2
+ import { DropdownItem, DropdownVariantProps } from '../type';
3
+ import { ActivityIndicator, Animated, StyleSheet, View } from 'react-native';
4
+ import { Dropdown } from 'react-native-element-dropdown';
5
+ import Icon from '../../Icon';
6
+ import { normalize } from '@/utils/normalize';
7
+ import { isHindiLanguage } from '@/utils/hindiText';
8
+ import React, { memo, useCallback, useEffect, useRef } from 'react';
9
+ import { useTranslation } from 'react-i18next';
10
+ import { FORM_FIELD, formFieldText } from '../formFieldStyles';
11
+
12
+ type RHFDropdownField = {
13
+ value: string;
14
+ onChange: (value: string) => void;
15
+ };
16
+ type DropdownFormMode = {
17
+ mode: 'form';
18
+ field: RHFDropdownField;
19
+ };
20
+
21
+ type DropdownStandaloneMode = {
22
+ mode: 'standalone';
23
+ value: string;
24
+ onChange: (value: string) => void;
25
+ };
26
+
27
+ export type DropdownVisualProps =
28
+ | (DropdownFormMode & DropdownVariantProps)
29
+ | (DropdownStandaloneMode & DropdownVariantProps);
30
+
31
+ interface AnimatedArrowProps {
32
+ visible?: boolean;
33
+ }
34
+
35
+ const AnimatedDropdownArrow = memo(
36
+ ({ visible = false }: AnimatedArrowProps) => {
37
+ const anim = useRef(new Animated.Value(visible ? 1 : 0)).current;
38
+
39
+ useEffect(() => {
40
+ Animated.spring(anim, {
41
+ toValue: visible ? 1 : 0,
42
+ friction: 7,
43
+ tension: 80,
44
+ useNativeDriver: true,
45
+ }).start();
46
+ }, [visible, anim]);
47
+
48
+ const scale = anim.interpolate({
49
+ inputRange: [0, 0.5, 1],
50
+ outputRange: [1, 0.75, 1],
51
+ });
52
+
53
+ const opacity = anim.interpolate({
54
+ inputRange: [0, 0.5, 1],
55
+ outputRange: [1, 0.7, 1],
56
+ });
57
+
58
+ return (
59
+ <Animated.View
60
+ style={[styles.trailingIconSlot, { transform: [{ scale }], opacity }]}
61
+ >
62
+ <Icon
63
+ name={visible ? 'upArrow' : 'downArrow'}
64
+ width={FORM_FIELD.iconSize}
65
+ height={FORM_FIELD.iconSize}
66
+ />
67
+ </Animated.View>
68
+ );
69
+ },
70
+ );
71
+
72
+ const DropdownVariant = (props: DropdownVisualProps) => {
73
+ const { color } = useAppTheme();
74
+ const { i18n } = useTranslation();
75
+ const isHindi = isHindiLanguage(i18n.language);
76
+
77
+ const {
78
+ dropdownData,
79
+ disabled,
80
+ placeholder,
81
+ isLoading,
82
+ onLoadMore,
83
+ onListFooterLoading,
84
+ search,
85
+ onSearchTextChange,
86
+ onDropdownSelect,
87
+ dropdownProps,
88
+ dropdownStyle,
89
+ dropdownListStyle,
90
+ mode,
91
+ } = props;
92
+
93
+ const resolvedValue = mode === 'form' ? props.field.value : props.value;
94
+
95
+ const handleChange = mode === 'form' ? props.field.onChange : props.onChange;
96
+
97
+ const renderRightIcon = useCallback(
98
+ (visible?: boolean) => {
99
+ if (dropdownProps?.renderRightIcon) {
100
+ return dropdownProps.renderRightIcon(visible);
101
+ }
102
+ if (isLoading) {
103
+ return (
104
+ <View style={styles.trailingIconSlot}>
105
+ <ActivityIndicator size="small" color={color.primary} />
106
+ </View>
107
+ );
108
+ }
109
+ return <AnimatedDropdownArrow visible={visible} />;
110
+ },
111
+ [dropdownProps, isLoading, color.primary],
112
+ );
113
+
114
+ const handleDropdownChange = useCallback(
115
+ (item: DropdownItem) => {
116
+ handleChange(item.value);
117
+ onDropdownSelect?.(item);
118
+ },
119
+ [handleChange, onDropdownSelect],
120
+ );
121
+
122
+ return (
123
+ <Dropdown
124
+ {...dropdownProps}
125
+ data={dropdownData}
126
+ labelField="label"
127
+ valueField="value"
128
+ value={resolvedValue}
129
+ disable={disabled}
130
+ showsVerticalScrollIndicator={false}
131
+ placeholder={placeholder}
132
+ style={[
133
+ styles.dropdownTrigger,
134
+ {
135
+ borderColor: color.border,
136
+ backgroundColor: disabled
137
+ ? color.disabled
138
+ : color.background_primary,
139
+ },
140
+ dropdownStyle,
141
+ ]}
142
+ containerStyle={[
143
+ styles.dropdownList,
144
+ {
145
+ borderColor: color.border,
146
+ backgroundColor: color.background_primary,
147
+ },
148
+ dropdownListStyle,
149
+ dropdownProps?.containerStyle,
150
+ ]}
151
+ placeholderStyle={[
152
+ formFieldText.dropdownText,
153
+ isHindi && formFieldText.dropdownTextHindi,
154
+ { color: color.text_placeholder },
155
+ dropdownProps?.placeholderStyle,
156
+ ]}
157
+ selectedTextStyle={[
158
+ formFieldText.dropdownText,
159
+ isHindi && formFieldText.dropdownTextHindi,
160
+ { color: color.text_primary },
161
+ dropdownProps?.selectedTextStyle,
162
+ ]}
163
+ itemTextStyle={[
164
+ formFieldText.dropdownText,
165
+ isHindi && formFieldText.dropdownTextHindi,
166
+ { color: color.text_primary },
167
+ dropdownProps?.itemTextStyle,
168
+ ]}
169
+ itemContainerStyle={dropdownProps?.itemContainerStyle}
170
+ activeColor={color.border}
171
+ renderRightIcon={renderRightIcon}
172
+ iconStyle={styles.dropdownIconStyle}
173
+ onChange={handleDropdownChange}
174
+ flatListProps={{
175
+ onEndReachedThreshold: 0.05,
176
+ onEndReached: onLoadMore,
177
+ ListFooterComponent: onListFooterLoading,
178
+ }}
179
+ search={search}
180
+ searchPlaceholder="Search..."
181
+ onChangeText={onSearchTextChange}
182
+ inputSearchStyle={{
183
+ color: color.text_primary,
184
+ borderRadius: normalize(12),
185
+ borderColor: color.border,
186
+ }}
187
+ />
188
+ );
189
+ };
190
+
191
+ export default memo(DropdownVariant);
192
+
193
+ const styles = StyleSheet.create({
194
+ dropdownTrigger: {
195
+ borderWidth: 1,
196
+ borderRadius: FORM_FIELD.radius,
197
+ height: FORM_FIELD.height,
198
+ minHeight: FORM_FIELD.height,
199
+ width: '100%',
200
+ paddingLeft: FORM_FIELD.paddingH,
201
+ paddingRight: FORM_FIELD.paddingH,
202
+ justifyContent: 'center',
203
+ },
204
+ trailingIconSlot: {
205
+ width: FORM_FIELD.iconSize,
206
+ height: FORM_FIELD.iconSize,
207
+ justifyContent: 'center',
208
+ alignItems: 'center',
209
+ },
210
+ dropdownIconStyle: {
211
+ width: FORM_FIELD.iconSize,
212
+ height: FORM_FIELD.iconSize,
213
+ marginRight: 0,
214
+ },
215
+ dropdownList: {
216
+ borderWidth: 1,
217
+ maxHeight: normalize(200),
218
+ overflow: 'hidden',
219
+ borderRadius: 5,
220
+ },
221
+ });
@@ -0,0 +1,300 @@
1
+ import { useAppTheme } from '@/context/ThemeContext';
2
+ import { FontFamily } from '@/theme';
3
+ import React, {
4
+ ComponentRef,
5
+ forwardRef,
6
+ memo,
7
+ useCallback,
8
+ useMemo,
9
+ useRef,
10
+ useState,
11
+ } from 'react';
12
+ import { StyleSheet, TextInput, Pressable, View } from 'react-native';
13
+ import { useTranslation } from 'react-i18next';
14
+ import Icon from '../../Icon';
15
+ import BaseSkelton from '../../skelton/BaseSkelton';
16
+ import { normalize } from '@/utils/normalize';
17
+ import { isHindiLanguage } from '@/utils/hindiText';
18
+ import { TextInputVariantProps } from '../type';
19
+ import { FORM_FIELD, formFieldText } from '../formFieldStyles';
20
+
21
+ type InputValue = string | number;
22
+
23
+ type RHFTextField<T = InputValue> = {
24
+ value: T;
25
+ onChange: (value: T) => void;
26
+ onBlur?: () => void;
27
+ };
28
+
29
+ type TextFormMode<T> = {
30
+ mode: 'form';
31
+ field: RHFTextField<T>;
32
+ };
33
+
34
+ type TextIndependentMode<T> = {
35
+ mode: 'standalone';
36
+ value: T;
37
+ onChangeText: (value: T) => void;
38
+ };
39
+ type TextInputVisualProps<T = InputValue> =
40
+ | (TextFormMode<T> & TextInputVariantProps)
41
+ | (TextIndependentMode<T> & TextInputVariantProps);
42
+
43
+ type TextInputInstance = ComponentRef<typeof TextInput>;
44
+
45
+ const TextInputVariant = forwardRef<TextInputInstance, TextInputVisualProps>(
46
+ (props, ref) => {
47
+ const {
48
+ mode,
49
+ disabled,
50
+ inputContainerStyle,
51
+ inputStyle,
52
+ leftIcon,
53
+ leftAdornment,
54
+ leftAdornmentStyle,
55
+ textInputProps,
56
+ rightIcon,
57
+ placeholder = 'Enter text',
58
+ isPassword = false,
59
+ focusOnContainerPress = true,
60
+ isLoading = false,
61
+ digitsOnly = false,
62
+ } = props;
63
+
64
+ const { color } = useAppTheme();
65
+ const { i18n } = useTranslation();
66
+ const isHindi = isHindiLanguage(i18n.language);
67
+ const [isPasswordVisible, setIsPasswordVisible] = useState(false);
68
+ const inputRef = useRef<TextInputInstance | null>(null);
69
+
70
+ const setRefs = useCallback(
71
+ (node: TextInputInstance | null) => {
72
+ inputRef.current = node;
73
+ if (typeof ref === 'function') {
74
+ ref(node);
75
+ } else if (ref) {
76
+ ref.current = node;
77
+ }
78
+ },
79
+ [ref],
80
+ );
81
+
82
+ const togglePassword = useCallback(() => {
83
+ setIsPasswordVisible(prev => !prev);
84
+ }, []);
85
+
86
+ const resolvedValue = mode === 'form' ? props.field.value : props.value;
87
+ const handleChange =
88
+ mode === 'form' ? props.field.onChange : props.onChangeText;
89
+ const handleBlur = mode === 'form' ? props.field.onBlur : undefined;
90
+ const isNumberValue = typeof resolvedValue === 'number';
91
+
92
+ const onChangeText = useCallback(
93
+ (text: string) => {
94
+ const nextText = digitsOnly ? text.replace(/\D/g, '') : text;
95
+
96
+ if (isNumberValue) {
97
+ const next = nextText === '' ? 0 : Number(nextText);
98
+ handleChange?.(next as never);
99
+ return;
100
+ }
101
+ handleChange?.(nextText as never);
102
+ },
103
+ [digitsOnly, handleChange, isNumberValue],
104
+ );
105
+
106
+ const isMultiline = Boolean(textInputProps?.multiline);
107
+ const { style: customTextInputStyle, ...restTextInputProps } =
108
+ textInputProps || {};
109
+
110
+ const wrapperToneStyle = useMemo(
111
+ () => ({
112
+ backgroundColor: disabled
113
+ ? color.disabled
114
+ : color.background_primary,
115
+ borderColor: color.border,
116
+ }),
117
+ [color.background_primary, color.border, color.disabled, disabled],
118
+ );
119
+
120
+ const inputColorStyle = useMemo(
121
+ () => ({ color: color.text_primary }),
122
+ [color.text_primary],
123
+ );
124
+
125
+ const fieldShimmerLayout = useMemo(
126
+ () => [
127
+ {
128
+ key: 'textField',
129
+ width: '100%' as const,
130
+ height: FORM_FIELD.height,
131
+ borderRadius: FORM_FIELD.radius,
132
+ },
133
+ ],
134
+ [],
135
+ );
136
+
137
+ if (isLoading) {
138
+ return (
139
+ <BaseSkelton
140
+ isLoading
141
+ layout={fieldShimmerLayout}
142
+ containerStyle={styles.shimmer}
143
+ />
144
+ );
145
+ }
146
+
147
+ return (
148
+ <View
149
+ collapsable={false}
150
+ onTouchEnd={() => {
151
+ if (!disabled && focusOnContainerPress && !leftAdornment) {
152
+ inputRef.current?.focus();
153
+ }
154
+ }}
155
+ style={[
156
+ styles.wrapper,
157
+ isMultiline && styles.multilineWrapper,
158
+ wrapperToneStyle,
159
+ inputContainerStyle,
160
+ ]}
161
+ >
162
+ {leftAdornment ? (
163
+ <View style={[styles.leftAdornment, leftAdornmentStyle]}>
164
+ {leftAdornment}
165
+ </View>
166
+ ) : (
167
+ leftIcon && (
168
+ <Pressable
169
+ style={[styles.leftIcon, isMultiline && styles.multilineIcon]}
170
+ disabled={disabled}
171
+ hitSlop={20}
172
+ >
173
+ {leftIcon}
174
+ </Pressable>
175
+ )
176
+ )}
177
+
178
+ <View
179
+ collapsable={false}
180
+ style={[styles.inputFlex, isMultiline && styles.multilineInputFlex]}
181
+ >
182
+ <TextInput
183
+ ref={setRefs}
184
+ value={String(resolvedValue ?? '')}
185
+ onChangeText={onChangeText}
186
+ onBlur={handleBlur}
187
+ editable={!disabled}
188
+ placeholderTextColor={color.text_placeholder}
189
+ secureTextEntry={isPassword && !isPasswordVisible}
190
+ placeholder={placeholder}
191
+ cursorColor={color.text_primary}
192
+ allowFontScaling={false}
193
+ underlineColorAndroid="transparent"
194
+ {...restTextInputProps}
195
+ style={[
196
+ styles.input,
197
+ formFieldText.input,
198
+ isHindi && formFieldText.inputHindi,
199
+ inputColorStyle,
200
+ isMultiline && styles.multilineInput,
201
+ isMultiline && isHindi && styles.multilineInputHindi,
202
+ leftAdornment ? styles.inputWithAdornment : undefined,
203
+ inputStyle,
204
+ customTextInputStyle,
205
+ ]}
206
+ />
207
+ </View>
208
+
209
+ {isPassword && (
210
+ <Pressable
211
+ onPress={togglePassword}
212
+ style={[styles.rightIcon, isMultiline && styles.multilineIcon]}
213
+ disabled={disabled}
214
+ hitSlop={20}
215
+ >
216
+ <Icon name={isPasswordVisible ? 'eye' : 'eyeClose'} size={22} />
217
+ </Pressable>
218
+ )}
219
+
220
+ {rightIcon && (
221
+ <Pressable
222
+ style={[styles.rightIcon, isMultiline && styles.multilineIcon]}
223
+ disabled={disabled}
224
+ hitSlop={20}
225
+ >
226
+ {rightIcon}
227
+ </Pressable>
228
+ )}
229
+ </View>
230
+ );
231
+ },
232
+ );
233
+
234
+ export default memo(TextInputVariant);
235
+
236
+ const styles = StyleSheet.create({
237
+ shimmer: {
238
+ width: '100%',
239
+ },
240
+ wrapper: {
241
+ flexDirection: 'row',
242
+ alignItems: 'center',
243
+ borderWidth: 1,
244
+ borderRadius: FORM_FIELD.radius,
245
+ height: FORM_FIELD.height,
246
+ minHeight: FORM_FIELD.height,
247
+ width: '100%',
248
+ paddingHorizontal: FORM_FIELD.paddingH,
249
+ },
250
+ multilineWrapper: {
251
+ minHeight: normalize(100),
252
+ height: undefined,
253
+ alignItems: 'stretch',
254
+ paddingVertical: 0,
255
+ },
256
+ inputFlex: {
257
+ flex: 1,
258
+ minWidth: 0,
259
+ justifyContent: 'center',
260
+ },
261
+ multilineInputFlex: {
262
+ alignSelf: 'stretch',
263
+ },
264
+ input: {
265
+ paddingVertical: 0,
266
+ },
267
+ multilineInput: {
268
+ height: undefined,
269
+ fontSize: FORM_FIELD.fontSize,
270
+ fontFamily: FontFamily.InterTightRegular,
271
+ textAlignVertical: 'top',
272
+ paddingTop: 12,
273
+ paddingBottom: 12,
274
+ minHeight: normalize(100),
275
+ width: '100%',
276
+ alignSelf: 'stretch',
277
+ includeFontPadding: false,
278
+ },
279
+ multilineInputHindi: {
280
+ includeFontPadding: true,
281
+ paddingTop: 14,
282
+ paddingBottom: 14,
283
+ },
284
+ leftAdornment: {
285
+ flexShrink: 0,
286
+ },
287
+ inputWithAdornment: {
288
+ width: '100%',
289
+ paddingHorizontal: 0,
290
+ },
291
+ leftIcon: {
292
+ marginRight: 8,
293
+ },
294
+ rightIcon: {
295
+ marginLeft: 8,
296
+ },
297
+ multilineIcon: {
298
+ marginTop: 14,
299
+ },
300
+ });
@@ -0,0 +1,194 @@
1
+ import { useAppTheme } from '@/context/ThemeContext';
2
+ import { normalize } from '@/utils/normalize';
3
+ import React, { memo, useEffect } from 'react';
4
+ import {
5
+ View,
6
+ Pressable,
7
+ StyleSheet,
8
+ ViewStyle,
9
+ } from 'react-native';
10
+ import Animated, {
11
+ useSharedValue,
12
+ useAnimatedStyle,
13
+ withTiming,
14
+ } from 'react-native-reanimated';
15
+ import CustomText from '@/components/shared/text/CustomText';
16
+ import { ToggleVariantProps } from '../type';
17
+
18
+ type RHFToggleField = {
19
+ value: boolean;
20
+ onChange: (value: boolean) => void;
21
+ };
22
+ type ToggleFormMode = {
23
+ mode: 'form';
24
+ field: RHFToggleField;
25
+ };
26
+
27
+ type ToggleStandaloneMode = {
28
+ mode: 'standalone';
29
+ value: boolean;
30
+ onChange: (value: boolean) => void;
31
+ alignToggle?: ViewStyle['alignItems'];
32
+ };
33
+
34
+ export type ToggleVisualProps =
35
+ | (ToggleFormMode & ToggleVariantProps)
36
+ | (ToggleStandaloneMode & ToggleVariantProps);
37
+
38
+ const SIZE_MAP = {
39
+ sm: {
40
+ width: 52,
41
+ height: 26,
42
+ thumb: 22,
43
+ padding: 2,
44
+ labelSize: normalize(9),
45
+ },
46
+ md: {
47
+ width: 60,
48
+ height: 32,
49
+ thumb: 28,
50
+ padding: 2,
51
+ labelSize: normalize(11),
52
+ },
53
+ } as const;
54
+
55
+ const Toggle = (props: ToggleVisualProps) => {
56
+ const {
57
+ disabled = false,
58
+ size = 'md',
59
+
60
+ showLabel = true,
61
+ onLabel = 'ON',
62
+ offLabel = 'OFF',
63
+
64
+ activeColor,
65
+ inactiveColor,
66
+ thumbColor,
67
+ styles: styleOverrides,
68
+ mode,
69
+ } = props;
70
+
71
+ const { width, height, thumb, padding, labelSize } = SIZE_MAP[size];
72
+ const { color } = useAppTheme();
73
+ const resolvedValue = mode === 'form' ? props.field.value : props.value;
74
+ const handleChange = mode === 'form' ? props.field.onChange : props.onChange;
75
+ const labelJustify = resolvedValue ? 'flex-start' : 'flex-end';
76
+ const alignToggleEnd: ViewStyle['alignItems'] =
77
+ mode === 'standalone' && props.alignToggle ? props.alignToggle : 'flex-end';
78
+ const thumbCont = {
79
+ width: thumb,
80
+ height: thumb,
81
+ borderRadius: thumb / 2,
82
+ backgroundColor: thumbColor || color.background_primary,
83
+ right: size === 'sm' ? 28 : 30,
84
+ };
85
+ const pressableOpacity = disabled ? 0.6 : 1.0;
86
+ const activeClr = activeColor || color.primary;
87
+ const inactiveClr = inactiveColor || color.placeholder;
88
+ const formWrapper: ViewStyle =
89
+ mode === 'form'
90
+ ? { position: 'absolute', right: 0 }
91
+ : { position: 'relative' };
92
+
93
+ const travelDistance = width - thumb - padding * 2;
94
+
95
+ const translateX = useSharedValue(resolvedValue ? travelDistance : 0);
96
+
97
+ useEffect(() => {
98
+ translateX.value = withTiming(resolvedValue ? travelDistance : 0, {
99
+ duration: 180,
100
+ });
101
+ }, [resolvedValue, travelDistance, translateX]);
102
+
103
+ const thumbStyle = useAnimatedStyle(() => ({
104
+ transform: [{ translateX: translateX.value }],
105
+ }));
106
+
107
+ const handlePress = () => {
108
+ handleChange?.(!resolvedValue);
109
+ };
110
+
111
+ return (
112
+ <Pressable
113
+ onPress={handlePress}
114
+ accessibilityRole="switch"
115
+ accessibilityState={{ checked: resolvedValue, disabled }}
116
+ style={[
117
+ { opacity: pressableOpacity, alignItems: alignToggleEnd },
118
+ formWrapper,
119
+ styleOverrides?.wrapper,
120
+ ]}
121
+ disabled={disabled}
122
+ >
123
+ {/* Track */}
124
+ <View
125
+ style={[
126
+ styles.track,
127
+ {
128
+ width,
129
+ height,
130
+ borderRadius: height / 2,
131
+ padding,
132
+ backgroundColor: resolvedValue ? activeClr : inactiveClr,
133
+ },
134
+ styleOverrides?.track,
135
+ ]}
136
+ >
137
+ {/* ON / OFF Label (SAFE, CONDITIONAL) */}
138
+ {showLabel && (
139
+ <View
140
+ pointerEvents="none"
141
+ style={[
142
+ styles.labelContainer,
143
+ {
144
+ justifyContent: labelJustify,
145
+ },
146
+ styles.labelContainer,
147
+ ]}
148
+ >
149
+ <CustomText
150
+ variant="label"
151
+ weight="600"
152
+ numberOfLines={1}
153
+ ellipsizeMode="clip"
154
+ textColor={color.text_default}
155
+ textAlign="center"
156
+ style={[styles.label, { fontSize: labelSize }, styleOverrides?.label]}
157
+ >
158
+ {resolvedValue ? onLabel : offLabel}
159
+ </CustomText>
160
+ </View>
161
+ )}
162
+
163
+ {/* Thumb */}
164
+ <Animated.View
165
+ style={[styles.thumb, thumbCont, thumbStyle, styleOverrides?.thumb]}
166
+ />
167
+ </View>
168
+ </Pressable>
169
+ );
170
+ };
171
+
172
+ export default memo(Toggle);
173
+
174
+ const styles = StyleSheet.create({
175
+ track: {
176
+ justifyContent: 'center',
177
+ },
178
+ thumb: {
179
+ position: 'absolute',
180
+ elevation: 2,
181
+ },
182
+ labelContainer: {
183
+ position: 'absolute',
184
+ top: 0,
185
+ bottom: 0,
186
+ flexDirection: 'row',
187
+ alignItems: 'center',
188
+ left: 6,
189
+ right: 6,
190
+ },
191
+ label: {
192
+ marginBottom: 0,
193
+ },
194
+ });