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

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 (210) 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 +387 -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 +33 -0
  48. package/template/src/assets/icons/setting.svg +4 -0
  49. package/template/src/assets/icons/tabs/home/filled_dark.svg +3 -0
  50. package/template/src/assets/icons/tabs/home/filled_light.svg +3 -0
  51. package/template/src/assets/icons/tabs/home/outline.svg +4 -0
  52. package/template/src/assets/icons/tabs/index.ts +31 -0
  53. package/template/src/assets/icons/tabs/profile/filled_dark.svg +6 -0
  54. package/template/src/assets/icons/tabs/profile/filled_light.svg +6 -0
  55. package/template/src/assets/icons/tabs/profile/outline.svg +3 -0
  56. package/template/src/assets/icons/tooltip_dark.svg +1 -0
  57. package/template/src/assets/icons/tooltip_light.svg +1 -0
  58. package/template/src/assets/icons/upArrow.svg +3 -0
  59. package/template/src/assets/images/back.png +0 -0
  60. package/template/src/assets/images/index.ts +7 -0
  61. package/template/src/assets/images/placeholder/profile.png +0 -0
  62. package/template/src/components/shared/AppImage.tsx +190 -0
  63. package/template/src/components/shared/AvatarPicker.tsx +175 -0
  64. package/template/src/components/shared/CustomButton.tsx +273 -0
  65. package/template/src/components/shared/DocumentPicker.tsx +86 -0
  66. package/template/src/components/shared/GlobalLoader.tsx +47 -0
  67. package/template/src/components/shared/Icon.tsx +28 -0
  68. package/template/src/components/shared/PressableIcon.tsx +104 -0
  69. package/template/src/components/shared/bottom-sheet/BaseBottomSheet.tsx +30 -0
  70. package/template/src/components/shared/bottom-sheet/BaseBottomSheetModal.tsx +50 -0
  71. package/template/src/components/shared/bottom-sheet/sheets/ImagePickerSheet.tsx +310 -0
  72. package/template/src/components/shared/bottom-sheet/types.ts +4 -0
  73. package/template/src/components/shared/form-input/FormInput.tsx +139 -0
  74. package/template/src/components/shared/form-input/FormInputRenderer.tsx +82 -0
  75. package/template/src/components/shared/form-input/FullNameInput.tsx +243 -0
  76. package/template/src/components/shared/form-input/formFieldStyles.ts +43 -0
  77. package/template/src/components/shared/form-input/type.ts +188 -0
  78. package/template/src/components/shared/form-input/variants/CountryPhoneVariant.tsx +289 -0
  79. package/template/src/components/shared/form-input/variants/DateTimeVariant.tsx +280 -0
  80. package/template/src/components/shared/form-input/variants/DropdownVariant.tsx +221 -0
  81. package/template/src/components/shared/form-input/variants/TextInputVariant.tsx +300 -0
  82. package/template/src/components/shared/form-input/variants/ToggleVariant.tsx +194 -0
  83. package/template/src/components/shared/modal/BaseModal.tsx +83 -0
  84. package/template/src/components/shared/modal/common/AlertModal.tsx +173 -0
  85. package/template/src/components/shared/navigation/AnimatedTabIcon.tsx +37 -0
  86. package/template/src/components/shared/navigation/HeaderActionButton.tsx +70 -0
  87. package/template/src/components/shared/navigation/HeaderBackButton.tsx +38 -0
  88. package/template/src/components/shared/navigation/StackHeader.tsx +105 -0
  89. package/template/src/components/shared/navigation/tabIconRender.tsx +14 -0
  90. package/template/src/components/shared/offline/OfflineQueryBoundary.tsx +25 -0
  91. package/template/src/components/shared/offline/OfflineState.tsx +229 -0
  92. package/template/src/components/shared/offline/index.ts +6 -0
  93. package/template/src/components/shared/offline/types.ts +15 -0
  94. package/template/src/components/shared/offline/wifi-icon-animation/BrokenWifiAnimation.tsx +116 -0
  95. package/template/src/components/shared/offline/wifi-icon-animation/WifiPiece.tsx +80 -0
  96. package/template/src/components/shared/offline/wifi-icon-animation/geometry.ts +163 -0
  97. package/template/src/components/shared/offline/wifi-icon-animation/useWifiIconAnimationActive.ts +37 -0
  98. package/template/src/components/shared/skelton/BaseSkelton.tsx +71 -0
  99. package/template/src/components/shared/skelton/ShimmerHolder.ts +6 -0
  100. package/template/src/components/shared/skelton/holders/HomeShimmer.tsx +25 -0
  101. package/template/src/components/shared/skelton/holders/index.ts +1 -0
  102. package/template/src/components/shared/skelton/layouts/avatar.layout.ts +18 -0
  103. package/template/src/components/shared/skelton/layouts/home.layout.ts +26 -0
  104. package/template/src/components/shared/skelton/layouts/index.ts +3 -0
  105. package/template/src/components/shared/skelton/layouts/text.layout.ts +18 -0
  106. package/template/src/components/shared/text/CustomText.tsx +85 -0
  107. package/template/src/components/shared/text/ShimmerText.tsx +159 -0
  108. package/template/src/components/shared/text/types.ts +40 -0
  109. package/template/src/constants/device.ts +12 -0
  110. package/template/src/constants/endpoint.ts +11 -0
  111. package/template/src/constants/keyExtractor.ts +6 -0
  112. package/template/src/constants/limits.ts +9 -0
  113. package/template/src/constants/queryKey.ts +3 -0
  114. package/template/src/constants/regex.ts +7 -0
  115. package/template/src/context/NetworkContext.tsx +102 -0
  116. package/template/src/context/ThemeContext.tsx +56 -0
  117. package/template/src/hooks/app/index.ts +2 -0
  118. package/template/src/hooks/app/useGetProfile.ts +38 -0
  119. package/template/src/hooks/app/useUpdateProfile.ts +21 -0
  120. package/template/src/hooks/useAppDispatch.ts +6 -0
  121. package/template/src/hooks/useAppSelector.ts +4 -0
  122. package/template/src/hooks/useDebounce.ts +15 -0
  123. package/template/src/hooks/useDocumentPicker.ts +102 -0
  124. package/template/src/hooks/useImagePicker.ts +83 -0
  125. package/template/src/i18n/i18next.d.ts +9 -0
  126. package/template/src/i18n/index.ts +16 -0
  127. package/template/src/i18n/locales/en.json +274 -0
  128. package/template/src/i18n/locales/ru.json +165 -0
  129. package/template/src/i18n/resources.ts +11 -0
  130. package/template/src/redux/selectors/auth.selectors.ts +4 -0
  131. package/template/src/redux/slice/auth.slice.ts +23 -0
  132. package/template/src/redux/slice/loader.slice.ts +25 -0
  133. package/template/src/redux/slice/settings.slice.ts +26 -0
  134. package/template/src/redux/slice/user.slice.ts +25 -0
  135. package/template/src/screens/app/main-tab/index.tsx +73 -0
  136. package/template/src/screens/app/main-tab/style.ts +0 -0
  137. package/template/src/screens/app/profile-setup/index.tsx +161 -0
  138. package/template/src/screens/app/profile-setup/styles.ts +3 -0
  139. package/template/src/screens/auth/forgot-password/index.tsx +59 -0
  140. package/template/src/screens/auth/forgot-password/styles.ts +0 -0
  141. package/template/src/screens/auth/index.ts +4 -0
  142. package/template/src/screens/auth/login/index.tsx +137 -0
  143. package/template/src/screens/auth/login/styles.ts +3 -0
  144. package/template/src/screens/auth/signup/index.tsx +110 -0
  145. package/template/src/screens/auth/signup/styles.ts +3 -0
  146. package/template/src/screens/auth/verify-email/index.tsx +15 -0
  147. package/template/src/screens/auth/verify-email/styles.ts +3 -0
  148. package/template/src/screens/tab/home/index.tsx +49 -0
  149. package/template/src/screens/tab/home/styles.ts +3 -0
  150. package/template/src/screens/tab/index.ts +2 -0
  151. package/template/src/screens/tab/profile/index.tsx +50 -0
  152. package/template/src/screens/tab/profile/styles.ts +3 -0
  153. package/template/src/services/api/auth/auth.api.ts +22 -0
  154. package/template/src/services/api/auth/auth.endpoints.ts +7 -0
  155. package/template/src/services/api/auth/auth.types.ts +9 -0
  156. package/template/src/services/api/auth/index.ts +3 -0
  157. package/template/src/services/api/axios/axios.instance.ts +15 -0
  158. package/template/src/services/api/axios/axios.interceptors.ts +43 -0
  159. package/template/src/services/api/axios/index.ts +2 -0
  160. package/template/src/services/api/mock/mockAdapter.ts +97 -0
  161. package/template/src/services/api/user/index.ts +2 -0
  162. package/template/src/services/api/user/user.api.ts +67 -0
  163. package/template/src/services/api/user/user.endpoints.ts +0 -0
  164. package/template/src/services/api/user/user.types.ts +0 -0
  165. package/template/src/services/errors/backendErrorCodes.ts +7 -0
  166. package/template/src/services/errors/errorHandler.ts +94 -0
  167. package/template/src/services/errors/firebaseErrorMap.ts +61 -0
  168. package/template/src/services/errors/httpStatusMap.ts +47 -0
  169. package/template/src/services/errors/index.ts +4 -0
  170. package/template/src/services/network/index.ts +1 -0
  171. package/template/src/services/network/onlineManager.ts +22 -0
  172. package/template/src/services/query/index.ts +1 -0
  173. package/template/src/services/query/queryClient.ts +23 -0
  174. package/template/src/services/toast/ToastCard.tsx +137 -0
  175. package/template/src/services/toast/ToastConfig.tsx +32 -0
  176. package/template/src/services/toast/index.ts +3 -0
  177. package/template/src/services/toast/toast.ts +68 -0
  178. package/template/src/storage/mmkvAdapter.ts +3 -0
  179. package/template/src/storage/mmkvInstance.ts +16 -0
  180. package/template/src/store/index.ts +15 -0
  181. package/template/src/store/mmkv.ts +6 -0
  182. package/template/src/store/persist.ts +10 -0
  183. package/template/src/store/rootReducer.ts +26 -0
  184. package/template/src/theme/dark.ts +40 -0
  185. package/template/src/theme/fonts.ts +20 -0
  186. package/template/src/theme/index.ts +6 -0
  187. package/template/src/theme/layout.ts +22 -0
  188. package/template/src/theme/light.ts +41 -0
  189. package/template/src/theme/palette.ts +32 -0
  190. package/template/src/theme/spacing.ts +7 -0
  191. package/template/src/theme/typography.ts +80 -0
  192. package/template/src/types/api.types.ts +34 -0
  193. package/template/src/types/env.d.ts +6 -0
  194. package/template/src/types/index.ts +2 -0
  195. package/template/src/types/navigation.types.ts +94 -0
  196. package/template/src/utils/clearAppSession.ts +10 -0
  197. package/template/src/utils/date.ts +19 -0
  198. package/template/src/utils/documentPickerHandler.ts +96 -0
  199. package/template/src/utils/getFileNameFromUri.ts +18 -0
  200. package/template/src/utils/getInitials.ts +13 -0
  201. package/template/src/utils/hindiText.ts +33 -0
  202. package/template/src/utils/imageCompress.ts +97 -0
  203. package/template/src/utils/imagePickerHandler.ts +200 -0
  204. package/template/src/utils/maskPhone.ts +17 -0
  205. package/template/src/utils/normalize.ts +12 -0
  206. package/template/src/validation/messages.ts +11 -0
  207. package/template/src/validation/rules.ts +44 -0
  208. package/template/src/validation/schema/auth.schema.ts +53 -0
  209. package/template/src/validation/schema/user.schema.ts +46 -0
  210. package/template/src/validation/tValError.ts +13 -0
@@ -0,0 +1,289 @@
1
+ import React, { forwardRef, memo } from 'react';
2
+ import { StyleSheet } from 'react-native';
3
+ import PhoneInput, {
4
+ IPhoneInputRef,
5
+ } from 'rn-international-phone-number';
6
+ import { useAppTheme } from '@/context/ThemeContext';
7
+ import { CountryPhoneVariantProps } from '../type';
8
+ import { FORM_FIELD } from '../formFieldStyles';
9
+ import { FontFamily } from '@/theme';
10
+ import { normalize } from '@/utils/normalize';
11
+
12
+ type RHFPhoneField = {
13
+ value: string;
14
+ onChange: (value: string) => void;
15
+ };
16
+
17
+ type FormModeProps = {
18
+ mode: 'form';
19
+ field: RHFPhoneField;
20
+ };
21
+
22
+ type StandaloneModeProps = {
23
+ mode: 'standalone';
24
+ value: string;
25
+ onChange: (value: string) => void;
26
+ };
27
+
28
+ export type CountryPhoneVisualProps =
29
+ | (FormModeProps & CountryPhoneVariantProps)
30
+ | (StandaloneModeProps & CountryPhoneVariantProps);
31
+
32
+ const CountryPhoneVariant = forwardRef<IPhoneInputRef, CountryPhoneVisualProps>(
33
+ (props, ref) => {
34
+ const { color } = useAppTheme();
35
+ const {
36
+ mode,
37
+ appearance = 'login',
38
+ countryContainerStyle,
39
+ defaultCountry = 'IN',
40
+ showFlag = true,
41
+ disabled,
42
+ modalDisabled = false,
43
+ onChangeSelectedCountry,
44
+ phoneInputProps,
45
+ placeholder = 'Enter phone number',
46
+ } = props;
47
+
48
+ const resolvedValue = mode === 'form' ? props.field.value : props.value;
49
+ const handleChange =
50
+ mode === 'form' ? props.field.onChange : props.onChange;
51
+ const showCountryCaret = showFlag && !modalDisabled;
52
+ const isFieldAppearance = appearance === 'field';
53
+ const chrome = isFieldAppearance ? fieldChrome : loginChrome;
54
+ const fillColor = disabled
55
+ ? color.disabled
56
+ : isFieldAppearance
57
+ ? color.background_primary
58
+ : color.background_secondary;
59
+ const prefixFillColor = disabled
60
+ ? color.disabled
61
+ : color.background_primary;
62
+ const placeholderColor = isFieldAppearance
63
+ ? color.text_placeholder
64
+ : color.placeholder;
65
+
66
+ return (
67
+ <PhoneInput
68
+ ref={ref ?? null}
69
+ value={resolvedValue ?? ''}
70
+ defaultCountry={defaultCountry}
71
+ onChangePhoneNumber={handleChange}
72
+ onChangeCountry={onChangeSelectedCountry}
73
+ allowFontScaling={false}
74
+ disabled={disabled}
75
+ modalDisabled={modalDisabled}
76
+ customFlag={isFieldAppearance ? () => null : undefined}
77
+ customCaret={
78
+ isFieldAppearance ? (() => null as unknown as React.ReactElement) : undefined
79
+ }
80
+ phoneInputStyles={{
81
+ flag: showFlag
82
+ ? { display: 'flex' }
83
+ : {
84
+ display: 'none',
85
+ width: 0,
86
+ height: 0,
87
+ margin: 0,
88
+ padding: 0,
89
+ },
90
+ caret: showCountryCaret
91
+ ? { display: 'flex', color: color.text_primary }
92
+ : {
93
+ display: 'none',
94
+ width: 0,
95
+ height: 0,
96
+ margin: 0,
97
+ padding: 0,
98
+ color: color.text_primary,
99
+ },
100
+ divider: isFieldAppearance
101
+ ? {
102
+ display: 'none',
103
+ width: 0,
104
+ height: 0,
105
+ marginHorizontal: 0,
106
+ marginLeft: 0,
107
+ marginRight: 0,
108
+ }
109
+ : {
110
+ display: showCountryCaret ? 'flex' : 'none',
111
+ width: showCountryCaret ? undefined : 0,
112
+ height: showCountryCaret ? undefined : 0,
113
+ opacity: showCountryCaret ? 1 : 0,
114
+ margin: showCountryCaret ? undefined : 0,
115
+ padding: showCountryCaret ? undefined : 0,
116
+ backgroundColor: showCountryCaret
117
+ ? color.border
118
+ : 'transparent',
119
+ },
120
+ container: [
121
+ chrome.container,
122
+ {
123
+ backgroundColor: fillColor,
124
+ borderColor: color.border,
125
+ },
126
+ countryContainerStyle,
127
+ ],
128
+ callingCode: [
129
+ chrome.callingCode,
130
+ {
131
+ color: color.text_primary,
132
+ },
133
+ ],
134
+ input: [
135
+ chrome.input,
136
+ { color: color.text_primary },
137
+ ],
138
+ flagContainer: isFieldAppearance
139
+ ? {
140
+ ...fieldChrome.flagContainer,
141
+ backgroundColor: prefixFillColor,
142
+ }
143
+ : [
144
+ chrome.flagContainer,
145
+ {
146
+ backgroundColor: prefixFillColor,
147
+ },
148
+ !showFlag && chrome.flagContainerNoFlag,
149
+ ],
150
+ }}
151
+ placeholder={placeholder}
152
+ cursorColor={color.text_primary}
153
+ modalStyles={{
154
+ countryItem: { backgroundColor: color.background_primary },
155
+ content: { backgroundColor: color.background_secondary },
156
+ countryName: { color: color.text_primary },
157
+ callingCode: { color: color.text_primary },
158
+ searchInput: [
159
+ styles.searchInput,
160
+ {
161
+ backgroundColor: color.background_primary,
162
+ color: color.text_primary,
163
+ },
164
+ ],
165
+ countryNotFoundMessage: {
166
+ color: color.text_primary,
167
+ },
168
+ alphabetLetterText: { color: color.text_primary },
169
+ alphabetLetterTextActive: { color: color.text_primary },
170
+ }}
171
+ modalSearchInputPlaceholderTextColor={placeholderColor}
172
+ placeholderTextColor={placeholderColor}
173
+ keyboardType="number-pad"
174
+ {...phoneInputProps}
175
+ />
176
+ );
177
+ },
178
+ );
179
+
180
+ export default memo(CountryPhoneVariant);
181
+
182
+ const loginChrome = StyleSheet.create({
183
+ container: {
184
+ flexDirection: 'row',
185
+ alignItems: 'center',
186
+ borderWidth: 1,
187
+ borderRadius: 12,
188
+ paddingRight: 12,
189
+ minHeight: normalize(52),
190
+ borderTopWidth: 1.5,
191
+ },
192
+ callingCode: {
193
+ paddingRight: 18,
194
+ fontSize: normalize(16),
195
+ lineHeight: normalize(20),
196
+ fontFamily: FontFamily.InterTightMedium,
197
+ includeFontPadding: false,
198
+ textAlignVertical: 'center',
199
+ },
200
+ input: {
201
+ flex: 1,
202
+ height: '100%',
203
+ fontSize: normalize(16),
204
+ fontFamily: FontFamily.InterTightRegular,
205
+ paddingTop: 0,
206
+ paddingBottom: 0,
207
+ paddingVertical: 0,
208
+ margin: 0,
209
+ includeFontPadding: false,
210
+ textAlignVertical: 'center',
211
+ },
212
+ flagContainer: {
213
+ borderTopLeftRadius: 12,
214
+ borderBottomLeftRadius: 12,
215
+ paddingLeft: 12,
216
+ alignItems: 'center',
217
+ justifyContent: 'center',
218
+ paddingRight: 0,
219
+ alignSelf: 'stretch',
220
+ },
221
+ flagContainerNoFlag: {
222
+ paddingLeft: 14,
223
+ },
224
+ });
225
+
226
+ const fieldChrome = StyleSheet.create({
227
+ container: {
228
+ flexDirection: 'row',
229
+ alignItems: 'center',
230
+ borderWidth: 1,
231
+ borderRadius: FORM_FIELD.radius,
232
+ height: FORM_FIELD.height,
233
+ minHeight: FORM_FIELD.height,
234
+ paddingLeft: FORM_FIELD.paddingH,
235
+ paddingRight: FORM_FIELD.paddingH,
236
+ },
237
+ callingCode: {
238
+ paddingLeft: 0,
239
+ paddingRight: 6,
240
+ margin: 0,
241
+ fontSize: FORM_FIELD.fontSize,
242
+ lineHeight: FORM_FIELD.lineHeight,
243
+ fontFamily: FontFamily.InterTightRegular,
244
+ includeFontPadding: false,
245
+ textAlignVertical: 'center',
246
+ },
247
+ input: {
248
+ flex: 1,
249
+ width: 'auto',
250
+ height: '100%',
251
+ fontSize: FORM_FIELD.fontSize,
252
+ fontFamily: FontFamily.InterTightRegular,
253
+ paddingTop: 0,
254
+ paddingBottom: 0,
255
+ paddingVertical: 0,
256
+ paddingLeft: 0,
257
+ paddingRight: 0,
258
+ margin: 0,
259
+ includeFontPadding: false,
260
+ textAlignVertical: 'center',
261
+ },
262
+ flagContainer: {
263
+ flexDirection: 'row',
264
+ alignItems: 'center',
265
+ justifyContent: 'center',
266
+ borderTopLeftRadius: FORM_FIELD.radius,
267
+ borderBottomLeftRadius: FORM_FIELD.radius,
268
+ paddingHorizontal: 0,
269
+ paddingVertical: 0,
270
+ paddingLeft: 0,
271
+ paddingRight: 0,
272
+ margin: 0,
273
+ gap: 0,
274
+ minWidth: 0,
275
+ height: '100%',
276
+ },
277
+ flagContainerNoFlag: {
278
+ paddingHorizontal: 0,
279
+ paddingLeft: 0,
280
+ gap: 0,
281
+ minWidth: 0,
282
+ },
283
+ });
284
+
285
+ const styles = StyleSheet.create({
286
+ searchInput: {
287
+ paddingLeft: 10,
288
+ },
289
+ });
@@ -0,0 +1,280 @@
1
+ import { useAppTheme } from '@/context/ThemeContext';
2
+ import React, { memo, useCallback, useEffect, useState } from 'react';
3
+ import {
4
+ Modal,
5
+ Pressable,
6
+ StyleSheet,
7
+ Text,
8
+ View,
9
+ } from 'react-native';
10
+ import Icon from '../../Icon';
11
+ import DateTimePicker, {
12
+ DateTimePickerChangeEvent,
13
+ } from '@react-native-community/datetimepicker';
14
+ import { DateTimeVariantProps } from '../type';
15
+ import moment from 'moment';
16
+ import { useTranslation } from 'react-i18next';
17
+ import { isAndroid, isIOS } from '@/constants/device';
18
+ import { FontFamily } from '@/theme';
19
+ import { normalize } from '@/utils/normalize';
20
+ import { FORM_FIELD } from '../formFieldStyles';
21
+ import CustomText from '../../text/CustomText';
22
+
23
+ type IOSMode = 'date' | 'time' | 'datetime' | 'countdown';
24
+ type AndroidMode = 'date' | 'time';
25
+
26
+ type RHFDateTimeField = {
27
+ value?: Date;
28
+ onChange?: (date: Date) => void;
29
+ };
30
+
31
+ type DateTimeFormMode = {
32
+ mode: 'form';
33
+ field: RHFDateTimeField;
34
+ dateTimeMode?: IOSMode | AndroidMode;
35
+ };
36
+
37
+ type DateTimeIndependentMode = {
38
+ mode: 'standalone';
39
+ value?: Date;
40
+ onChange?: (date: Date) => void;
41
+ dateTimeMode?: IOSMode | AndroidMode;
42
+ };
43
+
44
+ type DateTimeVisualProps =
45
+ | (DateTimeFormMode & DateTimeVariantProps)
46
+ | (DateTimeIndependentMode & DateTimeVariantProps);
47
+
48
+ const DateTimeVariant = (props: DateTimeVisualProps) => {
49
+ const { t } = useTranslation();
50
+ const { color } = useAppTheme();
51
+ const [showPicker, setShowPicker] = useState(false);
52
+ const [draftDate, setDraftDate] = useState<Date>(new Date());
53
+
54
+ const {
55
+ mode,
56
+ disabled,
57
+ placeholder = 'Select date',
58
+ dateTimeMode = 'date',
59
+ inputStyle,
60
+ minimumDate,
61
+ maximumDate,
62
+ showIcon = true,
63
+ iconName = 'calendar',
64
+ placeholderTextColor,
65
+ dateTimePickerProps,
66
+ dateTimeContainerStyle,
67
+ } = props;
68
+
69
+ const value =
70
+ mode === 'form' ? props.field.value ?? null : props.value ?? null;
71
+
72
+ const onChange = mode === 'form' ? props.field.onChange : props.onChange;
73
+
74
+ useEffect(() => {
75
+ if (showPicker) {
76
+ setDraftDate(value ?? new Date());
77
+ }
78
+ }, [showPicker, value]);
79
+
80
+ const handleAndroidValueChange = useCallback(
81
+ (_event: DateTimePickerChangeEvent, selectedDate: Date) => {
82
+ onChange?.(selectedDate);
83
+ setShowPicker(false);
84
+ },
85
+ [onChange],
86
+ );
87
+
88
+ const handleIosValueChange = useCallback(
89
+ (_event: DateTimePickerChangeEvent, selectedDate: Date) => {
90
+ setDraftDate(selectedDate);
91
+ },
92
+ [],
93
+ );
94
+
95
+ const handleDismiss = useCallback(() => {
96
+ setShowPicker(false);
97
+ }, []);
98
+
99
+ const handleConfirmIos = useCallback(() => {
100
+ onChange?.(draftDate);
101
+ setShowPicker(false);
102
+ }, [draftDate, onChange]);
103
+
104
+ const handlePress = useCallback(() => {
105
+ if (disabled) {
106
+ return;
107
+ }
108
+ setShowPicker(true);
109
+ }, [disabled]);
110
+
111
+ const displayValue = value
112
+ ? moment(value).format(dateTimeMode === 'time' ? 'hh:mm A' : 'DD/MM/YYYY')
113
+ : '';
114
+
115
+ return (
116
+ <>
117
+ <Pressable
118
+ onPress={handlePress}
119
+ disabled={disabled}
120
+ accessibilityRole="button"
121
+ style={[
122
+ styles.wrapper,
123
+ {
124
+ backgroundColor: disabled
125
+ ? color.disabled
126
+ : color.background_primary,
127
+ borderColor: color.border,
128
+ },
129
+ dateTimeContainerStyle,
130
+ ]}
131
+ >
132
+ <Text
133
+ numberOfLines={1}
134
+ allowFontScaling={false}
135
+ style={[
136
+ styles.input,
137
+ {
138
+ color: displayValue
139
+ ? color.text_primary
140
+ : (placeholderTextColor ?? color.text_placeholder),
141
+ },
142
+ inputStyle,
143
+ ]}
144
+ >
145
+ {displayValue || placeholder}
146
+ </Text>
147
+
148
+ {showIcon ? (
149
+ <View style={styles.rightIconWrap} pointerEvents="none">
150
+ <Icon
151
+ name={iconName}
152
+ width={FORM_FIELD.iconSize}
153
+ height={FORM_FIELD.iconSize}
154
+ />
155
+ </View>
156
+ ) : null}
157
+ </Pressable>
158
+
159
+ {showPicker && isAndroid ? (
160
+ <DateTimePicker
161
+ value={value ?? new Date()}
162
+ mode={dateTimeMode}
163
+ minimumDate={minimumDate}
164
+ maximumDate={maximumDate}
165
+ {...dateTimePickerProps}
166
+ onValueChange={handleAndroidValueChange}
167
+ onDismiss={handleDismiss}
168
+ />
169
+ ) : null}
170
+
171
+ {isIOS ? (
172
+ <Modal
173
+ transparent
174
+ visible={showPicker}
175
+ animationType="fade"
176
+ onRequestClose={handleDismiss}
177
+ >
178
+ <View style={styles.iosOverlay}>
179
+ <Pressable style={StyleSheet.absoluteFill} onPress={handleDismiss} />
180
+ <View
181
+ style={[
182
+ styles.iosSheet,
183
+ { backgroundColor: color.background_primary },
184
+ ]}
185
+ >
186
+ <View style={styles.iosToolbar}>
187
+ <Pressable onPress={handleDismiss} hitSlop={12}>
188
+ <CustomText
189
+ variant="body"
190
+ weight="500"
191
+ textColor={color.text_secondary}
192
+ >
193
+ {t('common.cancel')}
194
+ </CustomText>
195
+ </Pressable>
196
+ <Pressable onPress={handleConfirmIos} hitSlop={12}>
197
+ <CustomText
198
+ variant="body"
199
+ weight="600"
200
+ textColor={color.primary}
201
+ >
202
+ {t('common.done')}
203
+ </CustomText>
204
+ </Pressable>
205
+ </View>
206
+
207
+ <DateTimePicker
208
+ value={draftDate}
209
+ mode={dateTimeMode}
210
+ display="spinner"
211
+ minimumDate={minimumDate}
212
+ maximumDate={maximumDate}
213
+ themeVariant="light"
214
+ {...dateTimePickerProps}
215
+ onValueChange={handleIosValueChange}
216
+ onDismiss={handleDismiss}
217
+ style={styles.iosPicker}
218
+ />
219
+ </View>
220
+ </View>
221
+ </Modal>
222
+ ) : null}
223
+ </>
224
+ );
225
+ };
226
+
227
+ export default memo(DateTimeVariant);
228
+
229
+ const styles = StyleSheet.create({
230
+ wrapper: {
231
+ flexDirection: 'row',
232
+ alignItems: 'center',
233
+ borderWidth: 1,
234
+ borderRadius: FORM_FIELD.radius,
235
+ height: FORM_FIELD.height,
236
+ minHeight: FORM_FIELD.height,
237
+ width: '100%',
238
+ paddingHorizontal: FORM_FIELD.paddingH,
239
+ },
240
+ input: {
241
+ flex: 1,
242
+ minWidth: 0,
243
+ fontFamily: FontFamily.InterTightRegular,
244
+ fontSize: FORM_FIELD.fontSize,
245
+ paddingTop: 0,
246
+ paddingBottom: 0,
247
+ margin: 0,
248
+ includeFontPadding: false,
249
+ textAlignVertical: 'center',
250
+ },
251
+ rightIconWrap: {
252
+ marginLeft: normalize(8),
253
+ width: FORM_FIELD.iconSize,
254
+ height: FORM_FIELD.iconSize,
255
+ justifyContent: 'center',
256
+ alignItems: 'center',
257
+ },
258
+ iosOverlay: {
259
+ flex: 1,
260
+ justifyContent: 'flex-end',
261
+ backgroundColor: 'rgba(0, 0, 0, 0.45)',
262
+ },
263
+ iosSheet: {
264
+ borderTopLeftRadius: normalize(16),
265
+ borderTopRightRadius: normalize(16),
266
+ paddingBottom: normalize(24),
267
+ overflow: 'hidden',
268
+ },
269
+ iosToolbar: {
270
+ flexDirection: 'row',
271
+ justifyContent: 'space-between',
272
+ alignItems: 'center',
273
+ paddingHorizontal: normalize(16),
274
+ paddingVertical: normalize(14),
275
+ },
276
+ iosPicker: {
277
+ alignSelf: 'center',
278
+ width: '100%',
279
+ },
280
+ });