create-react-native-starter-kit 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +378 -2
- package/bin/create-react-native-starter-kit.js +95 -0
- package/lib/copy-src.js +127 -0
- package/lib/creator.js +211 -0
- package/lib/deps.js +58 -0
- package/lib/patch-configs.js +318 -0
- package/lib/patch-native.js +588 -0
- package/package.json +47 -4
- package/scripts/sync-template.js +52 -0
- package/template/.env.example +3 -0
- package/template/patches/react-native-element-dropdown+2.12.4.patch +67 -0
- package/template/src/app/App.tsx +25 -0
- package/template/src/app/navigation/root.tsx +24 -0
- package/template/src/app/navigation/stacks/app.stack.tsx +67 -0
- package/template/src/app/navigation/stacks/app.tab.tsx +72 -0
- package/template/src/app/navigation/stacks/auth.stack.tsx +56 -0
- package/template/src/app/providers.tsx +43 -0
- package/template/src/assets/fonts/InterTight-Black.ttf +0 -0
- package/template/src/assets/fonts/InterTight-BlackItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Bold.ttf +0 -0
- package/template/src/assets/fonts/InterTight-BoldItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-ExtraBold.ttf +0 -0
- package/template/src/assets/fonts/InterTight-ExtraBoldItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-ExtraLight.ttf +0 -0
- package/template/src/assets/fonts/InterTight-ExtraLightItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Italic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Light.ttf +0 -0
- package/template/src/assets/fonts/InterTight-LightItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Medium.ttf +0 -0
- package/template/src/assets/fonts/InterTight-MediumItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Regular.ttf +0 -0
- package/template/src/assets/fonts/InterTight-SemiBold.ttf +0 -0
- package/template/src/assets/fonts/InterTight-SemiBoldItalic.ttf +0 -0
- package/template/src/assets/fonts/InterTight-Thin.ttf +0 -0
- package/template/src/assets/fonts/InterTight-ThinItalic.ttf +0 -0
- package/template/src/assets/icons/back.svg +3 -0
- package/template/src/assets/icons/calendar.svg +3 -0
- package/template/src/assets/icons/claim_upload.svg +3 -0
- package/template/src/assets/icons/clock.svg +1 -0
- package/template/src/assets/icons/downArrow.svg +3 -0
- package/template/src/assets/icons/edit.svg +3 -0
- package/template/src/assets/icons/eye.svg +4 -0
- package/template/src/assets/icons/eyeClose.svg +7 -0
- package/template/src/assets/icons/folder.svg +5 -0
- package/template/src/assets/icons/home.svg +4 -0
- package/template/src/assets/icons/index.ts +35 -0
- package/template/src/assets/icons/log_out.svg +4 -0
- package/template/src/assets/icons/setting.svg +4 -0
- package/template/src/assets/icons/tabs/home/filled_dark.svg +3 -0
- package/template/src/assets/icons/tabs/home/filled_light.svg +3 -0
- package/template/src/assets/icons/tabs/home/outline.svg +4 -0
- package/template/src/assets/icons/tabs/index.ts +31 -0
- package/template/src/assets/icons/tabs/profile/filled_dark.svg +6 -0
- package/template/src/assets/icons/tabs/profile/filled_light.svg +6 -0
- package/template/src/assets/icons/tabs/profile/outline.svg +3 -0
- package/template/src/assets/icons/tooltip_dark.svg +1 -0
- package/template/src/assets/icons/tooltip_light.svg +1 -0
- package/template/src/assets/icons/upArrow.svg +3 -0
- package/template/src/assets/images/back.png +0 -0
- package/template/src/assets/images/index.ts +7 -0
- package/template/src/assets/images/placeholder/profile.png +0 -0
- package/template/src/components/shared/AppImage.tsx +190 -0
- package/template/src/components/shared/AvatarPicker.tsx +175 -0
- package/template/src/components/shared/CustomButton.tsx +273 -0
- package/template/src/components/shared/DocumentPicker.tsx +86 -0
- package/template/src/components/shared/GlobalLoader.tsx +47 -0
- package/template/src/components/shared/Icon.tsx +28 -0
- package/template/src/components/shared/PressableIcon.tsx +104 -0
- package/template/src/components/shared/bottom-sheet/BaseBottomSheet.tsx +30 -0
- package/template/src/components/shared/bottom-sheet/BaseBottomSheetModal.tsx +50 -0
- package/template/src/components/shared/bottom-sheet/sheets/ImagePickerSheet.tsx +310 -0
- package/template/src/components/shared/bottom-sheet/types.ts +4 -0
- package/template/src/components/shared/form-input/FormInput.tsx +140 -0
- package/template/src/components/shared/form-input/FormInputRenderer.tsx +82 -0
- package/template/src/components/shared/form-input/FullNameInput.tsx +243 -0
- package/template/src/components/shared/form-input/formFieldStyles.ts +43 -0
- package/template/src/components/shared/form-input/type.ts +188 -0
- package/template/src/components/shared/form-input/variants/CountryPhoneVariant.tsx +289 -0
- package/template/src/components/shared/form-input/variants/DateTimeVariant.tsx +280 -0
- package/template/src/components/shared/form-input/variants/DropdownVariant.tsx +221 -0
- package/template/src/components/shared/form-input/variants/TextInputVariant.tsx +300 -0
- package/template/src/components/shared/form-input/variants/ToggleVariant.tsx +194 -0
- package/template/src/components/shared/modal/BaseModal.tsx +83 -0
- package/template/src/components/shared/modal/common/AlertModal.tsx +173 -0
- package/template/src/components/shared/navigation/AnimatedTabIcon.tsx +37 -0
- package/template/src/components/shared/navigation/HeaderActionButton.tsx +70 -0
- package/template/src/components/shared/navigation/HeaderBackButton.tsx +38 -0
- package/template/src/components/shared/navigation/StackHeader.tsx +105 -0
- package/template/src/components/shared/navigation/tabIconRender.tsx +14 -0
- package/template/src/components/shared/offline/OfflineQueryBoundary.tsx +25 -0
- package/template/src/components/shared/offline/OfflineState.tsx +229 -0
- package/template/src/components/shared/offline/index.ts +6 -0
- package/template/src/components/shared/offline/types.ts +15 -0
- package/template/src/components/shared/offline/wifi-icon-animation/BrokenWifiAnimation.tsx +116 -0
- package/template/src/components/shared/offline/wifi-icon-animation/WifiPiece.tsx +80 -0
- package/template/src/components/shared/offline/wifi-icon-animation/geometry.ts +163 -0
- package/template/src/components/shared/offline/wifi-icon-animation/useWifiIconAnimationActive.ts +37 -0
- package/template/src/components/shared/skelton/BaseSkelton.tsx +71 -0
- package/template/src/components/shared/skelton/ShimmerHolder.ts +6 -0
- package/template/src/components/shared/skelton/holders/HomeShimmer.tsx +25 -0
- package/template/src/components/shared/skelton/holders/index.ts +1 -0
- package/template/src/components/shared/skelton/layouts/avatar.layout.ts +18 -0
- package/template/src/components/shared/skelton/layouts/home.layout.ts +16 -0
- package/template/src/components/shared/skelton/layouts/index.ts +3 -0
- package/template/src/components/shared/skelton/layouts/text.layout.ts +18 -0
- package/template/src/components/shared/text/CustomText.tsx +85 -0
- package/template/src/components/shared/text/ShimmerText.tsx +159 -0
- package/template/src/components/shared/text/types.ts +40 -0
- package/template/src/constants/device.ts +12 -0
- package/template/src/constants/endpoint.ts +11 -0
- package/template/src/constants/keyExtractor.ts +6 -0
- package/template/src/constants/limits.ts +9 -0
- package/template/src/constants/queryKey.ts +3 -0
- package/template/src/constants/regex.ts +7 -0
- package/template/src/context/NetworkContext.tsx +102 -0
- package/template/src/context/ThemeContext.tsx +56 -0
- package/template/src/hooks/app/index.ts +2 -0
- package/template/src/hooks/app/useGetProfile.ts +38 -0
- package/template/src/hooks/app/useUpdateProfile.ts +21 -0
- package/template/src/hooks/useAppDispatch.ts +6 -0
- package/template/src/hooks/useAppSelector.ts +4 -0
- package/template/src/hooks/useDebounce.ts +15 -0
- package/template/src/hooks/useDocumentPicker.ts +102 -0
- package/template/src/hooks/useImagePicker.ts +83 -0
- package/template/src/i18n/i18next.d.ts +9 -0
- package/template/src/i18n/index.ts +16 -0
- package/template/src/i18n/locales/en.json +274 -0
- package/template/src/i18n/locales/ru.json +165 -0
- package/template/src/i18n/resources.ts +11 -0
- package/template/src/redux/selectors/auth.selectors.ts +4 -0
- package/template/src/redux/slice/auth.slice.ts +23 -0
- package/template/src/redux/slice/loader.slice.ts +25 -0
- package/template/src/redux/slice/settings.slice.ts +26 -0
- package/template/src/redux/slice/user.slice.ts +25 -0
- package/template/src/screens/app/main-tab/index.tsx +73 -0
- package/template/src/screens/app/main-tab/style.ts +0 -0
- package/template/src/screens/app/profile-setup/index.tsx +162 -0
- package/template/src/screens/app/profile-setup/styles.ts +3 -0
- package/template/src/screens/auth/forgot-password/index.tsx +59 -0
- package/template/src/screens/auth/forgot-password/styles.ts +0 -0
- package/template/src/screens/auth/index.ts +4 -0
- package/template/src/screens/auth/login/index.tsx +138 -0
- package/template/src/screens/auth/login/styles.ts +3 -0
- package/template/src/screens/auth/signup/index.tsx +111 -0
- package/template/src/screens/auth/signup/styles.ts +3 -0
- package/template/src/screens/auth/verify-email/index.tsx +15 -0
- package/template/src/screens/auth/verify-email/styles.ts +3 -0
- package/template/src/screens/tab/home/index.tsx +49 -0
- package/template/src/screens/tab/home/styles.ts +3 -0
- package/template/src/screens/tab/index.ts +2 -0
- package/template/src/screens/tab/profile/index.tsx +50 -0
- package/template/src/screens/tab/profile/styles.ts +3 -0
- package/template/src/services/api/auth/auth.api.ts +22 -0
- package/template/src/services/api/auth/auth.endpoints.ts +7 -0
- package/template/src/services/api/auth/auth.types.ts +9 -0
- package/template/src/services/api/auth/index.ts +3 -0
- package/template/src/services/api/axios/axios.instance.ts +15 -0
- package/template/src/services/api/axios/axios.interceptors.ts +43 -0
- package/template/src/services/api/axios/index.ts +2 -0
- package/template/src/services/api/mock/mockAdapter.ts +97 -0
- package/template/src/services/api/user/index.ts +2 -0
- package/template/src/services/api/user/user.api.ts +67 -0
- package/template/src/services/api/user/user.endpoints.ts +0 -0
- package/template/src/services/api/user/user.types.ts +0 -0
- package/template/src/services/errors/backendErrorCodes.ts +7 -0
- package/template/src/services/errors/errorHandler.ts +94 -0
- package/template/src/services/errors/firebaseErrorMap.ts +61 -0
- package/template/src/services/errors/httpStatusMap.ts +47 -0
- package/template/src/services/errors/index.ts +4 -0
- package/template/src/services/network/index.ts +1 -0
- package/template/src/services/network/onlineManager.ts +22 -0
- package/template/src/services/query/index.ts +1 -0
- package/template/src/services/query/queryClient.ts +23 -0
- package/template/src/services/toast/ToastCard.tsx +137 -0
- package/template/src/services/toast/ToastConfig.tsx +32 -0
- package/template/src/services/toast/index.ts +3 -0
- package/template/src/services/toast/toast.ts +68 -0
- package/template/src/storage/mmkvAdapter.ts +3 -0
- package/template/src/storage/mmkvInstance.ts +16 -0
- package/template/src/store/index.ts +15 -0
- package/template/src/store/mmkv.ts +6 -0
- package/template/src/store/persist.ts +10 -0
- package/template/src/store/rootReducer.ts +26 -0
- package/template/src/theme/dark.ts +40 -0
- package/template/src/theme/fonts.ts +20 -0
- package/template/src/theme/index.ts +6 -0
- package/template/src/theme/layout.ts +23 -0
- package/template/src/theme/light.ts +41 -0
- package/template/src/theme/palette.ts +32 -0
- package/template/src/theme/spacing.ts +7 -0
- package/template/src/theme/typography.ts +80 -0
- package/template/src/types/api.types.ts +34 -0
- package/template/src/types/env.d.ts +6 -0
- package/template/src/types/index.ts +2 -0
- package/template/src/types/navigation.types.ts +94 -0
- package/template/src/utils/clearAppSession.ts +10 -0
- package/template/src/utils/date.ts +19 -0
- package/template/src/utils/documentPickerHandler.ts +96 -0
- package/template/src/utils/getFileNameFromUri.ts +18 -0
- package/template/src/utils/getInitials.ts +13 -0
- package/template/src/utils/hindiText.ts +33 -0
- package/template/src/utils/imageCompress.ts +97 -0
- package/template/src/utils/imagePickerHandler.ts +200 -0
- package/template/src/utils/maskPhone.ts +17 -0
- package/template/src/utils/normalize.ts +12 -0
- package/template/src/validation/messages.ts +11 -0
- package/template/src/validation/rules.ts +44 -0
- package/template/src/validation/schema/auth.schema.ts +53 -0
- package/template/src/validation/schema/user.schema.ts +46 -0
- package/template/src/validation/tValError.ts +13 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React, { memo, ReactNode } from 'react';
|
|
2
|
+
import { ViewStyle, StyleProp } from 'react-native';
|
|
3
|
+
import Skeleton from 'react-native-reanimated-skeleton';
|
|
4
|
+
import { useAppTheme } from '@/context/ThemeContext';
|
|
5
|
+
import { ICustomViewStyle } from 'react-native-reanimated-skeleton/lib/typescript/constants';
|
|
6
|
+
|
|
7
|
+
export interface SkeletonLayoutItem {
|
|
8
|
+
key: string;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
marginTop?: number;
|
|
12
|
+
marginBottom?: number;
|
|
13
|
+
marginLeft?: number;
|
|
14
|
+
marginRight?: number;
|
|
15
|
+
borderRadius?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SkeletonBaseProps {
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
isLoading?: boolean;
|
|
21
|
+
layout?: ICustomViewStyle[];
|
|
22
|
+
duration?: number;
|
|
23
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
24
|
+
boneColor?: string;
|
|
25
|
+
highlightColor?: string;
|
|
26
|
+
animationType?: 'pulse' | 'shiver' | 'none';
|
|
27
|
+
animationDirection?:
|
|
28
|
+
| 'horizontalLeft'
|
|
29
|
+
| 'horizontalRight'
|
|
30
|
+
| 'verticalTop'
|
|
31
|
+
| 'verticalDown'
|
|
32
|
+
| 'diagonalDownLeft'
|
|
33
|
+
| 'diagonalDownRight'
|
|
34
|
+
| 'diagonalTopLeft'
|
|
35
|
+
| 'diagonalTopRight';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const BaseSkelton = ({
|
|
39
|
+
children,
|
|
40
|
+
isLoading = false,
|
|
41
|
+
layout,
|
|
42
|
+
duration = 1000,
|
|
43
|
+
containerStyle,
|
|
44
|
+
boneColor,
|
|
45
|
+
highlightColor,
|
|
46
|
+
animationType = 'shiver',
|
|
47
|
+
animationDirection = 'horizontalRight',
|
|
48
|
+
}: SkeletonBaseProps) => {
|
|
49
|
+
const { color } = useAppTheme();
|
|
50
|
+
|
|
51
|
+
const defaultBoneColor = boneColor ?? color.background_secondary;
|
|
52
|
+
const defaultHighlightColor = highlightColor ?? color.border;
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Skeleton
|
|
56
|
+
isLoading={isLoading}
|
|
57
|
+
layout={layout}
|
|
58
|
+
animationType={animationType}
|
|
59
|
+
animationDirection={animationDirection}
|
|
60
|
+
boneColor={defaultBoneColor}
|
|
61
|
+
highlightColor={defaultHighlightColor}
|
|
62
|
+
duration={duration}
|
|
63
|
+
containerStyle={[containerStyle]}
|
|
64
|
+
hasFadeIn={true}
|
|
65
|
+
>
|
|
66
|
+
{children}
|
|
67
|
+
</Skeleton>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default memo(BaseSkelton);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { memo, useMemo } from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import BaseSkelton from '@/components/shared/skelton/BaseSkelton';
|
|
4
|
+
import { homeShimmerLayout } from '@/components/shared/skelton/layouts';
|
|
5
|
+
|
|
6
|
+
const HomeShimmer = () => {
|
|
7
|
+
const layout = useMemo(() => homeShimmerLayout(), []);
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<View style={styles.content}>
|
|
11
|
+
<BaseSkelton isLoading layout={layout} containerStyle={styles.skeleton} />
|
|
12
|
+
</View>
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default memo(HomeShimmer);
|
|
17
|
+
|
|
18
|
+
const styles = StyleSheet.create({
|
|
19
|
+
content: {
|
|
20
|
+
flex: 1,
|
|
21
|
+
},
|
|
22
|
+
skeleton: {
|
|
23
|
+
width: '100%',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as HomeShimmer } from './HomeShimmer';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ICustomViewStyle } from 'react-native-reanimated-skeleton/lib/typescript/constants';
|
|
2
|
+
|
|
3
|
+
interface AvatarProps {
|
|
4
|
+
size?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const avatarPickerLayout = ({ size = 100 }: AvatarProps) => {
|
|
8
|
+
const layout: ICustomViewStyle[] = [
|
|
9
|
+
{
|
|
10
|
+
key: 'avatar',
|
|
11
|
+
width: size,
|
|
12
|
+
height: size,
|
|
13
|
+
borderRadius: size / 2,
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
return layout;
|
|
18
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { spacing } from '@/theme';
|
|
2
|
+
import { ICustomViewStyle } from 'react-native-reanimated-skeleton/lib/typescript/constants';
|
|
3
|
+
|
|
4
|
+
const AVATAR_SIZE = 150;
|
|
5
|
+
|
|
6
|
+
/** Matches Home content: the centered AvatarPicker (the title is rendered outside the boundary). */
|
|
7
|
+
export const homeShimmerLayout = (): ICustomViewStyle[] => [
|
|
8
|
+
{
|
|
9
|
+
key: 'avatar',
|
|
10
|
+
width: AVATAR_SIZE,
|
|
11
|
+
height: AVATAR_SIZE,
|
|
12
|
+
borderRadius: AVATAR_SIZE / 2,
|
|
13
|
+
alignSelf: 'center',
|
|
14
|
+
marginTop: spacing.md,
|
|
15
|
+
},
|
|
16
|
+
];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ICustomViewStyle } from 'react-native-reanimated-skeleton/lib/typescript/constants';
|
|
2
|
+
|
|
3
|
+
interface TextProps {
|
|
4
|
+
width?: number;
|
|
5
|
+
height?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const textLayout = ({ width = 100, height = 40 }: TextProps) => {
|
|
9
|
+
const layout: ICustomViewStyle[] = [
|
|
10
|
+
{
|
|
11
|
+
width: width,
|
|
12
|
+
height: height,
|
|
13
|
+
borderRadius: 50,
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
return layout;
|
|
18
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useAppTheme } from '@/context/ThemeContext';
|
|
2
|
+
import { FONT_MAP, TYPOGRAPHY } from '@/theme/typography';
|
|
3
|
+
import { getHindiTextStyle, isHindiLanguage } from '@/utils/hindiText';
|
|
4
|
+
import React, { memo, useMemo, useState } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { Text, StyleSheet } from 'react-native';
|
|
7
|
+
import { CustomTextProps } from './types';
|
|
8
|
+
|
|
9
|
+
const CustomText = ({
|
|
10
|
+
weight = '400',
|
|
11
|
+
variant = 'body',
|
|
12
|
+
textColor,
|
|
13
|
+
style,
|
|
14
|
+
textAlign,
|
|
15
|
+
onPress,
|
|
16
|
+
ellipsizeMode,
|
|
17
|
+
numberOfLines,
|
|
18
|
+
adjustsFontSizeToFit,
|
|
19
|
+
minimumFontScale,
|
|
20
|
+
children,
|
|
21
|
+
...restTextProps
|
|
22
|
+
}: CustomTextProps) => {
|
|
23
|
+
const { color } = useAppTheme();
|
|
24
|
+
const { i18n } = useTranslation();
|
|
25
|
+
const [pressed, setPressed] = useState<boolean>(false);
|
|
26
|
+
const opacity = pressed ? 0.8 : 1;
|
|
27
|
+
const isPressable = typeof onPress === 'function';
|
|
28
|
+
const isHindi = isHindiLanguage(i18n.language);
|
|
29
|
+
|
|
30
|
+
const composedStyle = useMemo(() => {
|
|
31
|
+
const base = [
|
|
32
|
+
styles.base,
|
|
33
|
+
TYPOGRAPHY[variant],
|
|
34
|
+
{
|
|
35
|
+
fontFamily: FONT_MAP[weight],
|
|
36
|
+
opacity: opacity,
|
|
37
|
+
color: textColor || color.text_primary,
|
|
38
|
+
textAlign: textAlign,
|
|
39
|
+
},
|
|
40
|
+
style,
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
if (!isHindi) {
|
|
44
|
+
return base;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return [...base, getHindiTextStyle(base)];
|
|
48
|
+
}, [
|
|
49
|
+
variant,
|
|
50
|
+
weight,
|
|
51
|
+
opacity,
|
|
52
|
+
textColor,
|
|
53
|
+
color.text_primary,
|
|
54
|
+
textAlign,
|
|
55
|
+
style,
|
|
56
|
+
isHindi,
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
const handlePressIn = () => setPressed(true);
|
|
60
|
+
const handlePressOut = () => setPressed(false);
|
|
61
|
+
return (
|
|
62
|
+
<Text
|
|
63
|
+
allowFontScaling={false}
|
|
64
|
+
onPressIn={isPressable ? handlePressIn : undefined}
|
|
65
|
+
onPressOut={isPressable ? handlePressOut : undefined}
|
|
66
|
+
style={composedStyle}
|
|
67
|
+
children={children}
|
|
68
|
+
onPress={isPressable ? onPress : undefined}
|
|
69
|
+
ellipsizeMode={ellipsizeMode}
|
|
70
|
+
numberOfLines={numberOfLines}
|
|
71
|
+
adjustsFontSizeToFit={adjustsFontSizeToFit}
|
|
72
|
+
minimumFontScale={minimumFontScale}
|
|
73
|
+
{...restTextProps}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const styles = StyleSheet.create({
|
|
79
|
+
base: {
|
|
80
|
+
includeFontPadding: false,
|
|
81
|
+
textAlignVertical: 'center',
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export default memo(CustomText);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { useAppTheme } from '@/context/ThemeContext';
|
|
2
|
+
import { FONT_MAP, TYPOGRAPHY } from '@/theme/typography';
|
|
3
|
+
import { getHindiTextStyle, isHindiLanguage } from '@/utils/hindiText';
|
|
4
|
+
import React, { memo, useState, useMemo } from 'react';
|
|
5
|
+
import { Text, StyleSheet, View, ViewStyle } from 'react-native';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import BaseSkelton from '../skelton/BaseSkelton';
|
|
8
|
+
import { textLayout } from '../skelton/layouts';
|
|
9
|
+
import { ShimmerTextProps } from './types';
|
|
10
|
+
|
|
11
|
+
const ShimmerText = ({
|
|
12
|
+
weight = '400',
|
|
13
|
+
variant = 'body',
|
|
14
|
+
textColor,
|
|
15
|
+
style,
|
|
16
|
+
textAlign,
|
|
17
|
+
isLoading = false,
|
|
18
|
+
shimmerWidth = 100,
|
|
19
|
+
shimmerHeight = 30,
|
|
20
|
+
containerStyle,
|
|
21
|
+
onPress,
|
|
22
|
+
children,
|
|
23
|
+
ellipsizeMode,
|
|
24
|
+
numberOfLines,
|
|
25
|
+
}: ShimmerTextProps) => {
|
|
26
|
+
const { color } = useAppTheme();
|
|
27
|
+
const { i18n } = useTranslation();
|
|
28
|
+
const isHindi = isHindiLanguage(i18n.language);
|
|
29
|
+
const [pressed, setPressed] = useState<boolean>(false);
|
|
30
|
+
const opacity = pressed ? 0.8 : 1;
|
|
31
|
+
const isPressable = typeof onPress === 'function';
|
|
32
|
+
|
|
33
|
+
const handlePressIn = () => setPressed(true);
|
|
34
|
+
const handlePressOut = () => setPressed(false);
|
|
35
|
+
|
|
36
|
+
const typographyStyle = TYPOGRAPHY[variant];
|
|
37
|
+
|
|
38
|
+
const containerAlignStyle = useMemo((): ViewStyle => {
|
|
39
|
+
switch (textAlign) {
|
|
40
|
+
case 'center':
|
|
41
|
+
return { alignItems: 'center' };
|
|
42
|
+
case 'right':
|
|
43
|
+
return { alignItems: 'flex-end' };
|
|
44
|
+
default:
|
|
45
|
+
return { alignItems: 'flex-start' };
|
|
46
|
+
}
|
|
47
|
+
}, [textAlign]);
|
|
48
|
+
|
|
49
|
+
const flatStyle = StyleSheet.flatten(style) || {};
|
|
50
|
+
const {
|
|
51
|
+
margin,
|
|
52
|
+
marginTop,
|
|
53
|
+
marginBottom,
|
|
54
|
+
marginLeft,
|
|
55
|
+
marginRight,
|
|
56
|
+
marginHorizontal,
|
|
57
|
+
marginVertical,
|
|
58
|
+
padding,
|
|
59
|
+
paddingTop,
|
|
60
|
+
paddingBottom,
|
|
61
|
+
paddingLeft,
|
|
62
|
+
paddingRight,
|
|
63
|
+
paddingHorizontal,
|
|
64
|
+
paddingVertical,
|
|
65
|
+
alignSelf,
|
|
66
|
+
flex,
|
|
67
|
+
flexGrow,
|
|
68
|
+
flexShrink,
|
|
69
|
+
width,
|
|
70
|
+
...textOnlyStyle
|
|
71
|
+
} = flatStyle;
|
|
72
|
+
|
|
73
|
+
const positioningStyle: ViewStyle = {
|
|
74
|
+
margin,
|
|
75
|
+
marginTop,
|
|
76
|
+
marginBottom,
|
|
77
|
+
marginLeft,
|
|
78
|
+
marginRight,
|
|
79
|
+
marginHorizontal,
|
|
80
|
+
marginVertical,
|
|
81
|
+
padding,
|
|
82
|
+
paddingTop,
|
|
83
|
+
paddingBottom,
|
|
84
|
+
paddingLeft,
|
|
85
|
+
paddingRight,
|
|
86
|
+
paddingHorizontal,
|
|
87
|
+
paddingVertical,
|
|
88
|
+
alignSelf,
|
|
89
|
+
flex,
|
|
90
|
+
flexGrow,
|
|
91
|
+
flexShrink,
|
|
92
|
+
width,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
Object.keys(positioningStyle).forEach(key => {
|
|
96
|
+
if (positioningStyle[key as keyof ViewStyle] === undefined) {
|
|
97
|
+
delete positioningStyle[key as keyof ViewStyle];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const textStyle = useMemo(() => {
|
|
102
|
+
const base = [
|
|
103
|
+
styles.base,
|
|
104
|
+
typographyStyle,
|
|
105
|
+
{
|
|
106
|
+
fontFamily: FONT_MAP[weight],
|
|
107
|
+
opacity: opacity,
|
|
108
|
+
color: textColor || color.text_primary,
|
|
109
|
+
textAlign: textAlign,
|
|
110
|
+
},
|
|
111
|
+
textOnlyStyle,
|
|
112
|
+
];
|
|
113
|
+
if (!isHindi) {
|
|
114
|
+
return base;
|
|
115
|
+
}
|
|
116
|
+
return [...base, getHindiTextStyle(base)];
|
|
117
|
+
}, [
|
|
118
|
+
typographyStyle,
|
|
119
|
+
weight,
|
|
120
|
+
opacity,
|
|
121
|
+
textColor,
|
|
122
|
+
color.text_primary,
|
|
123
|
+
textAlign,
|
|
124
|
+
textOnlyStyle,
|
|
125
|
+
isHindi,
|
|
126
|
+
]);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<View style={[containerAlignStyle, positioningStyle, containerStyle]}>
|
|
130
|
+
<BaseSkelton
|
|
131
|
+
isLoading={isLoading}
|
|
132
|
+
layout={textLayout({
|
|
133
|
+
width: shimmerWidth,
|
|
134
|
+
height: shimmerHeight,
|
|
135
|
+
})}
|
|
136
|
+
>
|
|
137
|
+
<Text
|
|
138
|
+
allowFontScaling={false}
|
|
139
|
+
onPressIn={isPressable ? handlePressIn : undefined}
|
|
140
|
+
onPressOut={isPressable ? handlePressOut : undefined}
|
|
141
|
+
style={textStyle}
|
|
142
|
+
onPress={isPressable ? onPress : undefined}
|
|
143
|
+
children={children}
|
|
144
|
+
ellipsizeMode={ellipsizeMode}
|
|
145
|
+
numberOfLines={numberOfLines}
|
|
146
|
+
/>
|
|
147
|
+
</BaseSkelton>
|
|
148
|
+
</View>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const styles = StyleSheet.create({
|
|
153
|
+
base: {
|
|
154
|
+
includeFontPadding: false,
|
|
155
|
+
textAlignVertical: 'center',
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
export default memo(ShimmerText);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FontWeight, TextVariant } from '@/theme/typography';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { StyleProp, TextProps, TextStyle, ViewStyle } from 'react-native';
|
|
4
|
+
|
|
5
|
+
export type EllipsizeMode = TextProps['ellipsizeMode'];
|
|
6
|
+
export type TextAlignType = 'auto' | 'left' | 'right' | 'center' | 'justify';
|
|
7
|
+
|
|
8
|
+
export interface CustomTextProps {
|
|
9
|
+
weight?: FontWeight;
|
|
10
|
+
variant?: TextVariant;
|
|
11
|
+
textColor?: string;
|
|
12
|
+
textAlign?: TextAlignType;
|
|
13
|
+
style?: StyleProp<TextStyle>;
|
|
14
|
+
ellipsizeMode?: EllipsizeMode;
|
|
15
|
+
numberOfLines?: number;
|
|
16
|
+
adjustsFontSizeToFit?: boolean;
|
|
17
|
+
minimumFontScale?: number;
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
onPress?: () => void;
|
|
20
|
+
restTextProps?: Omit<
|
|
21
|
+
TextProps,
|
|
22
|
+
| 'style'
|
|
23
|
+
| 'onPress'
|
|
24
|
+
| 'onPressIn'
|
|
25
|
+
| 'onPressOut'
|
|
26
|
+
| 'children'
|
|
27
|
+
| 'ellipsizeMode'
|
|
28
|
+
| 'numberOfLines'
|
|
29
|
+
| 'allowFontScaling'
|
|
30
|
+
| 'adjustsFontSizeToFit'
|
|
31
|
+
| 'minimumFontScale'
|
|
32
|
+
>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ShimmerTextProps extends CustomTextProps {
|
|
36
|
+
isLoading?: boolean;
|
|
37
|
+
shimmerWidth?: number;
|
|
38
|
+
shimmerHeight?: number;
|
|
39
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Dimensions, PixelRatio, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export const AppDimensions = {
|
|
4
|
+
screenWidth: Dimensions.get('screen').width,
|
|
5
|
+
screenHeight: Dimensions.get('screen').height,
|
|
6
|
+
windowWidth: Dimensions.get('window').width,
|
|
7
|
+
windowHeight: Dimensions.get('window').height,
|
|
8
|
+
pixelRatio: PixelRatio.get(),
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export const isIOS = Platform.OS === 'ios';
|
|
12
|
+
export const isAndroid = Platform.OS === 'android';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
useCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import NetInfo, { type NetInfoState } from '@react-native-community/netinfo';
|
|
12
|
+
import { useTranslation } from 'react-i18next';
|
|
13
|
+
import { setupOnlineManager } from '@/services/network';
|
|
14
|
+
import { ErrorToast } from '@/services/toast';
|
|
15
|
+
|
|
16
|
+
type NetworkContextValue = {
|
|
17
|
+
isConnected: boolean;
|
|
18
|
+
isOffline: boolean;
|
|
19
|
+
isHydrated: boolean;
|
|
20
|
+
refresh: () => Promise<boolean>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const NetworkContext = createContext<NetworkContextValue | null>(null);
|
|
24
|
+
|
|
25
|
+
const resolveOnline = (state: NetInfoState): boolean =>
|
|
26
|
+
state.isConnected === true && state.isInternetReachable !== false;
|
|
27
|
+
|
|
28
|
+
type Props = {
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const NetworkProvider = ({ children }: Props) => {
|
|
33
|
+
const { t } = useTranslation();
|
|
34
|
+
const [isConnected, setIsConnected] = useState(true);
|
|
35
|
+
const [isHydrated, setIsHydrated] = useState(false);
|
|
36
|
+
const previousOnlineRef = useRef<boolean | null>(null);
|
|
37
|
+
const toastShownForOfflineRef = useRef(false);
|
|
38
|
+
|
|
39
|
+
const applyState = useCallback(
|
|
40
|
+
(state: NetInfoState) => {
|
|
41
|
+
const online = resolveOnline(state);
|
|
42
|
+
setIsConnected(online);
|
|
43
|
+
setIsHydrated(true);
|
|
44
|
+
|
|
45
|
+
const wasOnline = previousOnlineRef.current;
|
|
46
|
+
previousOnlineRef.current = online;
|
|
47
|
+
|
|
48
|
+
// Toast on cold-start offline, and again only when transitioning online → offline.
|
|
49
|
+
const shouldToast =
|
|
50
|
+
(!online && wasOnline === null) || (!online && wasOnline === true);
|
|
51
|
+
|
|
52
|
+
if (shouldToast && !toastShownForOfflineRef.current) {
|
|
53
|
+
toastShownForOfflineRef.current = true;
|
|
54
|
+
ErrorToast({
|
|
55
|
+
title: t('network.unavailableTitle'),
|
|
56
|
+
message: t('network.unavailableMessage'),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (online) {
|
|
61
|
+
toastShownForOfflineRef.current = false;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
[t],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
setupOnlineManager();
|
|
69
|
+
const unsubscribeNetInfo = NetInfo.addEventListener(applyState);
|
|
70
|
+
return () => {
|
|
71
|
+
unsubscribeNetInfo();
|
|
72
|
+
};
|
|
73
|
+
}, [applyState]);
|
|
74
|
+
|
|
75
|
+
// NetInfo.refresh() forces a new check and notifies listeners.
|
|
76
|
+
const refresh = useCallback(async () => {
|
|
77
|
+
const state = await NetInfo.refresh();
|
|
78
|
+
return resolveOnline(state);
|
|
79
|
+
}, []);
|
|
80
|
+
|
|
81
|
+
const value = useMemo<NetworkContextValue>(
|
|
82
|
+
() => ({
|
|
83
|
+
isConnected,
|
|
84
|
+
isOffline: !isConnected,
|
|
85
|
+
isHydrated,
|
|
86
|
+
refresh,
|
|
87
|
+
}),
|
|
88
|
+
[isConnected, isHydrated, refresh],
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<NetworkContext.Provider value={value}>{children}</NetworkContext.Provider>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const useNetwork = (): NetworkContextValue => {
|
|
97
|
+
const context = useContext(NetworkContext);
|
|
98
|
+
if (!context) {
|
|
99
|
+
throw new Error('useNetwork must be used within NetworkProvider');
|
|
100
|
+
}
|
|
101
|
+
return context;
|
|
102
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { dark, light } from '@/theme';
|
|
2
|
+
import React, {
|
|
3
|
+
createContext,
|
|
4
|
+
useContext,
|
|
5
|
+
useMemo,
|
|
6
|
+
ReactNode,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { useColorScheme } from 'react-native';
|
|
10
|
+
|
|
11
|
+
export type ThemeMode = 'system' | 'light' | 'dark';
|
|
12
|
+
export type AppTheme = typeof light;
|
|
13
|
+
|
|
14
|
+
interface ThemeContextValue {
|
|
15
|
+
theme: AppTheme;
|
|
16
|
+
mode: ThemeMode;
|
|
17
|
+
setMode: (mode: ThemeMode) => void;
|
|
18
|
+
color: AppTheme['color'];
|
|
19
|
+
icon: AppTheme['icon'];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const ThemeContext = createContext<ThemeContextValue>({
|
|
23
|
+
theme: light,
|
|
24
|
+
color: light.color,
|
|
25
|
+
icon: light.icon,
|
|
26
|
+
mode: 'system',
|
|
27
|
+
setMode: () => {},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const ThemeProvider = ({ children }: { children: ReactNode }) => {
|
|
31
|
+
const systemScheme = useColorScheme();
|
|
32
|
+
const [mode, setMode] = useState<ThemeMode>('system');
|
|
33
|
+
|
|
34
|
+
const resolvedTheme = useMemo<AppTheme>(() => {
|
|
35
|
+
if (mode === 'dark') return dark;
|
|
36
|
+
if (mode === 'light') return light;
|
|
37
|
+
return systemScheme === 'dark' ? dark : light;
|
|
38
|
+
}, [mode, systemScheme]);
|
|
39
|
+
|
|
40
|
+
const value = useMemo(
|
|
41
|
+
() => ({
|
|
42
|
+
theme: resolvedTheme,
|
|
43
|
+
mode,
|
|
44
|
+
setMode,
|
|
45
|
+
color: resolvedTheme.color,
|
|
46
|
+
icon: resolvedTheme.icon,
|
|
47
|
+
}),
|
|
48
|
+
[resolvedTheme, mode],
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const useAppTheme = () => useContext(ThemeContext);
|