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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +378 -2
  3. package/bin/create-react-native-starter-kit.js +95 -0
  4. package/lib/copy-src.js +127 -0
  5. package/lib/creator.js +211 -0
  6. package/lib/deps.js +58 -0
  7. package/lib/patch-configs.js +318 -0
  8. package/lib/patch-native.js +588 -0
  9. package/package.json +47 -4
  10. package/scripts/sync-template.js +52 -0
  11. package/template/.env.example +3 -0
  12. package/template/patches/react-native-element-dropdown+2.12.4.patch +67 -0
  13. package/template/src/app/App.tsx +25 -0
  14. package/template/src/app/navigation/root.tsx +24 -0
  15. package/template/src/app/navigation/stacks/app.stack.tsx +67 -0
  16. package/template/src/app/navigation/stacks/app.tab.tsx +72 -0
  17. package/template/src/app/navigation/stacks/auth.stack.tsx +56 -0
  18. package/template/src/app/providers.tsx +43 -0
  19. package/template/src/assets/fonts/InterTight-Black.ttf +0 -0
  20. package/template/src/assets/fonts/InterTight-BlackItalic.ttf +0 -0
  21. package/template/src/assets/fonts/InterTight-Bold.ttf +0 -0
  22. package/template/src/assets/fonts/InterTight-BoldItalic.ttf +0 -0
  23. package/template/src/assets/fonts/InterTight-ExtraBold.ttf +0 -0
  24. package/template/src/assets/fonts/InterTight-ExtraBoldItalic.ttf +0 -0
  25. package/template/src/assets/fonts/InterTight-ExtraLight.ttf +0 -0
  26. package/template/src/assets/fonts/InterTight-ExtraLightItalic.ttf +0 -0
  27. package/template/src/assets/fonts/InterTight-Italic.ttf +0 -0
  28. package/template/src/assets/fonts/InterTight-Light.ttf +0 -0
  29. package/template/src/assets/fonts/InterTight-LightItalic.ttf +0 -0
  30. package/template/src/assets/fonts/InterTight-Medium.ttf +0 -0
  31. package/template/src/assets/fonts/InterTight-MediumItalic.ttf +0 -0
  32. package/template/src/assets/fonts/InterTight-Regular.ttf +0 -0
  33. package/template/src/assets/fonts/InterTight-SemiBold.ttf +0 -0
  34. package/template/src/assets/fonts/InterTight-SemiBoldItalic.ttf +0 -0
  35. package/template/src/assets/fonts/InterTight-Thin.ttf +0 -0
  36. package/template/src/assets/fonts/InterTight-ThinItalic.ttf +0 -0
  37. package/template/src/assets/icons/back.svg +3 -0
  38. package/template/src/assets/icons/calendar.svg +3 -0
  39. package/template/src/assets/icons/claim_upload.svg +3 -0
  40. package/template/src/assets/icons/clock.svg +1 -0
  41. package/template/src/assets/icons/downArrow.svg +3 -0
  42. package/template/src/assets/icons/edit.svg +3 -0
  43. package/template/src/assets/icons/eye.svg +4 -0
  44. package/template/src/assets/icons/eyeClose.svg +7 -0
  45. package/template/src/assets/icons/folder.svg +5 -0
  46. package/template/src/assets/icons/home.svg +4 -0
  47. package/template/src/assets/icons/index.ts +35 -0
  48. package/template/src/assets/icons/log_out.svg +4 -0
  49. package/template/src/assets/icons/setting.svg +4 -0
  50. package/template/src/assets/icons/tabs/home/filled_dark.svg +3 -0
  51. package/template/src/assets/icons/tabs/home/filled_light.svg +3 -0
  52. package/template/src/assets/icons/tabs/home/outline.svg +4 -0
  53. package/template/src/assets/icons/tabs/index.ts +31 -0
  54. package/template/src/assets/icons/tabs/profile/filled_dark.svg +6 -0
  55. package/template/src/assets/icons/tabs/profile/filled_light.svg +6 -0
  56. package/template/src/assets/icons/tabs/profile/outline.svg +3 -0
  57. package/template/src/assets/icons/tooltip_dark.svg +1 -0
  58. package/template/src/assets/icons/tooltip_light.svg +1 -0
  59. package/template/src/assets/icons/upArrow.svg +3 -0
  60. package/template/src/assets/images/back.png +0 -0
  61. package/template/src/assets/images/index.ts +7 -0
  62. package/template/src/assets/images/placeholder/profile.png +0 -0
  63. package/template/src/components/shared/AppImage.tsx +190 -0
  64. package/template/src/components/shared/AvatarPicker.tsx +175 -0
  65. package/template/src/components/shared/CustomButton.tsx +273 -0
  66. package/template/src/components/shared/DocumentPicker.tsx +86 -0
  67. package/template/src/components/shared/GlobalLoader.tsx +47 -0
  68. package/template/src/components/shared/Icon.tsx +28 -0
  69. package/template/src/components/shared/PressableIcon.tsx +104 -0
  70. package/template/src/components/shared/bottom-sheet/BaseBottomSheet.tsx +30 -0
  71. package/template/src/components/shared/bottom-sheet/BaseBottomSheetModal.tsx +50 -0
  72. package/template/src/components/shared/bottom-sheet/sheets/ImagePickerSheet.tsx +310 -0
  73. package/template/src/components/shared/bottom-sheet/types.ts +4 -0
  74. package/template/src/components/shared/form-input/FormInput.tsx +140 -0
  75. package/template/src/components/shared/form-input/FormInputRenderer.tsx +82 -0
  76. package/template/src/components/shared/form-input/FullNameInput.tsx +243 -0
  77. package/template/src/components/shared/form-input/formFieldStyles.ts +43 -0
  78. package/template/src/components/shared/form-input/type.ts +188 -0
  79. package/template/src/components/shared/form-input/variants/CountryPhoneVariant.tsx +289 -0
  80. package/template/src/components/shared/form-input/variants/DateTimeVariant.tsx +280 -0
  81. package/template/src/components/shared/form-input/variants/DropdownVariant.tsx +221 -0
  82. package/template/src/components/shared/form-input/variants/TextInputVariant.tsx +300 -0
  83. package/template/src/components/shared/form-input/variants/ToggleVariant.tsx +194 -0
  84. package/template/src/components/shared/modal/BaseModal.tsx +83 -0
  85. package/template/src/components/shared/modal/common/AlertModal.tsx +173 -0
  86. package/template/src/components/shared/navigation/AnimatedTabIcon.tsx +37 -0
  87. package/template/src/components/shared/navigation/HeaderActionButton.tsx +70 -0
  88. package/template/src/components/shared/navigation/HeaderBackButton.tsx +38 -0
  89. package/template/src/components/shared/navigation/StackHeader.tsx +105 -0
  90. package/template/src/components/shared/navigation/tabIconRender.tsx +14 -0
  91. package/template/src/components/shared/offline/OfflineQueryBoundary.tsx +25 -0
  92. package/template/src/components/shared/offline/OfflineState.tsx +229 -0
  93. package/template/src/components/shared/offline/index.ts +6 -0
  94. package/template/src/components/shared/offline/types.ts +15 -0
  95. package/template/src/components/shared/offline/wifi-icon-animation/BrokenWifiAnimation.tsx +116 -0
  96. package/template/src/components/shared/offline/wifi-icon-animation/WifiPiece.tsx +80 -0
  97. package/template/src/components/shared/offline/wifi-icon-animation/geometry.ts +163 -0
  98. package/template/src/components/shared/offline/wifi-icon-animation/useWifiIconAnimationActive.ts +37 -0
  99. package/template/src/components/shared/skelton/BaseSkelton.tsx +71 -0
  100. package/template/src/components/shared/skelton/ShimmerHolder.ts +6 -0
  101. package/template/src/components/shared/skelton/holders/HomeShimmer.tsx +25 -0
  102. package/template/src/components/shared/skelton/holders/index.ts +1 -0
  103. package/template/src/components/shared/skelton/layouts/avatar.layout.ts +18 -0
  104. package/template/src/components/shared/skelton/layouts/home.layout.ts +16 -0
  105. package/template/src/components/shared/skelton/layouts/index.ts +3 -0
  106. package/template/src/components/shared/skelton/layouts/text.layout.ts +18 -0
  107. package/template/src/components/shared/text/CustomText.tsx +85 -0
  108. package/template/src/components/shared/text/ShimmerText.tsx +159 -0
  109. package/template/src/components/shared/text/types.ts +40 -0
  110. package/template/src/constants/device.ts +12 -0
  111. package/template/src/constants/endpoint.ts +11 -0
  112. package/template/src/constants/keyExtractor.ts +6 -0
  113. package/template/src/constants/limits.ts +9 -0
  114. package/template/src/constants/queryKey.ts +3 -0
  115. package/template/src/constants/regex.ts +7 -0
  116. package/template/src/context/NetworkContext.tsx +102 -0
  117. package/template/src/context/ThemeContext.tsx +56 -0
  118. package/template/src/hooks/app/index.ts +2 -0
  119. package/template/src/hooks/app/useGetProfile.ts +38 -0
  120. package/template/src/hooks/app/useUpdateProfile.ts +21 -0
  121. package/template/src/hooks/useAppDispatch.ts +6 -0
  122. package/template/src/hooks/useAppSelector.ts +4 -0
  123. package/template/src/hooks/useDebounce.ts +15 -0
  124. package/template/src/hooks/useDocumentPicker.ts +102 -0
  125. package/template/src/hooks/useImagePicker.ts +83 -0
  126. package/template/src/i18n/i18next.d.ts +9 -0
  127. package/template/src/i18n/index.ts +16 -0
  128. package/template/src/i18n/locales/en.json +274 -0
  129. package/template/src/i18n/locales/ru.json +165 -0
  130. package/template/src/i18n/resources.ts +11 -0
  131. package/template/src/redux/selectors/auth.selectors.ts +4 -0
  132. package/template/src/redux/slice/auth.slice.ts +23 -0
  133. package/template/src/redux/slice/loader.slice.ts +25 -0
  134. package/template/src/redux/slice/settings.slice.ts +26 -0
  135. package/template/src/redux/slice/user.slice.ts +25 -0
  136. package/template/src/screens/app/main-tab/index.tsx +73 -0
  137. package/template/src/screens/app/main-tab/style.ts +0 -0
  138. package/template/src/screens/app/profile-setup/index.tsx +162 -0
  139. package/template/src/screens/app/profile-setup/styles.ts +3 -0
  140. package/template/src/screens/auth/forgot-password/index.tsx +59 -0
  141. package/template/src/screens/auth/forgot-password/styles.ts +0 -0
  142. package/template/src/screens/auth/index.ts +4 -0
  143. package/template/src/screens/auth/login/index.tsx +138 -0
  144. package/template/src/screens/auth/login/styles.ts +3 -0
  145. package/template/src/screens/auth/signup/index.tsx +111 -0
  146. package/template/src/screens/auth/signup/styles.ts +3 -0
  147. package/template/src/screens/auth/verify-email/index.tsx +15 -0
  148. package/template/src/screens/auth/verify-email/styles.ts +3 -0
  149. package/template/src/screens/tab/home/index.tsx +49 -0
  150. package/template/src/screens/tab/home/styles.ts +3 -0
  151. package/template/src/screens/tab/index.ts +2 -0
  152. package/template/src/screens/tab/profile/index.tsx +50 -0
  153. package/template/src/screens/tab/profile/styles.ts +3 -0
  154. package/template/src/services/api/auth/auth.api.ts +22 -0
  155. package/template/src/services/api/auth/auth.endpoints.ts +7 -0
  156. package/template/src/services/api/auth/auth.types.ts +9 -0
  157. package/template/src/services/api/auth/index.ts +3 -0
  158. package/template/src/services/api/axios/axios.instance.ts +15 -0
  159. package/template/src/services/api/axios/axios.interceptors.ts +43 -0
  160. package/template/src/services/api/axios/index.ts +2 -0
  161. package/template/src/services/api/mock/mockAdapter.ts +97 -0
  162. package/template/src/services/api/user/index.ts +2 -0
  163. package/template/src/services/api/user/user.api.ts +67 -0
  164. package/template/src/services/api/user/user.endpoints.ts +0 -0
  165. package/template/src/services/api/user/user.types.ts +0 -0
  166. package/template/src/services/errors/backendErrorCodes.ts +7 -0
  167. package/template/src/services/errors/errorHandler.ts +94 -0
  168. package/template/src/services/errors/firebaseErrorMap.ts +61 -0
  169. package/template/src/services/errors/httpStatusMap.ts +47 -0
  170. package/template/src/services/errors/index.ts +4 -0
  171. package/template/src/services/network/index.ts +1 -0
  172. package/template/src/services/network/onlineManager.ts +22 -0
  173. package/template/src/services/query/index.ts +1 -0
  174. package/template/src/services/query/queryClient.ts +23 -0
  175. package/template/src/services/toast/ToastCard.tsx +137 -0
  176. package/template/src/services/toast/ToastConfig.tsx +32 -0
  177. package/template/src/services/toast/index.ts +3 -0
  178. package/template/src/services/toast/toast.ts +68 -0
  179. package/template/src/storage/mmkvAdapter.ts +3 -0
  180. package/template/src/storage/mmkvInstance.ts +16 -0
  181. package/template/src/store/index.ts +15 -0
  182. package/template/src/store/mmkv.ts +6 -0
  183. package/template/src/store/persist.ts +10 -0
  184. package/template/src/store/rootReducer.ts +26 -0
  185. package/template/src/theme/dark.ts +40 -0
  186. package/template/src/theme/fonts.ts +20 -0
  187. package/template/src/theme/index.ts +6 -0
  188. package/template/src/theme/layout.ts +23 -0
  189. package/template/src/theme/light.ts +41 -0
  190. package/template/src/theme/palette.ts +32 -0
  191. package/template/src/theme/spacing.ts +7 -0
  192. package/template/src/theme/typography.ts +80 -0
  193. package/template/src/types/api.types.ts +34 -0
  194. package/template/src/types/env.d.ts +6 -0
  195. package/template/src/types/index.ts +2 -0
  196. package/template/src/types/navigation.types.ts +94 -0
  197. package/template/src/utils/clearAppSession.ts +10 -0
  198. package/template/src/utils/date.ts +19 -0
  199. package/template/src/utils/documentPickerHandler.ts +96 -0
  200. package/template/src/utils/getFileNameFromUri.ts +18 -0
  201. package/template/src/utils/getInitials.ts +13 -0
  202. package/template/src/utils/hindiText.ts +33 -0
  203. package/template/src/utils/imageCompress.ts +97 -0
  204. package/template/src/utils/imagePickerHandler.ts +200 -0
  205. package/template/src/utils/maskPhone.ts +17 -0
  206. package/template/src/utils/normalize.ts +12 -0
  207. package/template/src/validation/messages.ts +11 -0
  208. package/template/src/validation/rules.ts +44 -0
  209. package/template/src/validation/schema/auth.schema.ts +53 -0
  210. package/template/src/validation/schema/user.schema.ts +46 -0
  211. package/template/src/validation/tValError.ts +13 -0
@@ -0,0 +1,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
+ });