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,86 @@
1
+ import React, {
2
+ forwardRef,
3
+ memo,
4
+ useEffect,
5
+ useImperativeHandle,
6
+ useRef,
7
+ } from 'react';
8
+ import {
9
+ useDocumentPicker,
10
+ type PickedFile,
11
+ } from '@/hooks/useDocumentPicker';
12
+ import ImagePickerSheet from './bottom-sheet/sheets/ImagePickerSheet';
13
+ import { BSRef } from './bottom-sheet/types';
14
+
15
+ export type DocumentPickerRef = {
16
+ open: () => void;
17
+ close: () => void;
18
+ };
19
+
20
+ type SourceType = 'files' | 'camera' | 'both';
21
+
22
+ interface Props {
23
+ source?: SourceType;
24
+ maxSize?: number;
25
+ quality?: number;
26
+ multiple?: boolean;
27
+ onDocumentChange?: (file: PickedFile) => void;
28
+ }
29
+
30
+ const DocumentPicker = forwardRef<DocumentPickerRef, Props>(
31
+ (
32
+ {
33
+ source = 'both',
34
+ maxSize = 1024,
35
+ quality = 85,
36
+ multiple = false,
37
+ onDocumentChange,
38
+ },
39
+ ref,
40
+ ) => {
41
+ const sheetRef = useRef<BSRef>(null);
42
+ const { captureFromCamera, documents, pickFromFiles, resetDocuments } =
43
+ useDocumentPicker({
44
+ maxSize,
45
+ quality,
46
+ multiple,
47
+ });
48
+
49
+ useImperativeHandle(
50
+ ref,
51
+ () => ({
52
+ open: () => {
53
+ if (source === 'both') {
54
+ sheetRef.current?.open();
55
+ } else if (source === 'camera') {
56
+ captureFromCamera();
57
+ } else {
58
+ pickFromFiles();
59
+ }
60
+ },
61
+ close: () => sheetRef.current?.close(),
62
+ }),
63
+ [source, captureFromCamera, pickFromFiles],
64
+ );
65
+
66
+ useEffect(() => {
67
+ if (!documents.length) return;
68
+
69
+ onDocumentChange?.(documents[0]);
70
+ resetDocuments();
71
+ }, [documents, onDocumentChange, resetDocuments]);
72
+
73
+ return (
74
+ <ImagePickerSheet
75
+ ref={sheetRef}
76
+ onCamera={captureFromCamera}
77
+ onGallery={pickFromFiles}
78
+ canDocUpload
79
+ />
80
+ );
81
+ },
82
+ );
83
+
84
+ DocumentPicker.displayName = 'DocumentPicker';
85
+
86
+ export default memo(DocumentPicker);
@@ -0,0 +1,47 @@
1
+ import { useAppTheme } from '@/context/ThemeContext';
2
+ import { useAppSelector } from '@/hooks/useAppSelector';
3
+ import React from 'react';
4
+ import { View, ActivityIndicator, StyleSheet, Modal } from 'react-native';
5
+
6
+ const GlobalLoader = () => {
7
+ const isLoading = useAppSelector(state => state.loader.isLoading);
8
+ const { color } = useAppTheme();
9
+
10
+ return (
11
+ <Modal transparent visible={isLoading} statusBarTranslucent>
12
+ <View style={styles.container}>
13
+ <View
14
+ style={[
15
+ styles.loaderBox,
16
+ { backgroundColor: color.background_secondary },
17
+ ]}
18
+ >
19
+ <ActivityIndicator size="large" color={color.primary} />
20
+ </View>
21
+ </View>
22
+ </Modal>
23
+ );
24
+ };
25
+
26
+ export default GlobalLoader;
27
+
28
+ const styles = StyleSheet.create({
29
+ container: {
30
+ flex: 1,
31
+ backgroundColor: 'rgba(0,0,0,0.5)',
32
+ justifyContent: 'center',
33
+ alignItems: 'center',
34
+ },
35
+ loaderBox: {
36
+ width: 70,
37
+ height: 70,
38
+ borderRadius: 12,
39
+ justifyContent: 'center',
40
+ alignItems: 'center',
41
+ elevation: 5,
42
+ shadowColor: '#000',
43
+ shadowOffset: { width: 0, height: 2 },
44
+ shadowOpacity: 0.25,
45
+ shadowRadius: 4,
46
+ },
47
+ });
@@ -0,0 +1,28 @@
1
+ import { IconName, Icons } from '@/assets/icons';
2
+ import React from 'react';
3
+ import { SvgProps } from 'react-native-svg';
4
+
5
+ export interface IconProps extends SvgProps {
6
+ name: IconName;
7
+ size?: number;
8
+ color?: string;
9
+ }
10
+
11
+ const Icon = ({ name, size = 24, color, ...props }: IconProps) => {
12
+ const Component = Icons[name];
13
+
14
+ if (!Component) {
15
+ return null;
16
+ }
17
+
18
+ return (
19
+ <Component
20
+ width={size}
21
+ height={size}
22
+ {...(color ? { fill: color } : {})}
23
+ {...props}
24
+ />
25
+ );
26
+ };
27
+
28
+ export default Icon;
@@ -0,0 +1,104 @@
1
+ import Haptics from '@mhpdev/react-native-haptics';
2
+ import React, { memo, useCallback, useRef } from 'react';
3
+ import {
4
+ Pressable,
5
+ StyleSheet,
6
+ ViewStyle,
7
+ StyleProp,
8
+ Insets,
9
+ } from 'react-native';
10
+ import { isIOS } from '@/constants/device';
11
+ import Icon from './Icon';
12
+ import { IconName } from '@/assets/icons';
13
+
14
+ type HapticType = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';
15
+
16
+ export interface PressableIconProps {
17
+ name: IconName;
18
+ size?: number;
19
+ color?: string;
20
+ onPress?: () => Promise<void> | void;
21
+ onLongPress?: () => void;
22
+ disabled?: boolean;
23
+ haptic?: HapticType;
24
+ hitSlop?: number | Insets;
25
+ backgroundColor?: string;
26
+ borderRadius?: number;
27
+ containerStyle?: StyleProp<ViewStyle>;
28
+ accessibilityLabel?: string;
29
+ }
30
+
31
+ const PressableIcon = ({
32
+ name,
33
+ size = 22,
34
+ color,
35
+ onPress,
36
+ onLongPress,
37
+ disabled = false,
38
+ haptic = 'light',
39
+ hitSlop = 8,
40
+ backgroundColor,
41
+ borderRadius,
42
+ containerStyle,
43
+ accessibilityLabel,
44
+ }: PressableIconProps) => {
45
+ const pressLock = useRef(false);
46
+
47
+ const handlePress = useCallback(async () => {
48
+ if (pressLock.current || disabled) return;
49
+
50
+ pressLock.current = true;
51
+ Haptics.impact(haptic);
52
+
53
+ try {
54
+ await onPress?.();
55
+ } finally {
56
+ pressLock.current = false;
57
+ }
58
+ }, [disabled, haptic, onPress]);
59
+
60
+ return (
61
+ <Pressable
62
+ onPress={handlePress}
63
+ onLongPress={onLongPress}
64
+ disabled={disabled}
65
+ hitSlop={hitSlop}
66
+ accessibilityRole="button"
67
+ accessibilityLabel={accessibilityLabel ?? name}
68
+ accessibilityState={{ disabled }}
69
+ android_ripple={{ color: 'transparent' }}
70
+ style={({ pressed }) => [
71
+ styles.base,
72
+ backgroundColor != null && { backgroundColor },
73
+ borderRadius != null && { borderRadius },
74
+ disabled && styles.disabled,
75
+ pressed && isIOS && styles.pressedIOS,
76
+ pressed && !isIOS && styles.pressedAndroid,
77
+ containerStyle,
78
+ ]}
79
+ >
80
+ <Icon name={name} size={size} color={color} />
81
+ </Pressable>
82
+ );
83
+ };
84
+
85
+ export default memo(PressableIcon);
86
+
87
+ const styles = StyleSheet.create({
88
+ base: {
89
+ justifyContent: 'center',
90
+ alignItems: 'center',
91
+ overflow: 'hidden',
92
+ },
93
+ disabled: {
94
+ opacity: 0.5,
95
+ },
96
+ pressedIOS: {
97
+ opacity: 0.7,
98
+ transform: [{ scale: 0.94 }],
99
+ },
100
+ pressedAndroid: {
101
+ opacity: 0.85,
102
+ transform: [{ scale: 0.96 }],
103
+ },
104
+ });
@@ -0,0 +1,30 @@
1
+ import React, { forwardRef, memo, useMemo } from 'react';
2
+ import BottomSheet, { BottomSheetProps } from '@gorhom/bottom-sheet';
3
+ import { useAppTheme } from '@/context/ThemeContext';
4
+
5
+ interface Props extends Partial<Omit<BottomSheetProps, 'snapPoints'>> {
6
+ children: React.ReactNode;
7
+ snapPoints?: string[];
8
+ }
9
+
10
+ const BaseBottomSheet = forwardRef<BottomSheet, Props>(
11
+ ({ children, snapPoints = ['50%'], ...rest }, ref) => {
12
+ const memoSnapPoints = useMemo(() => snapPoints, [snapPoints]);
13
+ const { color } = useAppTheme();
14
+
15
+ return (
16
+ <BottomSheet
17
+ ref={ref}
18
+ snapPoints={memoSnapPoints}
19
+ backgroundStyle={[{ backgroundColor: color.background_secondary }]}
20
+ enablePanDownToClose
21
+ enableDynamicSizing
22
+ {...rest}
23
+ >
24
+ {children}
25
+ </BottomSheet>
26
+ );
27
+ },
28
+ );
29
+
30
+ export default memo(BaseBottomSheet);
@@ -0,0 +1,50 @@
1
+ import React, { forwardRef, memo, useCallback, useMemo } from 'react';
2
+ import {
3
+ BottomSheetBackdrop,
4
+ BottomSheetModal,
5
+ BottomSheetModalProps,
6
+ } from '@gorhom/bottom-sheet';
7
+ import { BottomSheetDefaultBackdropProps } from '@gorhom/bottom-sheet/lib/typescript/components/bottomSheetBackdrop/types';
8
+ import { useAppTheme } from '@/context/ThemeContext';
9
+
10
+ interface Props extends Partial<Omit<BottomSheetModalProps, 'snapPoints'>> {
11
+ children: React.ReactNode;
12
+ snapPoints?: string[];
13
+ }
14
+
15
+ const BaseBottomSheetModal = forwardRef<BottomSheetModal, Props>(
16
+ ({ children, snapPoints = ['50%'], ...rest }, ref) => {
17
+ const memoSnapPoints = useMemo(() => snapPoints, [snapPoints]);
18
+ const { color } = useAppTheme();
19
+
20
+ const bottomSheetBackdropRenderer = useCallback(
21
+ (backdropProps: BottomSheetDefaultBackdropProps) => {
22
+ return (
23
+ <BottomSheetBackdrop
24
+ {...backdropProps}
25
+ disappearsOnIndex={-1}
26
+ appearsOnIndex={0}
27
+ pressBehavior={'close'}
28
+ />
29
+ );
30
+ },
31
+ [],
32
+ );
33
+ return (
34
+ <BottomSheetModal
35
+ ref={ref}
36
+ snapPoints={memoSnapPoints}
37
+ backgroundStyle={[{ backgroundColor: color.background_secondary }]}
38
+ enablePanDownToClose
39
+ enableDynamicSizing
40
+ backdropComponent={bottomSheetBackdropRenderer}
41
+ handleIndicatorStyle={{ backgroundColor: color.border }}
42
+ {...rest}
43
+ >
44
+ {children}
45
+ </BottomSheetModal>
46
+ );
47
+ },
48
+ );
49
+
50
+ export default memo(BaseBottomSheetModal);
@@ -0,0 +1,310 @@
1
+ import React, {
2
+ forwardRef,
3
+ useImperativeHandle,
4
+ useCallback,
5
+ useMemo,
6
+ useRef,
7
+ } from 'react';
8
+ import { Pressable, StyleSheet, View } from 'react-native';
9
+ import {
10
+ BottomSheetModal,
11
+ BottomSheetView,
12
+ } from '@gorhom/bottom-sheet';
13
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
14
+ import { useTranslation } from 'react-i18next';
15
+ import type { IconName } from '@/assets/icons';
16
+ import Icon from '@/components/shared/Icon';
17
+ import CustomText from '@/components/shared/text/CustomText';
18
+ import { useAppTheme } from '@/context/ThemeContext';
19
+ import { ColorType, spacing } from '@/theme';
20
+ import { normalize } from '@/utils/normalize';
21
+ import BaseBottomSheetModal from '../BaseBottomSheetModal';
22
+ import { BSRef } from '../types';
23
+
24
+ interface Props {
25
+ onCamera: () => void;
26
+ onGallery: () => void;
27
+ /** When true, uses document-upload copy (images, PDF, etc.). */
28
+ canDocUpload?: boolean;
29
+ }
30
+
31
+ const OPEN_PICKER_DELAY_MS = 300;
32
+
33
+ type SourceOption = {
34
+ id: 'camera' | 'gallery';
35
+ icon: IconName;
36
+ photoLabelKey: 'imagePicker.camera' | 'imagePicker.gallery';
37
+ photoHintKey: 'imagePicker.cameraHint' | 'imagePicker.galleryHint';
38
+ docLabelKey: 'imagePicker.docCamera' | 'imagePicker.docGallery';
39
+ docHintKey: 'imagePicker.docCameraHint' | 'imagePicker.docGalleryHint';
40
+ };
41
+
42
+ const SOURCE_OPTIONS: SourceOption[] = [
43
+ {
44
+ id: 'camera',
45
+ icon: 'claim_upload',
46
+ photoLabelKey: 'imagePicker.camera',
47
+ photoHintKey: 'imagePicker.cameraHint',
48
+ docLabelKey: 'imagePicker.docCamera',
49
+ docHintKey: 'imagePicker.docCameraHint',
50
+ },
51
+ {
52
+ id: 'gallery',
53
+ icon: 'folder',
54
+ photoLabelKey: 'imagePicker.gallery',
55
+ photoHintKey: 'imagePicker.galleryHint',
56
+ docLabelKey: 'imagePicker.docGallery',
57
+ docHintKey: 'imagePicker.docGalleryHint',
58
+ },
59
+ ];
60
+
61
+ const ImagePickerSheet = forwardRef<BSRef, Props>(
62
+ ({ onCamera, onGallery, canDocUpload = false }, ref) => {
63
+ const { t } = useTranslation();
64
+ const insets = useSafeAreaInsets();
65
+ const { color } = useAppTheme();
66
+ const styles = useMemo(() => makeStyles(color), [color]);
67
+ const sheetRef = useRef<BottomSheetModal>(null);
68
+ const pendingActionRef = useRef<(() => void) | null>(null);
69
+
70
+ const titleKey = canDocUpload
71
+ ? 'imagePicker.docTitle'
72
+ : 'imagePicker.title';
73
+ const subtitleKey = canDocUpload
74
+ ? 'imagePicker.docSubtitle'
75
+ : 'imagePicker.subtitle';
76
+
77
+ useImperativeHandle(ref, () => ({
78
+ open: () => sheetRef.current?.present(),
79
+ close: () => sheetRef.current?.dismiss(),
80
+ }));
81
+
82
+ const runAfterClose = useCallback((action: () => void) => {
83
+ pendingActionRef.current = action;
84
+ sheetRef.current?.dismiss();
85
+ }, []);
86
+
87
+ const handleDismiss = useCallback(() => {
88
+ const action = pendingActionRef.current;
89
+ pendingActionRef.current = null;
90
+ if (!action) return;
91
+ setTimeout(action, OPEN_PICKER_DELAY_MS);
92
+ }, []);
93
+
94
+ const handleCamera = useCallback(() => {
95
+ runAfterClose(onCamera);
96
+ }, [onCamera, runAfterClose]);
97
+
98
+ const handleGallery = useCallback(() => {
99
+ runAfterClose(onGallery);
100
+ }, [onGallery, runAfterClose]);
101
+
102
+ const handleCancel = useCallback(() => {
103
+ sheetRef.current?.dismiss();
104
+ }, []);
105
+
106
+ const handleOptionPress = useCallback(
107
+ (id: SourceOption['id']) => {
108
+ if (id === 'camera') {
109
+ handleCamera();
110
+ return;
111
+ }
112
+ handleGallery();
113
+ },
114
+ [handleCamera, handleGallery],
115
+ );
116
+
117
+ return (
118
+ <BaseBottomSheetModal
119
+ ref={sheetRef}
120
+ enableDynamicSizing
121
+ enablePanDownToClose
122
+ onDismiss={handleDismiss}
123
+ backgroundStyle={styles.sheetBackground}
124
+ handleIndicatorStyle={styles.handleIndicator}
125
+ >
126
+ <BottomSheetView
127
+ style={[
128
+ styles.content,
129
+ { paddingBottom: Math.max(insets.bottom, spacing.md) },
130
+ ]}
131
+ >
132
+ <View style={styles.header}>
133
+ <View style={styles.headerTop}>
134
+ <CustomText
135
+ variant="titleSm"
136
+ weight="700"
137
+ textColor={color.text_heading}
138
+ style={styles.title}
139
+ >
140
+ {t(titleKey)}
141
+ </CustomText>
142
+ <Pressable
143
+ onPress={handleCancel}
144
+ hitSlop={12}
145
+ style={({ pressed }) => [
146
+ styles.cancelHit,
147
+ pressed && styles.cancelPressed,
148
+ ]}
149
+ accessibilityRole="button"
150
+ accessibilityLabel={t('common.cancel')}
151
+ >
152
+ <CustomText
153
+ variant="label"
154
+ weight="600"
155
+ textColor={color.danger_strong}
156
+ style={styles.cancelLabel}
157
+ >
158
+ {t('common.cancel')}
159
+ </CustomText>
160
+ </Pressable>
161
+ </View>
162
+ <CustomText
163
+ variant="label"
164
+ weight="400"
165
+ textColor={color.text_secondary}
166
+ style={styles.subtitle}
167
+ >
168
+ {t(subtitleKey)}
169
+ </CustomText>
170
+ </View>
171
+
172
+ <View style={styles.options}>
173
+ {SOURCE_OPTIONS.map(option => {
174
+ const labelKey = canDocUpload
175
+ ? option.docLabelKey
176
+ : option.photoLabelKey;
177
+ const hintKey = canDocUpload
178
+ ? option.docHintKey
179
+ : option.photoHintKey;
180
+
181
+ return (
182
+ <Pressable
183
+ key={option.id}
184
+ onPress={() => handleOptionPress(option.id)}
185
+ style={({ pressed }) => [
186
+ styles.optionCard,
187
+ pressed && styles.optionPressed,
188
+ ]}
189
+ accessibilityRole="button"
190
+ accessibilityLabel={t(labelKey)}
191
+ >
192
+ <View style={styles.optionIconTile}>
193
+ <Icon name={option.icon} width={20} height={20} />
194
+ </View>
195
+ <View style={styles.optionCopy}>
196
+ <CustomText
197
+ variant="label"
198
+ weight="700"
199
+ textColor={color.text_heading}
200
+ style={styles.optionLabel}
201
+ >
202
+ {t(labelKey)}
203
+ </CustomText>
204
+ <CustomText
205
+ variant="caption"
206
+ weight="400"
207
+ textColor={color.text_subtle}
208
+ style={styles.optionHint}
209
+ >
210
+ {t(hintKey)}
211
+ </CustomText>
212
+ </View>
213
+ </Pressable>
214
+ );
215
+ })}
216
+ </View>
217
+ </BottomSheetView>
218
+ </BaseBottomSheetModal>
219
+ );
220
+ },
221
+ );
222
+
223
+ export default React.memo(ImagePickerSheet);
224
+
225
+ const makeStyles = (color: ColorType) =>
226
+ StyleSheet.create({
227
+ sheetBackground: {
228
+ backgroundColor: color.background_primary,
229
+ borderTopLeftRadius: normalize(24),
230
+ borderTopRightRadius: normalize(24),
231
+ },
232
+ handleIndicator: {
233
+ width: normalize(40),
234
+ height: normalize(4),
235
+ borderRadius: 999,
236
+ backgroundColor: color.border,
237
+ },
238
+ content: {
239
+ paddingHorizontal: spacing.md,
240
+ paddingTop: spacing.xs,
241
+ },
242
+ header: {
243
+ marginBottom: spacing.md,
244
+ gap: 6,
245
+ },
246
+ headerTop: {
247
+ flexDirection: 'row',
248
+ alignItems: 'center',
249
+ justifyContent: 'space-between',
250
+ gap: 12,
251
+ },
252
+ title: {
253
+ marginBottom: 0,
254
+ flex: 1,
255
+ },
256
+ cancelHit: {
257
+ paddingVertical: 2,
258
+ paddingLeft: 8,
259
+ },
260
+ cancelLabel: {
261
+ marginBottom: 0,
262
+ },
263
+ cancelPressed: {
264
+ opacity: 0.7,
265
+ },
266
+ subtitle: {
267
+ marginBottom: 0,
268
+ lineHeight: normalize(20),
269
+ },
270
+ options: {
271
+ gap: 10,
272
+ marginBottom: spacing.xs,
273
+ },
274
+ optionCard: {
275
+ flexDirection: 'row',
276
+ alignItems: 'center',
277
+ gap: 12,
278
+ minHeight: normalize(72),
279
+ paddingHorizontal: spacing.md,
280
+ paddingVertical: spacing.sm + 2,
281
+ borderRadius: normalize(16),
282
+ backgroundColor: color.background_soft,
283
+ borderWidth: 1,
284
+ borderColor: color.border,
285
+ overflow: 'hidden',
286
+ },
287
+ optionPressed: {
288
+ opacity: 0.88,
289
+ transform: [{ scale: 0.98 }],
290
+ },
291
+ optionIconTile: {
292
+ width: normalize(44),
293
+ height: normalize(44),
294
+ borderRadius: normalize(14),
295
+ backgroundColor: color.secondary_muted,
296
+ alignItems: 'center',
297
+ justifyContent: 'center',
298
+ },
299
+ optionCopy: {
300
+ flex: 1,
301
+ gap: 2,
302
+ minWidth: 0,
303
+ },
304
+ optionLabel: {
305
+ marginBottom: 0,
306
+ },
307
+ optionHint: {
308
+ marginBottom: 0,
309
+ },
310
+ });
@@ -0,0 +1,4 @@
1
+ export type BSRef = {
2
+ open: () => void;
3
+ close: () => void;
4
+ };