@umang-thakkar/base-template 1.1.2 → 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.
Files changed (45) hide show
  1. package/README.md +40 -304
  2. package/package.json +11 -2
  3. package/template/.eslintrc +16 -46
  4. package/template/.prettierrc.js +8 -0
  5. package/template/App.tsx +11 -15
  6. package/template/Main.tsx +29 -5
  7. package/template/__mocks__/react-native-mmkv.ts +4 -4
  8. package/template/__tests__/App.test.tsx +6 -1
  9. package/template/__tests__/helpers.test.ts +43 -0
  10. package/template/babel.config.js +2 -1
  11. package/template/constants/API_Routes.ts +19 -0
  12. package/template/constants/AppConstants.tsx +1 -1
  13. package/template/constants/AppString.ts +36 -0
  14. package/template/constants/StoragePreferences.ts +16 -31
  15. package/template/jest.config.js +5 -0
  16. package/template/jest.setup.js +5 -0
  17. package/template/package.json +2 -3
  18. package/template/src/api/AxiosActions.ts +65 -28
  19. package/template/src/api/AxiosClient.ts +13 -7
  20. package/template/src/api/queries.ts +59 -29
  21. package/template/src/api/service.ts +23 -9
  22. package/template/src/components/ErrorBoundary.tsx +27 -31
  23. package/template/src/components/SnackbarHost.tsx +86 -0
  24. package/template/src/helper/colors.ts +22 -22
  25. package/template/src/helper/common-functions.ts +56 -10
  26. package/template/src/helper/matrics.ts +4 -6
  27. package/template/src/helper/navigation-service.ts +21 -24
  28. package/template/src/helper/snackbar.ts +41 -0
  29. package/template/src/helper/typography.ts +2 -2
  30. package/template/src/helper/utility-functions.ts +10 -16
  31. package/template/src/hooks/ThemeContext.tsx +60 -30
  32. package/template/src/hooks/usePaginatedAPI.ts +96 -0
  33. package/template/src/navigation/AppStack.tsx +36 -27
  34. package/template/src/navigation/screens.ts +17 -11
  35. package/template/src/redux/slice.ts +17 -12
  36. package/template/src/redux/slices/authSlice.ts +11 -14
  37. package/template/src/redux/store.ts +13 -9
  38. package/template/src/redux/types.d.ts +40 -19
  39. package/template/src/screens/HomeScreen.tsx +103 -29
  40. package/template/src/screens/LoginScreen.tsx +101 -69
  41. package/template/src/screens/SplashScreen.tsx +36 -25
  42. package/template/src/theme/darkTheme.ts +13 -6
  43. package/template/src/theme/index.ts +4 -3
  44. package/template/src/theme/lightTheme.ts +13 -5
  45. package/template/ios/.xcode.env.local +0 -1
@@ -1,36 +1,40 @@
1
- import * as React from "react";
2
- import { Text, View, StyleSheet } 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 { useEffect } from "react";
7
- import { useAppSelector } from "../redux/store";
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
- AppStackParams,
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
- if (accessToken) {
25
- navigation.reset({ index: 0, routes: [{ name: "HomeScreen" }] });
26
- } else {
27
- navigation.reset({ index: 0, routes: [{ name: "LoginScreen" }] });
28
- }
29
- }, 800);
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>SplashScreen</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
- export const darkTheme = {
2
- background: "#000000",
3
- text: "#FFFFFF",
4
- primary: "#4045EF",
5
- secondary: "#1A1A1A",
6
- card: "#FFFF",
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
- light: lightTheme,
8
- dark: darkTheme,
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: "#FFFFFF",
3
- text: "#000000",
4
- primary: "#4045EF",
5
- secondary: "#F4F4F4",
6
- card: "#FFFF",
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