@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,76 +1,101 @@
|
|
|
1
|
-
import React, { useState } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { KeyboardAvoidingView, Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
|
|
3
|
+
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
4
|
+
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
5
|
+
import { RouteProp } from '@react-navigation/native';
|
|
6
|
+
|
|
7
|
+
// Types
|
|
8
|
+
import { AppStackParams } from '../navigation/AppStackParams';
|
|
9
|
+
|
|
10
|
+
// Hooks / state
|
|
11
|
+
import { useTheme } from '../hooks/ThemeContext';
|
|
12
|
+
import { useAppDispatch } from '../redux/store';
|
|
13
|
+
import { setCredentials } from '../redux/slices/authSlice';
|
|
14
|
+
|
|
15
|
+
// Helpers / constants
|
|
16
|
+
import { showSnackbar } from '../helper/common-functions';
|
|
17
|
+
import { isIOS } from '../helper/utility-functions';
|
|
18
|
+
import { Typography } from '../helper/typography';
|
|
19
|
+
import { horizontalScale, moderateScale, verticalScale } from '../helper/matrics';
|
|
20
|
+
import { AppString } from '../../constants/AppString';
|
|
16
21
|
|
|
17
22
|
type Props = {
|
|
18
|
-
navigation: NativeStackNavigationProp<AppStackParams,
|
|
19
|
-
route: RouteProp<AppStackParams,
|
|
23
|
+
navigation: NativeStackNavigationProp<AppStackParams, 'LoginScreen'>;
|
|
24
|
+
route: RouteProp<AppStackParams, 'LoginScreen'>;
|
|
20
25
|
};
|
|
21
26
|
|
|
22
27
|
const LoginScreen = ({ navigation }: Props) => {
|
|
23
28
|
const { theme } = useTheme();
|
|
24
29
|
const dispatch = useAppDispatch();
|
|
25
|
-
const [email, setEmail] = useState(
|
|
26
|
-
const [password, setPassword] = useState(
|
|
30
|
+
const [email, setEmail] = useState('');
|
|
31
|
+
const [password, setPassword] = useState('');
|
|
32
|
+
|
|
33
|
+
const inputStyle = [
|
|
34
|
+
styles.input,
|
|
35
|
+
Typography.body1,
|
|
36
|
+
{ backgroundColor: theme.card, borderColor: theme.border, color: theme.text },
|
|
37
|
+
];
|
|
27
38
|
|
|
28
39
|
const onLogin = () => {
|
|
29
|
-
//
|
|
40
|
+
// Demo only: stores dummy credentials. With a real backend, call the
|
|
41
|
+
// mutation instead:
|
|
42
|
+
// const { mutate: login, isPending } = useLogin();
|
|
43
|
+
// login({ email, password }, {
|
|
44
|
+
// onSuccess: res => dispatch(setCredentials(res)),
|
|
45
|
+
// onError: err => showErrorSnackbar(getErrorMessage(err)),
|
|
46
|
+
// });
|
|
30
47
|
dispatch(
|
|
31
48
|
setCredentials({
|
|
32
|
-
user: { id:
|
|
33
|
-
accessToken:
|
|
49
|
+
user: { id: '1', name: 'Demo User', email: email || 'demo@local' },
|
|
50
|
+
accessToken: 'dummy-access-token-123',
|
|
34
51
|
}),
|
|
35
52
|
);
|
|
36
|
-
|
|
53
|
+
showSnackbar(AppString.loginSuccess);
|
|
54
|
+
navigation.reset({ index: 0, routes: [{ name: 'HomeScreen' }] });
|
|
37
55
|
};
|
|
38
56
|
|
|
39
57
|
return (
|
|
40
|
-
<SafeAreaView style={{
|
|
41
|
-
<
|
|
42
|
-
<Text style={[styles.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
<SafeAreaView style={[styles.safeArea, { backgroundColor: theme.background }]}>
|
|
59
|
+
<KeyboardAvoidingView behavior={isIOS ? 'padding' : undefined} style={styles.container}>
|
|
60
|
+
<Text style={[Typography.title1, styles.center, { color: theme.text }]}>
|
|
61
|
+
{AppString.welcomeBack}
|
|
62
|
+
</Text>
|
|
63
|
+
<Text style={[Typography.body2, styles.center, styles.subtitle, { color: theme.muted }]}>
|
|
64
|
+
{AppString.signInToContinue}
|
|
65
|
+
</Text>
|
|
66
|
+
|
|
67
|
+
<View style={styles.fields}>
|
|
68
|
+
<TextInput
|
|
69
|
+
placeholder={AppString.email}
|
|
70
|
+
placeholderTextColor={theme.muted}
|
|
71
|
+
style={inputStyle}
|
|
72
|
+
value={email}
|
|
73
|
+
onChangeText={setEmail}
|
|
74
|
+
keyboardType="email-address"
|
|
75
|
+
autoCapitalize="none"
|
|
76
|
+
autoComplete="email"
|
|
77
|
+
/>
|
|
78
|
+
<TextInput
|
|
79
|
+
placeholder={AppString.password}
|
|
80
|
+
placeholderTextColor={theme.muted}
|
|
81
|
+
style={inputStyle}
|
|
82
|
+
value={password}
|
|
83
|
+
onChangeText={setPassword}
|
|
84
|
+
secureTextEntry
|
|
85
|
+
autoComplete="password"
|
|
86
|
+
/>
|
|
87
|
+
</View>
|
|
66
88
|
|
|
67
|
-
<
|
|
68
|
-
style={[styles.button, { backgroundColor: theme.primary }]}
|
|
89
|
+
<Pressable
|
|
69
90
|
onPress={onLogin}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
91
|
+
accessibilityRole="button"
|
|
92
|
+
style={({ pressed }) => [
|
|
93
|
+
styles.button,
|
|
94
|
+
{ backgroundColor: theme.primary, opacity: pressed ? 0.8 : 1 },
|
|
95
|
+
]}>
|
|
96
|
+
<Text style={[Typography.headline, { color: theme.onPrimary }]}>{AppString.login}</Text>
|
|
97
|
+
</Pressable>
|
|
98
|
+
</KeyboardAvoidingView>
|
|
74
99
|
</SafeAreaView>
|
|
75
100
|
);
|
|
76
101
|
};
|
|
@@ -78,28 +103,35 @@ const LoginScreen = ({ navigation }: Props) => {
|
|
|
78
103
|
export default LoginScreen;
|
|
79
104
|
|
|
80
105
|
const styles = StyleSheet.create({
|
|
106
|
+
safeArea: {
|
|
107
|
+
flex: 1,
|
|
108
|
+
},
|
|
81
109
|
container: {
|
|
82
110
|
flex: 1,
|
|
83
|
-
justifyContent:
|
|
84
|
-
|
|
111
|
+
justifyContent: 'center',
|
|
112
|
+
paddingHorizontal: horizontalScale(24),
|
|
113
|
+
},
|
|
114
|
+
center: {
|
|
115
|
+
textAlign: 'center',
|
|
116
|
+
},
|
|
117
|
+
subtitle: {
|
|
118
|
+
marginTop: verticalScale(8),
|
|
119
|
+
marginBottom: verticalScale(32),
|
|
85
120
|
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
fontWeight: "600",
|
|
89
|
-
marginBottom: 24,
|
|
90
|
-
textAlign: "center",
|
|
121
|
+
fields: {
|
|
122
|
+
gap: moderateScale(12),
|
|
91
123
|
},
|
|
92
124
|
input: {
|
|
93
125
|
height: 48,
|
|
94
|
-
borderRadius:
|
|
95
|
-
|
|
96
|
-
|
|
126
|
+
borderRadius: moderateScale(12),
|
|
127
|
+
borderWidth: 1,
|
|
128
|
+
paddingHorizontal: horizontalScale(16),
|
|
97
129
|
},
|
|
98
130
|
button: {
|
|
99
131
|
height: 48,
|
|
100
|
-
borderRadius:
|
|
101
|
-
alignItems:
|
|
102
|
-
justifyContent:
|
|
103
|
-
marginTop:
|
|
132
|
+
borderRadius: moderateScale(12),
|
|
133
|
+
alignItems: 'center',
|
|
134
|
+
justifyContent: 'center',
|
|
135
|
+
marginTop: verticalScale(24),
|
|
104
136
|
},
|
|
105
137
|
});
|
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Text, View
|
|
3
|
-
import { NativeStackNavigationProp } from
|
|
4
|
-
import { RouteProp } from
|
|
5
|
-
import { AppStackParams } from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { ActivityIndicator, StyleSheet, Text, View } from 'react-native';
|
|
3
|
+
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
4
|
+
import { RouteProp } from '@react-navigation/native';
|
|
5
|
+
import { AppStackParams } from '../navigation/AppStackParams';
|
|
6
|
+
import { useAppSelector } from '../redux/store';
|
|
7
|
+
import { selectAccessToken } from '../redux/slices/authSlice';
|
|
8
|
+
import { useTheme } from '../hooks/ThemeContext';
|
|
9
|
+
import { Typography } from '../helper/typography';
|
|
10
|
+
import { verticalScale } from '../helper/matrics';
|
|
11
|
+
import { name as appName } from '../../app.json';
|
|
8
12
|
|
|
9
|
-
import { selectAccessToken } from "../redux/slices/authSlice";
|
|
10
13
|
type Props = {
|
|
11
|
-
navigation: NativeStackNavigationProp<
|
|
12
|
-
|
|
13
|
-
"SplashScreen",
|
|
14
|
-
"SplashScreen"
|
|
15
|
-
>;
|
|
16
|
-
route: RouteProp<AppStackParams, "SplashScreen">;
|
|
14
|
+
navigation: NativeStackNavigationProp<AppStackParams, 'SplashScreen'>;
|
|
15
|
+
route: RouteProp<AppStackParams, 'SplashScreen'>;
|
|
17
16
|
};
|
|
18
17
|
|
|
18
|
+
const SPLASH_DELAY_MS = 800;
|
|
19
|
+
|
|
19
20
|
const SplashScreen = ({ navigation }: Props) => {
|
|
20
21
|
const accessToken = useAppSelector(selectAccessToken);
|
|
22
|
+
const { theme } = useTheme();
|
|
21
23
|
|
|
22
24
|
useEffect(() => {
|
|
23
|
-
setTimeout(() => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}, [accessToken]);
|
|
25
|
+
const timer = setTimeout(() => {
|
|
26
|
+
navigation.reset({
|
|
27
|
+
index: 0,
|
|
28
|
+
routes: [{ name: accessToken ? 'HomeScreen' : 'LoginScreen' }],
|
|
29
|
+
});
|
|
30
|
+
}, SPLASH_DELAY_MS);
|
|
31
|
+
return () => clearTimeout(timer);
|
|
32
|
+
}, [accessToken, navigation]);
|
|
33
|
+
|
|
31
34
|
return (
|
|
32
|
-
<View style={styles.container}>
|
|
33
|
-
<Text>
|
|
35
|
+
<View style={[styles.container, { backgroundColor: theme.background }]}>
|
|
36
|
+
<Text style={[Typography.title1, { color: theme.text }]}>{appName}</Text>
|
|
37
|
+
<ActivityIndicator style={styles.loader} color={theme.primary} />
|
|
34
38
|
</View>
|
|
35
39
|
);
|
|
36
40
|
};
|
|
@@ -38,5 +42,12 @@ const SplashScreen = ({ navigation }: Props) => {
|
|
|
38
42
|
export default SplashScreen;
|
|
39
43
|
|
|
40
44
|
const styles = StyleSheet.create({
|
|
41
|
-
container: {
|
|
45
|
+
container: {
|
|
46
|
+
flex: 1,
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
justifyContent: 'center',
|
|
49
|
+
},
|
|
50
|
+
loader: {
|
|
51
|
+
marginTop: verticalScale(24),
|
|
52
|
+
},
|
|
42
53
|
});
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
card:
|
|
1
|
+
import type { ThemeType } from './index';
|
|
2
|
+
|
|
3
|
+
/** Dark theme colors. Must have the same keys as lightTheme.ts. */
|
|
4
|
+
export const darkTheme: ThemeType = {
|
|
5
|
+
background: '#000000',
|
|
6
|
+
card: '#18181B',
|
|
7
|
+
text: '#FFFFFF',
|
|
8
|
+
muted: '#A1A1AA',
|
|
9
|
+
border: '#27272A',
|
|
10
|
+
primary: '#4045EF',
|
|
11
|
+
onPrimary: '#FFFFFF',
|
|
12
|
+
secondary: '#1A1A1A',
|
|
13
|
+
error: '#F87171',
|
|
7
14
|
};
|
|
@@ -2,8 +2,9 @@ import { lightTheme } from './lightTheme';
|
|
|
2
2
|
import { darkTheme } from './darkTheme';
|
|
3
3
|
|
|
4
4
|
export type ThemeType = typeof lightTheme;
|
|
5
|
+
export type ThemeMode = 'light' | 'dark';
|
|
5
6
|
|
|
6
|
-
export const themes = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export const themes: Record<ThemeMode, ThemeType> = {
|
|
8
|
+
light: lightTheme,
|
|
9
|
+
dark: darkTheme,
|
|
9
10
|
};
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Light theme colors.
|
|
3
|
+
* Adding a token? Add it to darkTheme.ts too (same keys).
|
|
4
|
+
*/
|
|
1
5
|
export const lightTheme = {
|
|
2
|
-
background:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
background: '#FFFFFF',
|
|
7
|
+
card: '#F4F4F5',
|
|
8
|
+
text: '#000000',
|
|
9
|
+
muted: '#71717A',
|
|
10
|
+
border: '#E4E4E7',
|
|
11
|
+
primary: '#4045EF',
|
|
12
|
+
onPrimary: '#FFFFFF',
|
|
13
|
+
secondary: '#F4F4F4',
|
|
14
|
+
error: '#DC2626',
|
|
7
15
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export NODE_BINARY=/opt/homebrew/Cellar/node/24.1.0/bin/node
|