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
|
Binary file
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import React, { memo, useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import FastImage, {
|
|
3
|
+
FastImageProps,
|
|
4
|
+
OnErrorEvent,
|
|
5
|
+
type ImageStyle as FastImageStyle,
|
|
6
|
+
} from '@d11/react-native-fast-image';
|
|
7
|
+
import {
|
|
8
|
+
ActivityIndicator,
|
|
9
|
+
View,
|
|
10
|
+
StyleSheet,
|
|
11
|
+
type StyleProp,
|
|
12
|
+
type ViewStyle,
|
|
13
|
+
} from 'react-native';
|
|
14
|
+
import type { IconName } from '@/assets/icons';
|
|
15
|
+
import { GlobalImage } from '@/assets/images';
|
|
16
|
+
import CustomText from '@/components/shared/text/CustomText';
|
|
17
|
+
import Icon from '@/components/shared/Icon';
|
|
18
|
+
import { useAppTheme } from '@/context/ThemeContext';
|
|
19
|
+
import { getInitials } from '@/utils/getInitials';
|
|
20
|
+
|
|
21
|
+
interface AppImageProps extends Omit<FastImageProps, 'style' | 'source'> {
|
|
22
|
+
showLoader?: boolean;
|
|
23
|
+
/** Applied to the outer View wrapper, not FastImage itself. */
|
|
24
|
+
style?: StyleProp<ViewStyle>;
|
|
25
|
+
source?: FastImageProps['source'];
|
|
26
|
+
/** When present and loads successfully → show image. */
|
|
27
|
+
imageUrl?: string | null;
|
|
28
|
+
/** When provided (and no image / image error, and no icon) → initials. */
|
|
29
|
+
name?: string | null;
|
|
30
|
+
/** When provided (and no image / image error) → icon. */
|
|
31
|
+
icon?: IconName;
|
|
32
|
+
iconSize?: number;
|
|
33
|
+
iconStyle?: StyleProp<ViewStyle>;
|
|
34
|
+
/** Last fallback when no image, icon, or name. */
|
|
35
|
+
placeholder?: FastImageProps['source'];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const FILL = StyleSheet.absoluteFill as FastImageStyle;
|
|
39
|
+
|
|
40
|
+
const hasImageUrl = (url?: string | null) => !!url?.trim();
|
|
41
|
+
|
|
42
|
+
const AppImage = memo(
|
|
43
|
+
({
|
|
44
|
+
resizeMode = FastImage.resizeMode.contain,
|
|
45
|
+
showLoader = false,
|
|
46
|
+
style,
|
|
47
|
+
onLoadStart,
|
|
48
|
+
onLoadEnd,
|
|
49
|
+
onError,
|
|
50
|
+
source,
|
|
51
|
+
imageUrl,
|
|
52
|
+
name,
|
|
53
|
+
icon,
|
|
54
|
+
iconSize = 24,
|
|
55
|
+
iconStyle,
|
|
56
|
+
placeholder = GlobalImage.profilePlaceholder,
|
|
57
|
+
...rest
|
|
58
|
+
}: AppImageProps) => {
|
|
59
|
+
const { color } = useAppTheme();
|
|
60
|
+
const [loading, setLoading] = useState(false);
|
|
61
|
+
const [failedSource, setFailedSource] =
|
|
62
|
+
useState<FastImageProps['source']>(undefined);
|
|
63
|
+
|
|
64
|
+
const initials = useMemo(() => getInitials(name), [name]);
|
|
65
|
+
|
|
66
|
+
const resolvedSource = useMemo(() => {
|
|
67
|
+
if (hasImageUrl(imageUrl)) {
|
|
68
|
+
return { uri: imageUrl!.trim() };
|
|
69
|
+
}
|
|
70
|
+
return source;
|
|
71
|
+
}, [imageUrl, source]);
|
|
72
|
+
|
|
73
|
+
const hasError =
|
|
74
|
+
failedSource !== undefined &&
|
|
75
|
+
JSON.stringify(failedSource) === JSON.stringify(resolvedSource);
|
|
76
|
+
|
|
77
|
+
const canShowImage = !!resolvedSource && !hasError;
|
|
78
|
+
|
|
79
|
+
const handleLoadStart = useCallback(() => {
|
|
80
|
+
setLoading(true);
|
|
81
|
+
onLoadStart?.();
|
|
82
|
+
}, [onLoadStart]);
|
|
83
|
+
|
|
84
|
+
const handleLoadEnd = useCallback(() => {
|
|
85
|
+
setLoading(false);
|
|
86
|
+
onLoadEnd?.();
|
|
87
|
+
}, [onLoadEnd]);
|
|
88
|
+
|
|
89
|
+
const handleError = useCallback(
|
|
90
|
+
(event: OnErrorEvent) => {
|
|
91
|
+
setLoading(false);
|
|
92
|
+
setFailedSource(resolvedSource);
|
|
93
|
+
onError?.(event);
|
|
94
|
+
},
|
|
95
|
+
[onError, resolvedSource],
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (canShowImage) {
|
|
99
|
+
return (
|
|
100
|
+
<View style={[styles.container, style]}>
|
|
101
|
+
{showLoader && loading && (
|
|
102
|
+
<View style={styles.loader}>
|
|
103
|
+
<ActivityIndicator />
|
|
104
|
+
</View>
|
|
105
|
+
)}
|
|
106
|
+
|
|
107
|
+
<FastImage
|
|
108
|
+
{...rest}
|
|
109
|
+
style={FILL}
|
|
110
|
+
resizeMode={resizeMode}
|
|
111
|
+
source={resolvedSource}
|
|
112
|
+
onLoadStart={handleLoadStart}
|
|
113
|
+
onLoadEnd={handleLoadEnd}
|
|
114
|
+
onError={handleError}
|
|
115
|
+
/>
|
|
116
|
+
</View>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (icon) {
|
|
121
|
+
return (
|
|
122
|
+
<View style={[styles.container, styles.iconContainer, style]}>
|
|
123
|
+
<Icon
|
|
124
|
+
name={icon}
|
|
125
|
+
width={iconSize}
|
|
126
|
+
height={iconSize}
|
|
127
|
+
style={iconStyle}
|
|
128
|
+
/>
|
|
129
|
+
</View>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (initials) {
|
|
134
|
+
return (
|
|
135
|
+
<View
|
|
136
|
+
style={[
|
|
137
|
+
styles.container,
|
|
138
|
+
styles.initialsContainer,
|
|
139
|
+
{ backgroundColor: color.primary },
|
|
140
|
+
style,
|
|
141
|
+
]}
|
|
142
|
+
>
|
|
143
|
+
<CustomText
|
|
144
|
+
variant="title"
|
|
145
|
+
weight="700"
|
|
146
|
+
textColor={color.text_default}
|
|
147
|
+
style={styles.initialsText}
|
|
148
|
+
>
|
|
149
|
+
{initials}
|
|
150
|
+
</CustomText>
|
|
151
|
+
</View>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<View style={[styles.container, style]}>
|
|
157
|
+
<FastImage
|
|
158
|
+
{...rest}
|
|
159
|
+
style={FILL}
|
|
160
|
+
resizeMode={resizeMode}
|
|
161
|
+
source={placeholder}
|
|
162
|
+
/>
|
|
163
|
+
</View>
|
|
164
|
+
);
|
|
165
|
+
},
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
export default AppImage;
|
|
169
|
+
|
|
170
|
+
const styles = StyleSheet.create({
|
|
171
|
+
container: {
|
|
172
|
+
overflow: 'hidden',
|
|
173
|
+
},
|
|
174
|
+
initialsContainer: {
|
|
175
|
+
alignItems: 'center',
|
|
176
|
+
justifyContent: 'center',
|
|
177
|
+
},
|
|
178
|
+
iconContainer: {
|
|
179
|
+
alignItems: 'center',
|
|
180
|
+
justifyContent: 'center',
|
|
181
|
+
},
|
|
182
|
+
initialsText: {
|
|
183
|
+
marginBottom: 0,
|
|
184
|
+
},
|
|
185
|
+
loader: {
|
|
186
|
+
...StyleSheet.absoluteFill,
|
|
187
|
+
justifyContent: 'center',
|
|
188
|
+
alignItems: 'center',
|
|
189
|
+
},
|
|
190
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect, useRef, memo } from 'react';
|
|
2
|
+
import { Pressable, StyleSheet, View, ViewStyle } from 'react-native';
|
|
3
|
+
import AppImage from './AppImage';
|
|
4
|
+
import { GlobalImage } from '@/assets/images';
|
|
5
|
+
import Icon from './Icon';
|
|
6
|
+
import { useAppTheme } from '@/context/ThemeContext';
|
|
7
|
+
import { isIOS } from '@/constants/device';
|
|
8
|
+
import { useImagePicker } from '@/hooks/useImagePicker';
|
|
9
|
+
import ImagePickerSheet from './bottom-sheet/sheets/ImagePickerSheet';
|
|
10
|
+
import { BSRef } from './bottom-sheet/types';
|
|
11
|
+
import BaseSkelton from './skelton/BaseSkelton';
|
|
12
|
+
import { avatarPickerLayout } from './skelton/layouts';
|
|
13
|
+
|
|
14
|
+
type SourceType = 'gallery' | 'camera' | 'both';
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
imageUrl?: string;
|
|
18
|
+
defaultImage?: any;
|
|
19
|
+
width?: number;
|
|
20
|
+
height?: number;
|
|
21
|
+
alignSelf?: ViewStyle['alignSelf'];
|
|
22
|
+
containerStyle?: ViewStyle;
|
|
23
|
+
editable?: boolean;
|
|
24
|
+
editIconSize?: number;
|
|
25
|
+
isLoading?: boolean;
|
|
26
|
+
|
|
27
|
+
source?: SourceType;
|
|
28
|
+
maxSize?: number;
|
|
29
|
+
quality?: number;
|
|
30
|
+
onImageChange?: (image: string) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const AvatarPicker = ({
|
|
34
|
+
imageUrl,
|
|
35
|
+
defaultImage = GlobalImage.profilePlaceholder,
|
|
36
|
+
width = 100,
|
|
37
|
+
height = 100,
|
|
38
|
+
alignSelf = 'center',
|
|
39
|
+
containerStyle,
|
|
40
|
+
editable = false,
|
|
41
|
+
editIconSize = 28,
|
|
42
|
+
isLoading,
|
|
43
|
+
source = 'both',
|
|
44
|
+
maxSize = 256,
|
|
45
|
+
quality = 80,
|
|
46
|
+
onImageChange,
|
|
47
|
+
}: Props) => {
|
|
48
|
+
const { color } = useAppTheme();
|
|
49
|
+
const { captureFromCamera, images, pickFromGallery } = useImagePicker({
|
|
50
|
+
maxSize,
|
|
51
|
+
quality,
|
|
52
|
+
});
|
|
53
|
+
const [localImageUri, setLocalImageUri] = useState<string | undefined>(
|
|
54
|
+
imageUrl,
|
|
55
|
+
);
|
|
56
|
+
const imageSource = localImageUri ? { uri: localImageUri } : defaultImage;
|
|
57
|
+
const sheetRef = useRef<BSRef>(null);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (images?.length > 0) {
|
|
61
|
+
const image = images[0];
|
|
62
|
+
|
|
63
|
+
setLocalImageUri(image.uri);
|
|
64
|
+
onImageChange?.(image.uri);
|
|
65
|
+
}
|
|
66
|
+
}, [images, onImageChange]);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
setLocalImageUri(imageUrl);
|
|
70
|
+
}, [imageUrl]);
|
|
71
|
+
|
|
72
|
+
const dynamicContainerStyle: ViewStyle = {
|
|
73
|
+
width,
|
|
74
|
+
height,
|
|
75
|
+
borderRadius: width / 2,
|
|
76
|
+
alignSelf,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Main press handler
|
|
80
|
+
const handleEditPress = useCallback(() => {
|
|
81
|
+
if (source === 'both') {
|
|
82
|
+
sheetRef.current?.open();
|
|
83
|
+
} else if (source === 'camera') {
|
|
84
|
+
captureFromCamera();
|
|
85
|
+
} else {
|
|
86
|
+
pickFromGallery();
|
|
87
|
+
}
|
|
88
|
+
}, [source, captureFromCamera, pickFromGallery]);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
<BaseSkelton
|
|
93
|
+
isLoading={isLoading}
|
|
94
|
+
layout={avatarPickerLayout({
|
|
95
|
+
size: width,
|
|
96
|
+
})}
|
|
97
|
+
containerStyle={[
|
|
98
|
+
styles.container,
|
|
99
|
+
dynamicContainerStyle,
|
|
100
|
+
containerStyle,
|
|
101
|
+
]}
|
|
102
|
+
>
|
|
103
|
+
<View
|
|
104
|
+
style={[
|
|
105
|
+
styles.imageContainer,
|
|
106
|
+
{ borderRadius: width / 2, borderColor: color.border },
|
|
107
|
+
]}
|
|
108
|
+
>
|
|
109
|
+
<AppImage
|
|
110
|
+
source={imageSource}
|
|
111
|
+
style={styles.image}
|
|
112
|
+
resizeMode="cover"
|
|
113
|
+
/>
|
|
114
|
+
</View>
|
|
115
|
+
|
|
116
|
+
{editable && (
|
|
117
|
+
<Pressable
|
|
118
|
+
onPress={handleEditPress}
|
|
119
|
+
style={({ pressed }) => [
|
|
120
|
+
styles.editIconContainer,
|
|
121
|
+
pressed && isIOS && { opacity: 0.7 },
|
|
122
|
+
{
|
|
123
|
+
width: editIconSize,
|
|
124
|
+
height: editIconSize,
|
|
125
|
+
borderRadius: editIconSize / 2,
|
|
126
|
+
backgroundColor: color.primary,
|
|
127
|
+
borderColor: color.background_secondary,
|
|
128
|
+
},
|
|
129
|
+
]}
|
|
130
|
+
android_ripple={{
|
|
131
|
+
color: 'rgba(255,255,255,0.2)',
|
|
132
|
+
borderless: true,
|
|
133
|
+
foreground: true,
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<Icon name="edit" size={14} />
|
|
137
|
+
</Pressable>
|
|
138
|
+
)}
|
|
139
|
+
</BaseSkelton>
|
|
140
|
+
<ImagePickerSheet
|
|
141
|
+
ref={sheetRef}
|
|
142
|
+
onCamera={captureFromCamera}
|
|
143
|
+
onGallery={pickFromGallery}
|
|
144
|
+
/>
|
|
145
|
+
</>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export default memo(AvatarPicker);
|
|
150
|
+
|
|
151
|
+
const styles = StyleSheet.create({
|
|
152
|
+
container: {
|
|
153
|
+
marginTop: 16,
|
|
154
|
+
},
|
|
155
|
+
imageContainer: {
|
|
156
|
+
overflow: 'hidden',
|
|
157
|
+
width: '100%',
|
|
158
|
+
height: '100%',
|
|
159
|
+
borderWidth: 0.5,
|
|
160
|
+
},
|
|
161
|
+
image: {
|
|
162
|
+
width: '100%',
|
|
163
|
+
height: '100%',
|
|
164
|
+
},
|
|
165
|
+
editIconContainer: {
|
|
166
|
+
position: 'absolute',
|
|
167
|
+
bottom: 2,
|
|
168
|
+
right: 2,
|
|
169
|
+
justifyContent: 'center',
|
|
170
|
+
alignItems: 'center',
|
|
171
|
+
elevation: 3,
|
|
172
|
+
borderWidth: 2,
|
|
173
|
+
overflow: 'hidden',
|
|
174
|
+
},
|
|
175
|
+
});
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { useNetwork } from '@/context/NetworkContext';
|
|
2
|
+
import { useAppTheme } from '@/context/ThemeContext';
|
|
3
|
+
import { ErrorToast } from '@/services/toast';
|
|
4
|
+
import Haptics from '@mhpdev/react-native-haptics';
|
|
5
|
+
import React, { memo, useRef, useCallback, ReactNode, useMemo } from 'react';
|
|
6
|
+
import {
|
|
7
|
+
Pressable,
|
|
8
|
+
View,
|
|
9
|
+
ActivityIndicator,
|
|
10
|
+
StyleSheet,
|
|
11
|
+
TextStyle,
|
|
12
|
+
ViewStyle,
|
|
13
|
+
StyleProp,
|
|
14
|
+
} from 'react-native';
|
|
15
|
+
import { useTranslation } from 'react-i18next';
|
|
16
|
+
import CustomText from './text/CustomText';
|
|
17
|
+
import { normalize } from '@/utils/normalize';
|
|
18
|
+
import { isHindiLanguage } from '@/utils/hindiText';
|
|
19
|
+
import { isIOS } from '@/constants/device';
|
|
20
|
+
import Icon from './Icon';
|
|
21
|
+
import { IconName } from '@/assets/icons';
|
|
22
|
+
import type { FontWeight, TextVariant } from '@/theme/typography';
|
|
23
|
+
|
|
24
|
+
/* ───────────────── Types ───────────────── */
|
|
25
|
+
|
|
26
|
+
type Variant = 'primary' | 'outline' | 'danger' | 'ghost';
|
|
27
|
+
type Align = 'left' | 'center' | 'right';
|
|
28
|
+
type HapticType = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';
|
|
29
|
+
|
|
30
|
+
export interface AppButtonProps {
|
|
31
|
+
title?: string;
|
|
32
|
+
onPress?: () => Promise<void> | void;
|
|
33
|
+
onLongPress?: () => void;
|
|
34
|
+
|
|
35
|
+
variant?: Variant;
|
|
36
|
+
overrideVariantColor?: string;
|
|
37
|
+
overrideVariantTextColor?: string;
|
|
38
|
+
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
loading?: boolean;
|
|
41
|
+
/** Blocks the press while offline and shows a toast (use for API actions). */
|
|
42
|
+
requiresNetwork?: boolean;
|
|
43
|
+
|
|
44
|
+
align?: Align;
|
|
45
|
+
fullWidth?: boolean;
|
|
46
|
+
|
|
47
|
+
leftIcon?: IconName;
|
|
48
|
+
rightIcon?: IconName;
|
|
49
|
+
iconSize?: number;
|
|
50
|
+
|
|
51
|
+
haptic?: HapticType;
|
|
52
|
+
|
|
53
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
54
|
+
textStyle?: StyleProp<TextStyle>;
|
|
55
|
+
textVariant?: TextVariant;
|
|
56
|
+
textWeight?: FontWeight;
|
|
57
|
+
|
|
58
|
+
backgroundColor?: string;
|
|
59
|
+
borderRadius?: number;
|
|
60
|
+
|
|
61
|
+
children?: ReactNode;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const CustomButton = ({
|
|
65
|
+
title,
|
|
66
|
+
onPress,
|
|
67
|
+
onLongPress,
|
|
68
|
+
|
|
69
|
+
variant = 'primary',
|
|
70
|
+
overrideVariantColor,
|
|
71
|
+
overrideVariantTextColor,
|
|
72
|
+
|
|
73
|
+
disabled = false,
|
|
74
|
+
loading = false,
|
|
75
|
+
requiresNetwork = false,
|
|
76
|
+
|
|
77
|
+
align = 'center',
|
|
78
|
+
fullWidth = false,
|
|
79
|
+
|
|
80
|
+
leftIcon,
|
|
81
|
+
rightIcon,
|
|
82
|
+
iconSize = 18,
|
|
83
|
+
|
|
84
|
+
haptic = 'light',
|
|
85
|
+
|
|
86
|
+
backgroundColor,
|
|
87
|
+
borderRadius = 16,
|
|
88
|
+
|
|
89
|
+
containerStyle,
|
|
90
|
+
textStyle,
|
|
91
|
+
textVariant = 'button',
|
|
92
|
+
textWeight = '600',
|
|
93
|
+
children,
|
|
94
|
+
}: AppButtonProps) => {
|
|
95
|
+
const pressLock = useRef(false);
|
|
96
|
+
const { color } = useAppTheme();
|
|
97
|
+
const { t, i18n } = useTranslation();
|
|
98
|
+
const isHindi = isHindiLanguage(i18n.language);
|
|
99
|
+
const { isOffline } = useNetwork();
|
|
100
|
+
const isNetworkBlocked = requiresNetwork && isOffline;
|
|
101
|
+
|
|
102
|
+
const handlePress = useCallback(async () => {
|
|
103
|
+
if (pressLock.current || disabled || loading) return;
|
|
104
|
+
|
|
105
|
+
if (isNetworkBlocked) {
|
|
106
|
+
ErrorToast({
|
|
107
|
+
title: t('network.unavailableTitle'),
|
|
108
|
+
message: t('network.unavailableMessage'),
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
pressLock.current = true;
|
|
114
|
+
try {
|
|
115
|
+
Haptics.impact(haptic);
|
|
116
|
+
await onPress?.();
|
|
117
|
+
} finally {
|
|
118
|
+
pressLock.current = false;
|
|
119
|
+
}
|
|
120
|
+
}, [isNetworkBlocked, disabled, loading, onPress, haptic, t]);
|
|
121
|
+
|
|
122
|
+
const alignSelf: ViewStyle['alignSelf'] =
|
|
123
|
+
align === 'left' ? 'flex-start' : align === 'right' ? 'flex-end' : 'center';
|
|
124
|
+
|
|
125
|
+
const isIconOnly = !title && !children && !!(leftIcon || rightIcon);
|
|
126
|
+
|
|
127
|
+
const variantButtonStyle = useMemo(
|
|
128
|
+
() => ({
|
|
129
|
+
primary: { backgroundColor: overrideVariantColor || color.primary },
|
|
130
|
+
danger: { backgroundColor: overrideVariantColor || color.danger },
|
|
131
|
+
outline: {
|
|
132
|
+
backgroundColor: 'transparent',
|
|
133
|
+
borderWidth: 1,
|
|
134
|
+
borderColor: overrideVariantColor || color.primary,
|
|
135
|
+
},
|
|
136
|
+
ghost: {
|
|
137
|
+
backgroundColor: overrideVariantColor || 'transparent',
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
[color, overrideVariantColor],
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const variantTextStyle = useMemo(
|
|
144
|
+
() => ({
|
|
145
|
+
primary: { color: overrideVariantTextColor || color.text_default },
|
|
146
|
+
danger: { color: overrideVariantTextColor || color.text_default },
|
|
147
|
+
outline: { color: overrideVariantTextColor || color.primary },
|
|
148
|
+
ghost: { color: color.primary },
|
|
149
|
+
}),
|
|
150
|
+
[color, overrideVariantTextColor],
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<Pressable
|
|
155
|
+
onPress={handlePress}
|
|
156
|
+
onLongPress={onLongPress}
|
|
157
|
+
disabled={disabled || loading}
|
|
158
|
+
accessibilityRole="button"
|
|
159
|
+
accessibilityState={{ disabled: disabled || loading, busy: loading }}
|
|
160
|
+
style={({ pressed }) => [
|
|
161
|
+
buttonStyles.base,
|
|
162
|
+
isHindi && buttonStyles.baseHindi,
|
|
163
|
+
variantButtonStyle[variant],
|
|
164
|
+
fullWidth && buttonStyles.fullWidth,
|
|
165
|
+
disabled && buttonStyles.disabled,
|
|
166
|
+
pressed && isIOS && buttonStyles.pressedIOS,
|
|
167
|
+
pressed && !isIOS && buttonStyles.pressedAndroid,
|
|
168
|
+
{ alignSelf },
|
|
169
|
+
backgroundColor && { backgroundColor },
|
|
170
|
+
{ borderRadius },
|
|
171
|
+
containerStyle,
|
|
172
|
+
]}
|
|
173
|
+
android_ripple={{
|
|
174
|
+
color: 'rgba(255,255,255,0.2)',
|
|
175
|
+
borderless: true,
|
|
176
|
+
foreground: true,
|
|
177
|
+
}}
|
|
178
|
+
>
|
|
179
|
+
{isIconOnly ? (
|
|
180
|
+
<Icon name={(leftIcon || rightIcon)!} size={iconSize} />
|
|
181
|
+
) : (
|
|
182
|
+
<>
|
|
183
|
+
{leftIcon && (
|
|
184
|
+
<View style={fullWidth && buttonStyles.leftIcon}>
|
|
185
|
+
<Icon name={leftIcon} size={iconSize} />
|
|
186
|
+
</View>
|
|
187
|
+
)}
|
|
188
|
+
<View style={buttonStyles.content}>
|
|
189
|
+
{title ? (
|
|
190
|
+
<CustomText
|
|
191
|
+
style={[
|
|
192
|
+
buttonStyles.title,
|
|
193
|
+
loading && buttonStyles.hidden,
|
|
194
|
+
variantTextStyle[variant],
|
|
195
|
+
textStyle,
|
|
196
|
+
]}
|
|
197
|
+
variant={textVariant}
|
|
198
|
+
weight={textWeight}
|
|
199
|
+
numberOfLines={1}
|
|
200
|
+
>
|
|
201
|
+
{title}
|
|
202
|
+
</CustomText>
|
|
203
|
+
) : (
|
|
204
|
+
children
|
|
205
|
+
)}
|
|
206
|
+
</View>
|
|
207
|
+
{rightIcon && (
|
|
208
|
+
<View style={fullWidth && buttonStyles.rightIcon}>
|
|
209
|
+
<Icon name={rightIcon} size={iconSize} />
|
|
210
|
+
</View>
|
|
211
|
+
)}
|
|
212
|
+
</>
|
|
213
|
+
)}
|
|
214
|
+
|
|
215
|
+
{loading && (
|
|
216
|
+
<View style={buttonStyles.loader}>
|
|
217
|
+
<ActivityIndicator color={variantTextStyle[variant].color} />
|
|
218
|
+
</View>
|
|
219
|
+
)}
|
|
220
|
+
</Pressable>
|
|
221
|
+
);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export default memo(CustomButton);
|
|
225
|
+
|
|
226
|
+
const buttonStyles = StyleSheet.create({
|
|
227
|
+
base: {
|
|
228
|
+
flexDirection: 'row',
|
|
229
|
+
alignItems: 'center',
|
|
230
|
+
justifyContent: 'center',
|
|
231
|
+
overflow: 'hidden',
|
|
232
|
+
padding: 12,
|
|
233
|
+
minHeight: normalize(46),
|
|
234
|
+
gap: 8,
|
|
235
|
+
},
|
|
236
|
+
/** Extra vertical room for Devanagari matras inside overflow:hidden. */
|
|
237
|
+
baseHindi: {
|
|
238
|
+
paddingVertical: 14,
|
|
239
|
+
minHeight: normalize(50),
|
|
240
|
+
},
|
|
241
|
+
fullWidth: {
|
|
242
|
+
width: '100%',
|
|
243
|
+
},
|
|
244
|
+
disabled: {
|
|
245
|
+
opacity: 0.8,
|
|
246
|
+
},
|
|
247
|
+
pressedIOS: {
|
|
248
|
+
opacity: 0.9,
|
|
249
|
+
transform: [{ scale: 0.94 }],
|
|
250
|
+
},
|
|
251
|
+
pressedAndroid: {
|
|
252
|
+
opacity: 0.9,
|
|
253
|
+
transform: [{ scale: 0.96 }],
|
|
254
|
+
},
|
|
255
|
+
content: {
|
|
256
|
+
flexDirection: 'row',
|
|
257
|
+
alignItems: 'center',
|
|
258
|
+
flexShrink: 0,
|
|
259
|
+
},
|
|
260
|
+
title: {
|
|
261
|
+
flexShrink: 0,
|
|
262
|
+
},
|
|
263
|
+
loader: {
|
|
264
|
+
...StyleSheet.absoluteFill,
|
|
265
|
+
justifyContent: 'center',
|
|
266
|
+
alignItems: 'center',
|
|
267
|
+
},
|
|
268
|
+
hidden: {
|
|
269
|
+
opacity: 0,
|
|
270
|
+
},
|
|
271
|
+
leftIcon: { position: 'absolute', left: 14 },
|
|
272
|
+
rightIcon: { position: 'absolute', right: 14 },
|
|
273
|
+
});
|