@umang-thakkar/base-template 1.1.1 → 1.2.0
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/README.md +40 -282
- package/package.json +11 -2
- package/template/.eslintrc +16 -46
- package/template/.prettierrc.js +8 -0
- package/template/App.tsx +11 -15
- package/template/Main.tsx +29 -5
- package/template/__mocks__/react-native-mmkv.ts +59 -0
- package/template/__tests__/App.test.tsx +6 -1
- package/template/__tests__/helpers.test.ts +43 -0
- package/template/babel.config.js +2 -1
- package/template/constants/API_Routes.ts +19 -0
- package/template/constants/AppConstants.tsx +1 -1
- package/template/constants/AppString.ts +36 -0
- package/template/constants/StoragePreferences.ts +120 -57
- package/template/jest.config.js +5 -0
- package/template/jest.setup.js +5 -0
- package/template/package.json +4 -4
- package/template/src/api/AxiosActions.ts +65 -28
- package/template/src/api/AxiosClient.ts +13 -7
- package/template/src/api/queries.ts +59 -29
- package/template/src/api/service.ts +23 -9
- package/template/src/components/ErrorBoundary.tsx +27 -31
- package/template/src/components/SnackbarHost.tsx +86 -0
- package/template/src/helper/colors.ts +22 -22
- package/template/src/helper/common-functions.ts +56 -10
- package/template/src/helper/matrics.ts +30 -0
- package/template/src/helper/navigation-service.ts +21 -24
- package/template/src/helper/snackbar.ts +41 -0
- package/template/src/helper/typography.ts +2 -2
- package/template/src/helper/utility-functions.ts +41 -69
- package/template/src/hooks/ThemeContext.tsx +60 -30
- package/template/src/hooks/usePaginatedAPI.ts +96 -0
- package/template/src/navigation/AppStack.tsx +36 -27
- package/template/src/navigation/screens.ts +17 -11
- package/template/src/redux/slice.ts +17 -12
- package/template/src/redux/slices/authSlice.ts +11 -14
- package/template/src/redux/store.ts +14 -10
- package/template/src/redux/types.d.ts +40 -19
- package/template/src/screens/HomeScreen.tsx +103 -29
- package/template/src/screens/LoginScreen.tsx +101 -69
- package/template/src/screens/SplashScreen.tsx +36 -25
- package/template/src/theme/darkTheme.ts +13 -6
- package/template/src/theme/index.ts +4 -3
- package/template/src/theme/lightTheme.ts +13 -5
- package/template/ios/.xcode.env.local +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { ReactNode, ErrorInfo } from
|
|
2
|
-
import { View, Text, StyleSheet, TouchableOpacity } from
|
|
1
|
+
import React, { ReactNode, ErrorInfo } from 'react';
|
|
2
|
+
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
|
|
3
3
|
|
|
4
4
|
interface Props {
|
|
5
5
|
children: ReactNode;
|
|
@@ -26,14 +26,14 @@ export class ErrorBoundary extends React.Component<Props, State> {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
static getDerivedStateFromError(
|
|
29
|
+
static getDerivedStateFromError(): Partial<State> {
|
|
30
30
|
return { hasError: true };
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
34
34
|
// Log error details for debugging
|
|
35
|
-
console.error(
|
|
36
|
-
console.error(
|
|
35
|
+
console.error('ErrorBoundary caught an error:', error);
|
|
36
|
+
console.error('Error Info:', errorInfo);
|
|
37
37
|
|
|
38
38
|
this.setState({
|
|
39
39
|
error,
|
|
@@ -62,13 +62,9 @@ export class ErrorBoundary extends React.Component<Props, State> {
|
|
|
62
62
|
{__DEV__ && this.state.error && (
|
|
63
63
|
<View style={styles.errorDetails}>
|
|
64
64
|
<Text style={styles.errorTitle}>Error Details:</Text>
|
|
65
|
-
<Text style={styles.errorText}>
|
|
66
|
-
{this.state.error.toString()}
|
|
67
|
-
</Text>
|
|
65
|
+
<Text style={styles.errorText}>{this.state.error.toString()}</Text>
|
|
68
66
|
{this.state.errorInfo && (
|
|
69
|
-
<Text style={styles.stackTrace}>
|
|
70
|
-
{this.state.errorInfo.componentStack}
|
|
71
|
-
</Text>
|
|
67
|
+
<Text style={styles.stackTrace}>{this.state.errorInfo.componentStack}</Text>
|
|
72
68
|
)}
|
|
73
69
|
</View>
|
|
74
70
|
)}
|
|
@@ -88,17 +84,17 @@ export class ErrorBoundary extends React.Component<Props, State> {
|
|
|
88
84
|
const styles = StyleSheet.create({
|
|
89
85
|
container: {
|
|
90
86
|
flex: 1,
|
|
91
|
-
backgroundColor:
|
|
92
|
-
justifyContent:
|
|
93
|
-
alignItems:
|
|
87
|
+
backgroundColor: '#f5f5f5',
|
|
88
|
+
justifyContent: 'center',
|
|
89
|
+
alignItems: 'center',
|
|
94
90
|
padding: 20,
|
|
95
91
|
},
|
|
96
92
|
content: {
|
|
97
|
-
backgroundColor:
|
|
93
|
+
backgroundColor: '#ffffff',
|
|
98
94
|
borderRadius: 12,
|
|
99
95
|
padding: 24,
|
|
100
|
-
alignItems:
|
|
101
|
-
shadowColor:
|
|
96
|
+
alignItems: 'center',
|
|
97
|
+
shadowColor: '#000',
|
|
102
98
|
shadowOffset: { width: 0, height: 2 },
|
|
103
99
|
shadowOpacity: 0.1,
|
|
104
100
|
shadowRadius: 8,
|
|
@@ -106,49 +102,49 @@ const styles = StyleSheet.create({
|
|
|
106
102
|
},
|
|
107
103
|
title: {
|
|
108
104
|
fontSize: 20,
|
|
109
|
-
fontWeight:
|
|
110
|
-
color:
|
|
105
|
+
fontWeight: 'bold',
|
|
106
|
+
color: '#333333',
|
|
111
107
|
marginBottom: 12,
|
|
112
|
-
textAlign:
|
|
108
|
+
textAlign: 'center',
|
|
113
109
|
},
|
|
114
110
|
message: {
|
|
115
111
|
fontSize: 16,
|
|
116
|
-
color:
|
|
117
|
-
textAlign:
|
|
112
|
+
color: '#666666',
|
|
113
|
+
textAlign: 'center',
|
|
118
114
|
marginBottom: 20,
|
|
119
115
|
lineHeight: 22,
|
|
120
116
|
},
|
|
121
117
|
errorDetails: {
|
|
122
|
-
backgroundColor:
|
|
118
|
+
backgroundColor: '#ffe6e6',
|
|
123
119
|
borderRadius: 8,
|
|
124
120
|
padding: 12,
|
|
125
121
|
marginBottom: 20,
|
|
126
122
|
maxHeight: 200,
|
|
127
123
|
},
|
|
128
124
|
errorTitle: {
|
|
129
|
-
fontWeight:
|
|
130
|
-
color:
|
|
125
|
+
fontWeight: '600',
|
|
126
|
+
color: '#d32f2f',
|
|
131
127
|
marginBottom: 8,
|
|
132
128
|
},
|
|
133
129
|
errorText: {
|
|
134
|
-
color:
|
|
130
|
+
color: '#c62828',
|
|
135
131
|
fontSize: 12,
|
|
136
132
|
marginBottom: 8,
|
|
137
133
|
},
|
|
138
134
|
stackTrace: {
|
|
139
|
-
color:
|
|
135
|
+
color: '#c62828',
|
|
140
136
|
fontSize: 10,
|
|
141
|
-
fontFamily:
|
|
137
|
+
fontFamily: 'Courier New',
|
|
142
138
|
},
|
|
143
139
|
button: {
|
|
144
|
-
backgroundColor:
|
|
140
|
+
backgroundColor: '#4045EF',
|
|
145
141
|
paddingHorizontal: 32,
|
|
146
142
|
paddingVertical: 12,
|
|
147
143
|
borderRadius: 8,
|
|
148
144
|
},
|
|
149
145
|
buttonText: {
|
|
150
|
-
color:
|
|
146
|
+
color: '#ffffff',
|
|
151
147
|
fontSize: 16,
|
|
152
|
-
fontWeight:
|
|
148
|
+
fontWeight: '600',
|
|
153
149
|
},
|
|
154
150
|
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
3
|
+
import Animated, { FadeInDown, FadeOutDown } from 'react-native-reanimated';
|
|
4
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
5
|
+
import { subscribeSnackbar, type SnackbarMessage } from '../helper/snackbar';
|
|
6
|
+
import { useTheme } from '../hooks/ThemeContext';
|
|
7
|
+
import { Typography } from '../helper/typography';
|
|
8
|
+
import { horizontalScale, moderateScale, verticalScale } from '../helper/matrics';
|
|
9
|
+
import { colors } from '../helper/colors';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Renders messages sent with showSnackbar / showErrorSnackbar. Mounted once
|
|
13
|
+
* in App.tsx inside ThemeProvider; one message at a time, newest wins.
|
|
14
|
+
*/
|
|
15
|
+
const SnackbarHost = () => {
|
|
16
|
+
const insets = useSafeAreaInsets();
|
|
17
|
+
const { theme } = useTheme();
|
|
18
|
+
const [snack, setSnack] = useState<SnackbarMessage | null>(null);
|
|
19
|
+
|
|
20
|
+
useEffect(() => subscribeSnackbar(setSnack), []);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!snack) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const timer = setTimeout(() => setSnack(null), snack.duration);
|
|
27
|
+
return () => clearTimeout(timer);
|
|
28
|
+
}, [snack]);
|
|
29
|
+
|
|
30
|
+
const isError = snack?.type === 'error';
|
|
31
|
+
const backgroundColor = isError ? theme.error : theme.text;
|
|
32
|
+
const color = isError ? theme.onPrimary : theme.background;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<View
|
|
36
|
+
pointerEvents="box-none"
|
|
37
|
+
style={[styles.container, { paddingBottom: insets.bottom + verticalScale(16) }]}>
|
|
38
|
+
{snack ? (
|
|
39
|
+
<Animated.View key={snack.id} entering={FadeInDown} exiting={FadeOutDown}>
|
|
40
|
+
<Pressable
|
|
41
|
+
onPress={() => setSnack(null)}
|
|
42
|
+
accessibilityRole="alert"
|
|
43
|
+
accessibilityLiveRegion="polite"
|
|
44
|
+
style={[styles.snack, { backgroundColor }]}>
|
|
45
|
+
<Text style={[Typography.subhead, styles.title, { color }]}>{snack.title}</Text>
|
|
46
|
+
{snack.message ? (
|
|
47
|
+
<Text style={[Typography.footnote, styles.message, { color }]}>{snack.message}</Text>
|
|
48
|
+
) : null}
|
|
49
|
+
</Pressable>
|
|
50
|
+
</Animated.View>
|
|
51
|
+
) : null}
|
|
52
|
+
</View>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default SnackbarHost;
|
|
57
|
+
|
|
58
|
+
const styles = StyleSheet.create({
|
|
59
|
+
container: {
|
|
60
|
+
position: 'absolute',
|
|
61
|
+
left: 0,
|
|
62
|
+
right: 0,
|
|
63
|
+
bottom: 0,
|
|
64
|
+
paddingHorizontal: horizontalScale(16),
|
|
65
|
+
},
|
|
66
|
+
snack: {
|
|
67
|
+
width: '100%',
|
|
68
|
+
maxWidth: 560,
|
|
69
|
+
alignSelf: 'center',
|
|
70
|
+
borderRadius: moderateScale(12),
|
|
71
|
+
paddingHorizontal: horizontalScale(16),
|
|
72
|
+
paddingVertical: verticalScale(12),
|
|
73
|
+
elevation: 4,
|
|
74
|
+
shadowColor: colors.black,
|
|
75
|
+
shadowOffset: { width: 0, height: 2 },
|
|
76
|
+
shadowOpacity: 0.2,
|
|
77
|
+
shadowRadius: 6,
|
|
78
|
+
},
|
|
79
|
+
title: {
|
|
80
|
+
fontWeight: '600',
|
|
81
|
+
},
|
|
82
|
+
message: {
|
|
83
|
+
marginTop: verticalScale(2),
|
|
84
|
+
opacity: 0.8,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export const colors = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
2
|
+
grayColor: '#9B9B9B',
|
|
3
|
+
dividerColor: '#BDBDBD',
|
|
4
|
+
fieldColor: '#F5F5F5',
|
|
5
|
+
yellowColor: '#FDC60A',
|
|
6
|
+
navyBlue: '#3C5A99',
|
|
7
|
+
kashmir: '#5D6D7E',
|
|
8
|
+
orangeColor: '#E5634D',
|
|
9
|
+
blueColor: '#5DADE2',
|
|
10
|
+
pinkColor: '#A569BD',
|
|
11
|
+
pinkLightColor: '#FF5E80',
|
|
12
|
+
pinkDarkColor: '#F90030',
|
|
13
|
+
accentColor: '#4A90A4',
|
|
14
|
+
//App colors
|
|
15
|
+
whiteColor: '#FFFFFF',
|
|
16
|
+
purple: '#6739B7',
|
|
17
|
+
green: '#4BB543',
|
|
18
|
+
suvaGrey: '#909090',
|
|
19
|
+
airForceBlue: '#6687A5',
|
|
20
|
+
red: '#D73F5A',
|
|
21
|
+
lightGray: '#B3B3B3',
|
|
22
|
+
black: '#000000',
|
|
23
|
+
kashmirBlue: '#566A90',
|
|
24
24
|
};
|
|
@@ -1,19 +1,65 @@
|
|
|
1
|
-
import axios from
|
|
2
|
-
import { format, isValid, parseISO } from
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { format, isValid, parseISO } from 'date-fns';
|
|
3
|
+
import { AppString } from '../../constants/AppString';
|
|
4
|
+
import { pushSnackbar } from './snackbar';
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
// ---------- Feedback ----------
|
|
7
|
+
|
|
8
|
+
/** Neutral/success message at the bottom of the screen. */
|
|
9
|
+
export const showSnackbar = (title: string, message?: string) =>
|
|
10
|
+
pushSnackbar(title, { message, type: 'success' });
|
|
11
|
+
|
|
12
|
+
/** Error message. Pass the error's message, or nothing for the generic one. */
|
|
13
|
+
export const showErrorSnackbar = (message?: string) =>
|
|
14
|
+
pushSnackbar(message || AppString.somethingWentWrong, { type: 'error' });
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Best human-readable message from anything thrown by an API call:
|
|
18
|
+
* a backend error body ({ message }), an AxiosError, an Error or a string.
|
|
19
|
+
*/
|
|
20
|
+
export const getErrorMessage = (error: unknown): string => {
|
|
5
21
|
if (axios.isAxiosError(error)) {
|
|
6
22
|
return error.response?.data?.message || error.message;
|
|
7
23
|
}
|
|
8
|
-
|
|
24
|
+
if (error && typeof error === 'object' && 'message' in error) {
|
|
25
|
+
return String((error as { message: unknown }).message);
|
|
26
|
+
}
|
|
27
|
+
if (typeof error === 'string') {
|
|
28
|
+
return error;
|
|
29
|
+
}
|
|
30
|
+
return AppString.somethingWentWrong;
|
|
9
31
|
};
|
|
10
32
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
// ---------- Formatting ----------
|
|
34
|
+
|
|
35
|
+
/** 1234567 -> "1,234,567" */
|
|
36
|
+
export const formatWithComma = (value: number, locale = 'en-US') =>
|
|
37
|
+
new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(value);
|
|
38
|
+
|
|
39
|
+
/** 1234.5 -> "1,234.50" */
|
|
40
|
+
export const formatPrice = (value: number, locale = 'en-US') =>
|
|
41
|
+
new Intl.NumberFormat(locale, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(
|
|
42
|
+
value,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
/** ISO string -> formatted date (date-fns tokens), or null when invalid. */
|
|
46
|
+
export function toFormattedDate(dateString: string, formatStr: string): string | null {
|
|
47
|
+
if (!dateString) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
16
50
|
const date = parseISO(dateString);
|
|
17
|
-
if (!isValid(date))
|
|
51
|
+
if (!isValid(date)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
18
54
|
return format(date, formatStr);
|
|
19
55
|
}
|
|
56
|
+
|
|
57
|
+
// ---------- Payloads ----------
|
|
58
|
+
|
|
59
|
+
/** Drops null, undefined and empty-string values before sending a request body/params. */
|
|
60
|
+
export const cleanPayload = <T extends Record<string, unknown>>(payload: T): Partial<T> =>
|
|
61
|
+
Object.fromEntries(
|
|
62
|
+
Object.entries(payload).filter(
|
|
63
|
+
([, value]) => value !== null && value !== undefined && value !== '',
|
|
64
|
+
),
|
|
65
|
+
) as Partial<T>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Dimensions } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const { width, height } = Dimensions.get('window');
|
|
4
|
+
|
|
5
|
+
const guidelineBaseWidth: number = 390;
|
|
6
|
+
const guidelineBaseHeight: number = 844;
|
|
7
|
+
|
|
8
|
+
export const isTablet = width >= 768;
|
|
9
|
+
const tabletMaxWidth = 550;
|
|
10
|
+
const tabletMaxHeight = 900;
|
|
11
|
+
|
|
12
|
+
const effectiveWidth = isTablet ? Math.min(width, tabletMaxWidth) : width;
|
|
13
|
+
const effectiveHeight = isTablet ? Math.min(height, tabletMaxHeight) : height;
|
|
14
|
+
|
|
15
|
+
const horizontalScale = (size: number): number => (effectiveWidth / guidelineBaseWidth) * size;
|
|
16
|
+
|
|
17
|
+
const verticalScale = (size: number): number => (effectiveHeight / guidelineBaseHeight) * size;
|
|
18
|
+
|
|
19
|
+
const moderateScale = (size: number, factor: number = 0.5): number =>
|
|
20
|
+
size + (horizontalScale(size) - size) * factor;
|
|
21
|
+
|
|
22
|
+
const getResponsiveIconSize = (baseSize = 100) => {
|
|
23
|
+
const scaleFactor = Math.min(
|
|
24
|
+
effectiveWidth / guidelineBaseWidth,
|
|
25
|
+
effectiveHeight / guidelineBaseHeight,
|
|
26
|
+
);
|
|
27
|
+
return baseSize * scaleFactor;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { horizontalScale, verticalScale, moderateScale, getResponsiveIconSize };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// navigationService.ts
|
|
2
|
-
import * as React from
|
|
3
|
-
import { CommonActions, StackActions } from
|
|
4
|
-
import type { NavigationContainerRef } from
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { CommonActions, StackActions } from '@react-navigation/native';
|
|
4
|
+
import type { NavigationContainerRef } from '@react-navigation/native';
|
|
5
5
|
|
|
6
6
|
// Create a ref to hold navigation
|
|
7
7
|
export const navigationRef = React.createRef<NavigationContainerRef<any>>();
|
|
@@ -10,60 +10,57 @@ export const navigationRef = React.createRef<NavigationContainerRef<any>>();
|
|
|
10
10
|
* Navigate to a screen by name
|
|
11
11
|
*/
|
|
12
12
|
export function navigate(name: string, params?: object) {
|
|
13
|
-
|
|
13
|
+
navigationRef.current?.navigate(name, params);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Go back to the previous screen
|
|
18
18
|
*/
|
|
19
19
|
export function goBack() {
|
|
20
|
-
|
|
20
|
+
navigationRef.current?.goBack();
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Reset navigation with multiple routes
|
|
25
25
|
*/
|
|
26
|
-
export function navigateAndReset(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
routes,
|
|
34
|
-
})
|
|
35
|
-
);
|
|
26
|
+
export function navigateAndReset(routes: { name: string; params?: object }[] = [], index = 0) {
|
|
27
|
+
navigationRef.current?.dispatch(
|
|
28
|
+
CommonActions.reset({
|
|
29
|
+
index,
|
|
30
|
+
routes,
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
/**
|
|
39
36
|
* Reset navigation with a single route
|
|
40
37
|
*/
|
|
41
38
|
export function navigateAndSimpleReset(name: string, index = 0) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
navigationRef.current?.dispatch(
|
|
40
|
+
CommonActions.reset({
|
|
41
|
+
index,
|
|
42
|
+
routes: [{ name }],
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
/**
|
|
51
48
|
* Push a new screen on top of the stack
|
|
52
49
|
*/
|
|
53
50
|
export function push(name: string, params?: object) {
|
|
54
|
-
|
|
51
|
+
navigationRef.current?.dispatch(StackActions.push(name, params));
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
/**
|
|
58
55
|
* Pop the current screen
|
|
59
56
|
*/
|
|
60
57
|
export function pop(count: number = 1) {
|
|
61
|
-
|
|
58
|
+
navigationRef.current?.dispatch(StackActions.pop(count));
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
/**
|
|
65
62
|
* Pop to the top of the stack
|
|
66
63
|
*/
|
|
67
64
|
export function popToTop() {
|
|
68
|
-
|
|
65
|
+
navigationRef.current?.dispatch(StackActions.popToTop());
|
|
69
66
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny snackbar store. `showSnackbar` / `showErrorSnackbar` (re-exported from
|
|
3
|
+
* common-functions.ts) can be called from anywhere: screens, mutation
|
|
4
|
+
* callbacks, axios interceptors. <SnackbarHost /> in App.tsx renders them.
|
|
5
|
+
*/
|
|
6
|
+
export type SnackbarType = 'success' | 'error' | 'info';
|
|
7
|
+
|
|
8
|
+
export interface SnackbarMessage {
|
|
9
|
+
id: number;
|
|
10
|
+
title: string;
|
|
11
|
+
message?: string;
|
|
12
|
+
type: SnackbarType;
|
|
13
|
+
duration: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type Listener = (snack: SnackbarMessage) => void;
|
|
17
|
+
|
|
18
|
+
const DEFAULT_DURATION_MS = 3000;
|
|
19
|
+
const listeners = new Set<Listener>();
|
|
20
|
+
let nextId = 1;
|
|
21
|
+
|
|
22
|
+
export const subscribeSnackbar = (listener: Listener) => {
|
|
23
|
+
listeners.add(listener);
|
|
24
|
+
return () => {
|
|
25
|
+
listeners.delete(listener);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const pushSnackbar = (
|
|
30
|
+
title: string,
|
|
31
|
+
options: { message?: string; type?: SnackbarType; duration?: number } = {},
|
|
32
|
+
) => {
|
|
33
|
+
const snack: SnackbarMessage = {
|
|
34
|
+
id: nextId++,
|
|
35
|
+
title,
|
|
36
|
+
message: options.message,
|
|
37
|
+
type: options.type ?? 'info',
|
|
38
|
+
duration: options.duration ?? DEFAULT_DURATION_MS,
|
|
39
|
+
};
|
|
40
|
+
listeners.forEach(listener => listener(snack));
|
|
41
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StyleSheet } from 'react-native';
|
|
2
2
|
|
|
3
|
-
export const FontWeight
|
|
3
|
+
export const FontWeight = {
|
|
4
4
|
thin: '100',
|
|
5
5
|
ultraLight: '200',
|
|
6
6
|
light: '300',
|
|
@@ -10,7 +10,7 @@ export const FontWeight: any = {
|
|
|
10
10
|
bold: '700',
|
|
11
11
|
heavy: '800',
|
|
12
12
|
black: '900',
|
|
13
|
-
};
|
|
13
|
+
} as const;
|
|
14
14
|
|
|
15
15
|
export const Typography = StyleSheet.create({
|
|
16
16
|
header: {
|
|
@@ -1,85 +1,57 @@
|
|
|
1
1
|
// utils.ts
|
|
2
|
-
import { Dimensions, Platform, PixelRatio, Keyboard, Alert } from
|
|
3
|
-
const { width, height } = Dimensions.get("window");
|
|
2
|
+
import { Dimensions, Platform, PixelRatio, Keyboard, Alert } from 'react-native';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
export const deviceWidth = width;
|
|
7
|
-
export const deviceHeight = height;
|
|
4
|
+
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window');
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
export const isAndroid = Platform.OS ===
|
|
11
|
-
export const
|
|
6
|
+
export const isIOS = Platform.OS === 'ios';
|
|
7
|
+
export const isAndroid = Platform.OS === 'android';
|
|
8
|
+
export const deviceWidth = SCREEN_WIDTH;
|
|
9
|
+
export const deviceHeight = SCREEN_HEIGHT;
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
export function responsiveFontSize(size: number) {
|
|
15
|
-
const scale = width / 375; // base width: iPhone 11
|
|
16
|
-
const newSize = size * scale;
|
|
17
|
-
return Math.round(PixelRatio.roundToNearestPixel(newSize));
|
|
18
|
-
}
|
|
11
|
+
const scale = SCREEN_WIDTH / 390;
|
|
19
12
|
|
|
20
|
-
export const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
export const responsiveFontSize = (size: number): number => {
|
|
14
|
+
const newSize = size * scale;
|
|
15
|
+
if (isIOS) {
|
|
16
|
+
return Math.round(PixelRatio.roundToNearestPixel(newSize));
|
|
17
|
+
} else {
|
|
18
|
+
return Math.round(PixelRatio.roundToNearestPixel(newSize)) - 1;
|
|
19
|
+
}
|
|
27
20
|
};
|
|
28
21
|
|
|
29
|
-
export const
|
|
30
|
-
|
|
31
|
-
if (deviceWidth !== 414) {
|
|
32
|
-
let temp2 = (value / 414).toFixed(4); // 414 is a common base width (e.g., iPhone 11)
|
|
33
|
-
temp = PixelRatio.roundToNearestPixel(deviceWidth * Number(temp2));
|
|
34
|
-
}
|
|
35
|
-
return temp;
|
|
22
|
+
export const responsiveHeight = (height: number): number => {
|
|
23
|
+
return Math.round((SCREEN_HEIGHT / 844) * height);
|
|
36
24
|
};
|
|
37
25
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (width < 768) return "medium";
|
|
42
|
-
return "large";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Example: normalize size for both iOS/Android
|
|
46
|
-
export function normalize(size: number) {
|
|
47
|
-
const scale = width / 375;
|
|
48
|
-
const newSize = size * scale;
|
|
49
|
-
if (isIOS) {
|
|
50
|
-
return Math.round(PixelRatio.roundToNearestPixel(newSize));
|
|
51
|
-
} else {
|
|
52
|
-
return Math.round(PixelRatio.roundToNearestPixel(newSize)) - 2;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
26
|
+
export const responsiveWidth = (width: number): number => {
|
|
27
|
+
return Math.round((SCREEN_WIDTH / 390) * width);
|
|
28
|
+
};
|
|
55
29
|
|
|
56
30
|
export const hideKeyboard = () => {
|
|
57
|
-
|
|
31
|
+
Keyboard.dismiss();
|
|
58
32
|
};
|
|
59
33
|
|
|
60
34
|
export const showAlert = (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
35
|
+
title: string,
|
|
36
|
+
message: string,
|
|
37
|
+
settingsText = 'Open Settings',
|
|
38
|
+
rejectText = 'Reject',
|
|
39
|
+
onSettingsPress: () => void,
|
|
66
40
|
) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
41
|
+
Alert.alert(
|
|
42
|
+
title,
|
|
43
|
+
message,
|
|
44
|
+
[
|
|
45
|
+
{
|
|
46
|
+
text: settingsText,
|
|
47
|
+
onPress: onSettingsPress,
|
|
48
|
+
style: 'default',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
text: rejectText,
|
|
52
|
+
style: 'destructive',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
{ cancelable: false },
|
|
56
|
+
);
|
|
83
57
|
};
|
|
84
|
-
|
|
85
|
-
|