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.
- package/LICENSE +21 -0
- package/README.md +378 -2
- package/bin/create-react-native-starter-kit.js +95 -0
- package/lib/copy-src.js +127 -0
- package/lib/creator.js +211 -0
- package/lib/deps.js +58 -0
- package/lib/patch-configs.js +318 -0
- package/lib/patch-native.js +588 -0
- package/package.json +47 -4
- package/scripts/sync-template.js +52 -0
- package/template/.env.example +3 -0
- package/template/patches/react-native-element-dropdown+2.12.4.patch +67 -0
- package/template/src/app/App.tsx +25 -0
- package/template/src/app/navigation/root.tsx +24 -0
- package/template/src/app/navigation/stacks/app.stack.tsx +67 -0
- package/template/src/app/navigation/stacks/app.tab.tsx +72 -0
- package/template/src/app/navigation/stacks/auth.stack.tsx +56 -0
- package/template/src/app/providers.tsx +43 -0
- package/template/src/assets/fonts/InterTight-Black.ttf +0 -0
- package/template/src/assets/fonts/InterTight-BlackItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Bold.ttf +0 -0
- package/template/src/assets/fonts/InterTight-BoldItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-ExtraBold.ttf +0 -0
- package/template/src/assets/fonts/InterTight-ExtraBoldItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-ExtraLight.ttf +0 -0
- package/template/src/assets/fonts/InterTight-ExtraLightItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Italic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Light.ttf +0 -0
- package/template/src/assets/fonts/InterTight-LightItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Medium.ttf +0 -0
- package/template/src/assets/fonts/InterTight-MediumItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Regular.ttf +0 -0
- package/template/src/assets/fonts/InterTight-SemiBold.ttf +0 -0
- package/template/src/assets/fonts/InterTight-SemiBoldItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Thin.ttf +0 -0
- package/template/src/assets/fonts/InterTight-ThinItalic.ttf +0 -0
- package/template/src/assets/icons/back.svg +3 -0
- package/template/src/assets/icons/calendar.svg +3 -0
- package/template/src/assets/icons/claim_upload.svg +3 -0
- package/template/src/assets/icons/clock.svg +1 -0
- package/template/src/assets/icons/downArrow.svg +3 -0
- package/template/src/assets/icons/edit.svg +3 -0
- package/template/src/assets/icons/eye.svg +4 -0
- package/template/src/assets/icons/eyeClose.svg +7 -0
- package/template/src/assets/icons/folder.svg +5 -0
- package/template/src/assets/icons/home.svg +4 -0
- package/template/src/assets/icons/index.ts +35 -0
- package/template/src/assets/icons/log_out.svg +4 -0
- package/template/src/assets/icons/setting.svg +4 -0
- package/template/src/assets/icons/tabs/home/filled_dark.svg +3 -0
- package/template/src/assets/icons/tabs/home/filled_light.svg +3 -0
- package/template/src/assets/icons/tabs/home/outline.svg +4 -0
- package/template/src/assets/icons/tabs/index.ts +31 -0
- package/template/src/assets/icons/tabs/profile/filled_dark.svg +6 -0
- package/template/src/assets/icons/tabs/profile/filled_light.svg +6 -0
- package/template/src/assets/icons/tabs/profile/outline.svg +3 -0
- package/template/src/assets/icons/tooltip_dark.svg +1 -0
- package/template/src/assets/icons/tooltip_light.svg +1 -0
- package/template/src/assets/icons/upArrow.svg +3 -0
- package/template/src/assets/images/back.png +0 -0
- package/template/src/assets/images/index.ts +7 -0
- package/template/src/assets/images/placeholder/profile.png +0 -0
- package/template/src/components/shared/AppImage.tsx +190 -0
- package/template/src/components/shared/AvatarPicker.tsx +175 -0
- package/template/src/components/shared/CustomButton.tsx +273 -0
- package/template/src/components/shared/DocumentPicker.tsx +86 -0
- package/template/src/components/shared/GlobalLoader.tsx +47 -0
- package/template/src/components/shared/Icon.tsx +28 -0
- package/template/src/components/shared/PressableIcon.tsx +104 -0
- package/template/src/components/shared/bottom-sheet/BaseBottomSheet.tsx +30 -0
- package/template/src/components/shared/bottom-sheet/BaseBottomSheetModal.tsx +50 -0
- package/template/src/components/shared/bottom-sheet/sheets/ImagePickerSheet.tsx +310 -0
- package/template/src/components/shared/bottom-sheet/types.ts +4 -0
- package/template/src/components/shared/form-input/FormInput.tsx +140 -0
- package/template/src/components/shared/form-input/FormInputRenderer.tsx +82 -0
- package/template/src/components/shared/form-input/FullNameInput.tsx +243 -0
- package/template/src/components/shared/form-input/formFieldStyles.ts +43 -0
- package/template/src/components/shared/form-input/type.ts +188 -0
- package/template/src/components/shared/form-input/variants/CountryPhoneVariant.tsx +289 -0
- package/template/src/components/shared/form-input/variants/DateTimeVariant.tsx +280 -0
- package/template/src/components/shared/form-input/variants/DropdownVariant.tsx +221 -0
- package/template/src/components/shared/form-input/variants/TextInputVariant.tsx +300 -0
- package/template/src/components/shared/form-input/variants/ToggleVariant.tsx +194 -0
- package/template/src/components/shared/modal/BaseModal.tsx +83 -0
- package/template/src/components/shared/modal/common/AlertModal.tsx +173 -0
- package/template/src/components/shared/navigation/AnimatedTabIcon.tsx +37 -0
- package/template/src/components/shared/navigation/HeaderActionButton.tsx +70 -0
- package/template/src/components/shared/navigation/HeaderBackButton.tsx +38 -0
- package/template/src/components/shared/navigation/StackHeader.tsx +105 -0
- package/template/src/components/shared/navigation/tabIconRender.tsx +14 -0
- package/template/src/components/shared/offline/OfflineQueryBoundary.tsx +25 -0
- package/template/src/components/shared/offline/OfflineState.tsx +229 -0
- package/template/src/components/shared/offline/index.ts +6 -0
- package/template/src/components/shared/offline/types.ts +15 -0
- package/template/src/components/shared/offline/wifi-icon-animation/BrokenWifiAnimation.tsx +116 -0
- package/template/src/components/shared/offline/wifi-icon-animation/WifiPiece.tsx +80 -0
- package/template/src/components/shared/offline/wifi-icon-animation/geometry.ts +163 -0
- package/template/src/components/shared/offline/wifi-icon-animation/useWifiIconAnimationActive.ts +37 -0
- package/template/src/components/shared/skelton/BaseSkelton.tsx +71 -0
- package/template/src/components/shared/skelton/ShimmerHolder.ts +6 -0
- package/template/src/components/shared/skelton/holders/HomeShimmer.tsx +25 -0
- package/template/src/components/shared/skelton/holders/index.ts +1 -0
- package/template/src/components/shared/skelton/layouts/avatar.layout.ts +18 -0
- package/template/src/components/shared/skelton/layouts/home.layout.ts +16 -0
- package/template/src/components/shared/skelton/layouts/index.ts +3 -0
- package/template/src/components/shared/skelton/layouts/text.layout.ts +18 -0
- package/template/src/components/shared/text/CustomText.tsx +85 -0
- package/template/src/components/shared/text/ShimmerText.tsx +159 -0
- package/template/src/components/shared/text/types.ts +40 -0
- package/template/src/constants/device.ts +12 -0
- package/template/src/constants/endpoint.ts +11 -0
- package/template/src/constants/keyExtractor.ts +6 -0
- package/template/src/constants/limits.ts +9 -0
- package/template/src/constants/queryKey.ts +3 -0
- package/template/src/constants/regex.ts +7 -0
- package/template/src/context/NetworkContext.tsx +102 -0
- package/template/src/context/ThemeContext.tsx +56 -0
- package/template/src/hooks/app/index.ts +2 -0
- package/template/src/hooks/app/useGetProfile.ts +38 -0
- package/template/src/hooks/app/useUpdateProfile.ts +21 -0
- package/template/src/hooks/useAppDispatch.ts +6 -0
- package/template/src/hooks/useAppSelector.ts +4 -0
- package/template/src/hooks/useDebounce.ts +15 -0
- package/template/src/hooks/useDocumentPicker.ts +102 -0
- package/template/src/hooks/useImagePicker.ts +83 -0
- package/template/src/i18n/i18next.d.ts +9 -0
- package/template/src/i18n/index.ts +16 -0
- package/template/src/i18n/locales/en.json +274 -0
- package/template/src/i18n/locales/ru.json +165 -0
- package/template/src/i18n/resources.ts +11 -0
- package/template/src/redux/selectors/auth.selectors.ts +4 -0
- package/template/src/redux/slice/auth.slice.ts +23 -0
- package/template/src/redux/slice/loader.slice.ts +25 -0
- package/template/src/redux/slice/settings.slice.ts +26 -0
- package/template/src/redux/slice/user.slice.ts +25 -0
- package/template/src/screens/app/main-tab/index.tsx +73 -0
- package/template/src/screens/app/main-tab/style.ts +0 -0
- package/template/src/screens/app/profile-setup/index.tsx +162 -0
- package/template/src/screens/app/profile-setup/styles.ts +3 -0
- package/template/src/screens/auth/forgot-password/index.tsx +59 -0
- package/template/src/screens/auth/forgot-password/styles.ts +0 -0
- package/template/src/screens/auth/index.ts +4 -0
- package/template/src/screens/auth/login/index.tsx +138 -0
- package/template/src/screens/auth/login/styles.ts +3 -0
- package/template/src/screens/auth/signup/index.tsx +111 -0
- package/template/src/screens/auth/signup/styles.ts +3 -0
- package/template/src/screens/auth/verify-email/index.tsx +15 -0
- package/template/src/screens/auth/verify-email/styles.ts +3 -0
- package/template/src/screens/tab/home/index.tsx +49 -0
- package/template/src/screens/tab/home/styles.ts +3 -0
- package/template/src/screens/tab/index.ts +2 -0
- package/template/src/screens/tab/profile/index.tsx +50 -0
- package/template/src/screens/tab/profile/styles.ts +3 -0
- package/template/src/services/api/auth/auth.api.ts +22 -0
- package/template/src/services/api/auth/auth.endpoints.ts +7 -0
- package/template/src/services/api/auth/auth.types.ts +9 -0
- package/template/src/services/api/auth/index.ts +3 -0
- package/template/src/services/api/axios/axios.instance.ts +15 -0
- package/template/src/services/api/axios/axios.interceptors.ts +43 -0
- package/template/src/services/api/axios/index.ts +2 -0
- package/template/src/services/api/mock/mockAdapter.ts +97 -0
- package/template/src/services/api/user/index.ts +2 -0
- package/template/src/services/api/user/user.api.ts +67 -0
- package/template/src/services/api/user/user.endpoints.ts +0 -0
- package/template/src/services/api/user/user.types.ts +0 -0
- package/template/src/services/errors/backendErrorCodes.ts +7 -0
- package/template/src/services/errors/errorHandler.ts +94 -0
- package/template/src/services/errors/firebaseErrorMap.ts +61 -0
- package/template/src/services/errors/httpStatusMap.ts +47 -0
- package/template/src/services/errors/index.ts +4 -0
- package/template/src/services/network/index.ts +1 -0
- package/template/src/services/network/onlineManager.ts +22 -0
- package/template/src/services/query/index.ts +1 -0
- package/template/src/services/query/queryClient.ts +23 -0
- package/template/src/services/toast/ToastCard.tsx +137 -0
- package/template/src/services/toast/ToastConfig.tsx +32 -0
- package/template/src/services/toast/index.ts +3 -0
- package/template/src/services/toast/toast.ts +68 -0
- package/template/src/storage/mmkvAdapter.ts +3 -0
- package/template/src/storage/mmkvInstance.ts +16 -0
- package/template/src/store/index.ts +15 -0
- package/template/src/store/mmkv.ts +6 -0
- package/template/src/store/persist.ts +10 -0
- package/template/src/store/rootReducer.ts +26 -0
- package/template/src/theme/dark.ts +40 -0
- package/template/src/theme/fonts.ts +20 -0
- package/template/src/theme/index.ts +6 -0
- package/template/src/theme/layout.ts +23 -0
- package/template/src/theme/light.ts +41 -0
- package/template/src/theme/palette.ts +32 -0
- package/template/src/theme/spacing.ts +7 -0
- package/template/src/theme/typography.ts +80 -0
- package/template/src/types/api.types.ts +34 -0
- package/template/src/types/env.d.ts +6 -0
- package/template/src/types/index.ts +2 -0
- package/template/src/types/navigation.types.ts +94 -0
- package/template/src/utils/clearAppSession.ts +10 -0
- package/template/src/utils/date.ts +19 -0
- package/template/src/utils/documentPickerHandler.ts +96 -0
- package/template/src/utils/getFileNameFromUri.ts +18 -0
- package/template/src/utils/getInitials.ts +13 -0
- package/template/src/utils/hindiText.ts +33 -0
- package/template/src/utils/imageCompress.ts +97 -0
- package/template/src/utils/imagePickerHandler.ts +200 -0
- package/template/src/utils/maskPhone.ts +17 -0
- package/template/src/utils/normalize.ts +12 -0
- package/template/src/validation/messages.ts +11 -0
- package/template/src/validation/rules.ts +44 -0
- package/template/src/validation/schema/auth.schema.ts +53 -0
- package/template/src/validation/schema/user.schema.ts +46 -0
- 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
|
+
});
|