@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.
Files changed (45) hide show
  1. package/README.md +40 -282
  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 +59 -0
  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 +120 -57
  15. package/template/jest.config.js +5 -0
  16. package/template/jest.setup.js +5 -0
  17. package/template/package.json +4 -4
  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 +30 -0
  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 +41 -69
  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 +14 -10
  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,43 +1,73 @@
1
- import React, { createContext, useContext, useEffect, useState } from 'react';
1
+ import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
2
2
  import { Appearance } from 'react-native';
3
- import { themes, ThemeType } from '../theme';
3
+ import { themes, ThemeMode, ThemeType } from '../theme';
4
+ import { StorageKeys, StoragePreferences } from '../../constants/StoragePreferences';
4
5
 
5
- type ThemeMode = 'light' | 'dark';
6
+ /** What the user picked: a fixed mode, or follow the OS. */
7
+ export type ThemePreference = ThemeMode | 'system';
6
8
 
7
9
  interface ThemeContextProps {
8
- theme: ThemeType;
9
- mode: ThemeMode;
10
- toggleTheme: () => void;
10
+ /** Colors of the active theme. Use them in styles: `{ color: theme.text }`. */
11
+ theme: ThemeType;
12
+ /** The mode actually shown. */
13
+ mode: ThemeMode;
14
+ /** The user's choice, persisted in MMKV. */
15
+ preference: ThemePreference;
16
+ setPreference: (preference: ThemePreference) => void;
17
+ /** Switches between light and dark (pins the choice). */
18
+ toggleTheme: () => void;
11
19
  }
12
20
 
13
21
  const ThemeContext = createContext<ThemeContextProps | undefined>(undefined);
14
22
 
23
+ const readSystemMode = (): ThemeMode => (Appearance.getColorScheme() === 'dark' ? 'dark' : 'light');
24
+
25
+ const readStoredPreference = (): ThemePreference => {
26
+ const stored = StoragePreferences.getString(StorageKeys.THEME_MODE);
27
+ return stored === 'light' || stored === 'dark' ? stored : 'system';
28
+ };
29
+
15
30
  export const ThemeProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
16
- const systemColorScheme = Appearance.getColorScheme() as ThemeMode;
17
- const [mode, setMode] = useState<ThemeMode>(systemColorScheme || 'light');
18
-
19
- const toggleTheme = () => setMode(prev => (prev === 'light' ? 'dark' : 'light'));
20
-
21
- useEffect(() => {
22
- const listener = Appearance.addChangeListener(({ colorScheme }) => {
23
- if (colorScheme) {
24
- setMode(colorScheme as ThemeMode);
25
- }
26
- });
27
- return () => listener.remove();
28
- }, []);
29
-
30
- return (
31
- <ThemeContext.Provider value={{ theme: themes[mode], mode, toggleTheme }}>
32
- {children}
33
- </ThemeContext.Provider>
34
- );
31
+ const [systemMode, setSystemMode] = useState<ThemeMode>(readSystemMode);
32
+ // MMKV is synchronous, so the saved choice applies on the first frame.
33
+ const [preference, setPreferenceState] = useState<ThemePreference>(readStoredPreference);
34
+ const mode: ThemeMode = preference === 'system' ? systemMode : preference;
35
+
36
+ useEffect(() => {
37
+ const listener = Appearance.addChangeListener(({ colorScheme }) => {
38
+ if (colorScheme === 'light' || colorScheme === 'dark') {
39
+ setSystemMode(colorScheme);
40
+ }
41
+ });
42
+ return () => listener.remove();
43
+ }, []);
44
+
45
+ const value = useMemo<ThemeContextProps>(() => {
46
+ const setPreference = (next: ThemePreference) => {
47
+ if (next === 'system') {
48
+ StoragePreferences.remove(StorageKeys.THEME_MODE);
49
+ } else {
50
+ StoragePreferences.setString(StorageKeys.THEME_MODE, next);
51
+ }
52
+ setPreferenceState(next);
53
+ };
54
+
55
+ return {
56
+ theme: themes[mode],
57
+ mode,
58
+ preference,
59
+ setPreference,
60
+ toggleTheme: () => setPreference(mode === 'light' ? 'dark' : 'light'),
61
+ };
62
+ }, [mode, preference]);
63
+
64
+ return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
35
65
  };
36
66
 
37
67
  export const useTheme = () => {
38
- const context = useContext(ThemeContext);
39
- if (!context) {
40
- throw new Error('useTheme must be used within ThemeProvider');
41
- }
42
- return context;
68
+ const context = useContext(ThemeContext);
69
+ if (!context) {
70
+ throw new Error('useTheme must be used within ThemeProvider');
71
+ }
72
+ return context;
43
73
  };
@@ -0,0 +1,96 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { useInfiniteQuery, type QueryKey } from '@tanstack/react-query';
3
+
4
+ const SEARCH_DEBOUNCE_MS = 400;
5
+
6
+ interface PageContext<TParams> {
7
+ pageParam: number;
8
+ limit: number;
9
+ /** Debounced search term ('' when empty). */
10
+ search: string;
11
+ dynamicParams?: TParams;
12
+ }
13
+
14
+ interface Options<TPage, TItem, TParams> {
15
+ /** Base key. The search term and dynamicParams are appended automatically. */
16
+ queryKey: QueryKey;
17
+ queryFn: (ctx: PageContext<TParams>) => Promise<TPage>;
18
+ /** Flattens all loaded pages into one list. */
19
+ select: (pages: TPage[]) => TItem[];
20
+ limit?: number;
21
+ /** Extra values the request depends on (filters, ids). Part of the cache key. */
22
+ dynamicParams?: TParams;
23
+ /**
24
+ * Whether another page exists. Default: the last page returned `limit`
25
+ * items. Override when the API returns a total or a `hasMore` flag.
26
+ */
27
+ hasNextPage?: (lastPage: TPage, allPages: TPage[], limit: number) => boolean;
28
+ firstPage?: number;
29
+ staleTime?: number;
30
+ enabled?: boolean;
31
+ }
32
+
33
+ /**
34
+ * Infinite-scroll helper on top of useInfiniteQuery.
35
+ *
36
+ * const { data, handleScrollToBottom, handleRefetch, ... } = useTodoList();
37
+ * <FlatList data={data} onEndReached={handleScrollToBottom} onRefresh={handleRefetch} />
38
+ */
39
+ export function usePaginatedAPI<TPage, TItem, TParams = undefined>({
40
+ queryKey,
41
+ queryFn,
42
+ select,
43
+ limit = 10,
44
+ dynamicParams,
45
+ hasNextPage,
46
+ firstPage = 1,
47
+ staleTime,
48
+ enabled = true,
49
+ }: Options<TPage, TItem, TParams>) {
50
+ const [search, setSearch] = useState('');
51
+ const [debouncedSearch, setDebouncedSearch] = useState('');
52
+
53
+ useEffect(() => {
54
+ const timer = setTimeout(() => setDebouncedSearch(search.trim()), SEARCH_DEBOUNCE_MS);
55
+ return () => clearTimeout(timer);
56
+ }, [search]);
57
+
58
+ const query = useInfiniteQuery({
59
+ queryKey: [...queryKey, { search: debouncedSearch, limit, ...dynamicParams }],
60
+ queryFn: ({ pageParam }) =>
61
+ queryFn({ pageParam, limit, search: debouncedSearch, dynamicParams }),
62
+ initialPageParam: firstPage,
63
+ getNextPageParam: (lastPage, allPages, lastPageParam) => {
64
+ const more = hasNextPage
65
+ ? hasNextPage(lastPage, allPages, limit)
66
+ : select([lastPage]).length >= limit;
67
+ return more ? lastPageParam + 1 : undefined;
68
+ },
69
+ select: result => select(result.pages),
70
+ staleTime,
71
+ enabled,
72
+ });
73
+
74
+ const handleScrollToBottom = () => {
75
+ if (query.hasNextPage && !query.isFetchingNextPage && !query.isFetching) {
76
+ query.fetchNextPage();
77
+ }
78
+ };
79
+
80
+ return {
81
+ data: query.data ?? [],
82
+ isLoading: query.isLoading,
83
+ isFetchingNextPage: query.isFetchingNextPage,
84
+ isRefreshing: query.isRefetching && !query.isFetchingNextPage,
85
+ hasNextPage: query.hasNextPage,
86
+ error: query.error,
87
+ handleScrollToBottom,
88
+ handleRefetch: () => query.refetch(),
89
+ search,
90
+ handleSearch: setSearch,
91
+ resetSearch: () => setSearch(''),
92
+ query,
93
+ };
94
+ }
95
+
96
+ export default usePaginatedAPI;
@@ -1,32 +1,41 @@
1
- // navigation/AppStack.tsx
2
- import React from "react";
1
+ import React from 'react';
3
2
  import {
4
- createStackNavigator,
5
- StackNavigationOptions,
6
- } from "@react-navigation/stack";
7
- import { NavigationProp } from "@react-navigation/native";
8
- import { AppStackParams } from "./AppStackParams";
9
- import { screens } from "./screens";
3
+ createNativeStackNavigator,
4
+ NativeStackNavigationOptions,
5
+ NativeStackNavigationProp,
6
+ } from '@react-navigation/native-stack';
7
+ import { AppStackParams } from './AppStackParams';
8
+ import { screens } from './screens';
10
9
 
11
- const App = createStackNavigator<AppStackParams>();
12
- const options: StackNavigationOptions = { headerShown: false };
10
+ const Stack = createNativeStackNavigator<AppStackParams>();
13
11
 
14
- export type StackNavigation = NavigationProp<AppStackParams>;
15
-
16
- const AppStack = () => {
17
- return (
18
- <App.Navigator initialRouteName="SplashScreen">
19
- {screens.map((item) => (
20
- <App.Screen
21
- key={item.name}
22
- name={item.name as any}
23
- component={item.component as any}
24
- options={options}
25
- />
26
- ))}
27
- {/* 🚀 Later you can add HomeDrawer, Tabs, or other screens separately */}
28
- </App.Navigator>
29
- );
12
+ /**
13
+ * Defaults for every screen. Native stack uses UINavigationController on iOS
14
+ * and Fragments on Android, so transitions and swipe-back run natively.
15
+ */
16
+ export const defaultScreenOptions: NativeStackNavigationOptions = {
17
+ headerShown: false,
18
+ // Same slide on both platforms (Android's default is a fade-from-bottom).
19
+ animation: 'ios_from_right',
20
+ // Off-screen screens stop re-rendering until they're focused again.
21
+ freezeOnBlur: true,
30
22
  };
31
23
 
32
- export default AppStack;
24
+ /** Use with `useNavigation<StackNavigation>()` in nested components. */
25
+ export type StackNavigation = NativeStackNavigationProp<AppStackParams>;
26
+
27
+ const AppStack = () => (
28
+ <Stack.Navigator initialRouteName="SplashScreen" screenOptions={defaultScreenOptions}>
29
+ {screens.map(item => (
30
+ <Stack.Screen
31
+ key={item.name}
32
+ name={item.name}
33
+ component={item.component}
34
+ options={item.options}
35
+ />
36
+ ))}
37
+ {/* Tabs or a drawer can be registered here as screens (see docs/navigation.md). */}
38
+ </Stack.Navigator>
39
+ );
40
+
41
+ export default AppStack;
@@ -1,16 +1,22 @@
1
- import { StackNavigationOptions } from "@react-navigation/stack";
2
- import HomeScreen from "../screens/HomeScreen";
3
- import SplashScreen from "../screens/SplashScreen";
4
- import LoginScreen from "../screens/LoginScreen";
5
- import { AppStackParams } from "./AppStackParams";
1
+ import type React from 'react';
2
+ import type { NativeStackNavigationOptions } from '@react-navigation/native-stack';
3
+ import HomeScreen from '../screens/HomeScreen';
4
+ import SplashScreen from '../screens/SplashScreen';
5
+ import LoginScreen from '../screens/LoginScreen';
6
+ import { AppStackParams } from './AppStackParams';
6
7
 
7
- export const screens: Array<{
8
+ export type ScreenConfig = {
8
9
  name: keyof AppStackParams;
9
10
  component: React.ComponentType<any>;
10
- options?: StackNavigationOptions;
11
- }> = [
12
- { name: "SplashScreen", component: SplashScreen },
13
- { name: "LoginScreen", component: LoginScreen },
14
- { name: "HomeScreen", component: HomeScreen },
11
+ /** Merged over `defaultScreenOptions` in AppStack.tsx. */
12
+ options?: NativeStackNavigationOptions;
13
+ };
14
+
15
+ export const screens: ScreenConfig[] = [
16
+ { name: 'SplashScreen', component: SplashScreen },
17
+ // Login and Home replace the whole stack (navigation.reset), so a fade
18
+ // reads better than a slide.
19
+ { name: 'LoginScreen', component: LoginScreen, options: { animation: 'fade' } },
20
+ { name: 'HomeScreen', component: HomeScreen, options: { animation: 'fade' } },
15
21
  // Add your other screens here
16
22
  ];
@@ -1,21 +1,26 @@
1
1
  import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2
2
 
3
- const initialState: any = {
4
- value: 0,
3
+ /** Example app-wide slice. Replace or remove once the app has real global state. */
4
+ interface GlobalState {
5
+ value: number;
6
+ }
7
+
8
+ const initialState: GlobalState = {
9
+ value: 0,
5
10
  };
6
11
 
7
12
  const appSlice = createSlice({
8
- name: 'global',
9
- initialState,
10
- reducers: {
11
- setValue: (state, action: PayloadAction<number>) => {
12
- state.value = action.payload;
13
- },
14
- resetValue: (state) => {
15
- state.value = 0;
16
- },
13
+ name: 'global',
14
+ initialState,
15
+ reducers: {
16
+ setValue: (state, action: PayloadAction<number>) => {
17
+ state.value = action.payload;
18
+ },
19
+ resetValue: state => {
20
+ state.value = 0;
17
21
  },
22
+ },
18
23
  });
19
24
 
20
25
  export const { setValue, resetValue } = appSlice.actions;
21
- export default appSlice.reducer;
26
+ export default appSlice.reducer;
@@ -1,9 +1,9 @@
1
- import { createSlice, PayloadAction } from "@reduxjs/toolkit";
2
-
3
- type User = { [key: string]: any } | null;
1
+ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2
+ import type { User } from '../types';
3
+ import type { RootStore } from '../store';
4
4
 
5
5
  interface AuthState {
6
- user: User;
6
+ user: User | null;
7
7
  accessToken: string | null;
8
8
  }
9
9
 
@@ -13,17 +13,14 @@ const initialState: AuthState = {
13
13
  };
14
14
 
15
15
  const authSlice = createSlice({
16
- name: "auth",
16
+ name: 'auth',
17
17
  initialState,
18
18
  reducers: {
19
- setCredentials(
20
- state,
21
- action: PayloadAction<{ user: User; accessToken: string }>,
22
- ) {
19
+ setCredentials(state, action: PayloadAction<{ user: User; accessToken: string }>) {
23
20
  state.user = action.payload.user;
24
21
  state.accessToken = action.payload.accessToken;
25
22
  },
26
- setUser(state, action: PayloadAction<User>) {
23
+ setUser(state, action: PayloadAction<User | null>) {
27
24
  state.user = action.payload;
28
25
  },
29
26
  setAccessToken(state, action: PayloadAction<string | null>) {
@@ -36,10 +33,10 @@ const authSlice = createSlice({
36
33
  },
37
34
  });
38
35
 
39
- export const { setCredentials, setUser, setAccessToken, clearAuth } =
40
- authSlice.actions;
36
+ export const { setCredentials, setUser, setAccessToken, clearAuth } = authSlice.actions;
41
37
 
42
- export const selectCurrentUser = (state: any) => state.auth?.user;
43
- export const selectAccessToken = (state: any) => state.auth?.accessToken;
38
+ export const selectCurrentUser = (state: RootStore) => state.auth.user;
39
+ export const selectAccessToken = (state: RootStore) => state.auth.accessToken;
40
+ export const selectIsLoggedIn = (state: RootStore) => !!state.auth.accessToken;
44
41
 
45
42
  export default authSlice.reducer;
@@ -1,23 +1,27 @@
1
- import { combineReducers, configureStore } from "@reduxjs/toolkit";
2
- import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
3
- import { persistReducer, persistStore } from "redux-persist";
4
- import reducer from "./slice";
5
- import authReducer from "./slices/authSlice";
6
- import AsyncStorage from "@react-native-async-storage/async-storage";
1
+ import { combineReducers, configureStore } from '@reduxjs/toolkit';
2
+ import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux';
3
+ import { persistReducer, persistStore } from 'redux-persist';
4
+ import reducer from './slice';
5
+ import authReducer from './slices/authSlice';
6
+ import { reduxStorage } from '../../constants/StoragePreferences';
7
+
7
8
  const persistConfig = {
8
- key: "root",
9
- storage: AsyncStorage,
10
- whitelist: ["auth"],
9
+ key: 'root',
10
+ storage: reduxStorage,
11
+ // Only these slices are written to MMKV. Server data belongs in React Query.
12
+ whitelist: ['auth'],
11
13
  };
12
14
 
13
15
  const rootReducer = combineReducers({
14
16
  global: reducer,
15
17
  auth: authReducer,
16
18
  });
19
+
17
20
  const persistedReducer = persistReducer(persistConfig, rootReducer);
21
+
18
22
  export const store = configureStore({
19
23
  reducer: persistedReducer,
20
- middleware: (getDefaultMiddleware) =>
24
+ middleware: getDefaultMiddleware =>
21
25
  getDefaultMiddleware({
22
26
  serializableCheck: false,
23
27
  }),
@@ -1,40 +1,61 @@
1
1
  /**
2
- * API Error Response Type
2
+ * Shared types: API request bodies, response models and app entities.
3
+ * Component props stay in their component file; route params live in
4
+ * src/navigation/AppStackParams.ts.
3
5
  */
6
+
7
+ // ---------- API envelopes ----------
8
+
4
9
  export interface ApiErrorResponse {
5
10
  message: string;
6
11
  statusCode?: number;
7
12
  code?: string;
8
- details?: Record<string, any>;
13
+ details?: Record<string, unknown>;
9
14
  }
10
15
 
11
- /**
12
- * API Success Response Type
13
- */
14
16
  export interface ApiSuccessResponse<T> {
15
17
  data: T;
16
18
  message?: string;
17
19
  statusCode?: number;
18
20
  }
19
21
 
20
- /**
21
- * Todo Item Type
22
- */
22
+ export type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;
23
+
24
+ export interface PaginationOptions {
25
+ page: number;
26
+ limit: number;
27
+ }
28
+
29
+ // ---------- Auth ----------
30
+
31
+ export interface User {
32
+ id: string;
33
+ name: string;
34
+ email: string;
35
+ avatarUrl?: string;
36
+ }
37
+
38
+ export interface LoginForm {
39
+ email: string;
40
+ password: string;
41
+ }
42
+
43
+ export interface LoginResponse {
44
+ user: User;
45
+ accessToken: string;
46
+ refreshToken?: string;
47
+ }
48
+
49
+ // ---------- Todos (demo) ----------
50
+
23
51
  export interface TodoItem {
24
52
  id: number;
25
53
  title: string;
26
54
  completed: boolean;
27
55
  }
28
56
 
29
- /**
30
- * Pagination Type
31
- */
32
- export interface PaginationOptions {
33
- page: number;
34
- limit: number;
57
+ export interface TodoListParams {
58
+ _page: number;
59
+ _limit: number;
60
+ q?: string;
35
61
  }
36
-
37
- /**
38
- * Generic API Response
39
- */
40
- export type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;
@@ -1,38 +1,112 @@
1
- import * as React from 'react';
2
- import { Text, View, StyleSheet, TouchableOpacity } from 'react-native';
1
+ import React from 'react';
2
+ import { Pressable, StyleSheet, Text, View } from 'react-native';
3
3
  import { SafeAreaView } from 'react-native-safe-area-context';
4
+
5
+ // Hooks / state
4
6
  import { useTheme } from '../hooks/ThemeContext';
7
+ import { useAppDispatch, useAppSelector } from '../redux/store';
8
+ import { clearAuth, selectCurrentUser } from '../redux/slices/authSlice';
9
+
10
+ // Helpers / constants
11
+ import { navigateAndSimpleReset } from '../helper/navigation-service';
12
+ import { Typography } from '../helper/typography';
13
+ import { horizontalScale, moderateScale, verticalScale } from '../helper/matrics';
14
+ import { AppString } from '../../constants/AppString';
15
+
16
+ const HomeScreen = () => {
17
+ const { theme, mode, preference, toggleTheme, setPreference } = useTheme();
18
+ const user = useAppSelector(selectCurrentUser);
19
+ const dispatch = useAppDispatch();
20
+
21
+ const onLogout = () => {
22
+ dispatch(clearAuth());
23
+ navigateAndSimpleReset('LoginScreen');
24
+ };
25
+
26
+ const outlineButton = [styles.button, styles.outline, { borderColor: theme.border }];
27
+
28
+ return (
29
+ <SafeAreaView style={[styles.safeArea, { backgroundColor: theme.background }]}>
30
+ <View style={styles.container}>
31
+ <Text style={[Typography.title1, { color: theme.text }]}>
32
+ {AppString.hello}
33
+ {user?.name ? `, ${user.name}` : ''}
34
+ </Text>
35
+
36
+ <View style={[styles.card, { backgroundColor: theme.card, borderColor: theme.border }]}>
37
+ <Text style={[Typography.caption1, styles.overline, { color: theme.muted }]}>
38
+ {AppString.currentTheme}
39
+ </Text>
40
+ <Text style={[Typography.headline, styles.capitalize, { color: theme.text }]}>
41
+ {mode} · {preference}
42
+ </Text>
43
+ </View>
5
44
 
6
- interface Props { }
7
-
8
- const HomeScreen = (props: Props) => {
9
- const { theme, toggleTheme, mode } = useTheme();
10
- return (
11
- <SafeAreaView style={{ flex: 1, backgroundColor: theme.background }}>
12
- <View style={[styles.container, { backgroundColor: theme.background }]}>
13
- <Text style={{ color: theme.text }}>Current theme: {mode}</Text>
14
- <TouchableOpacity
15
- style={[styles.button, { backgroundColor: theme.primary }]}
16
- onPress={toggleTheme}
17
- >
18
- <Text style={{ color: theme.text }}>Toggle Theme</Text>
19
- </TouchableOpacity>
20
- </View>
21
- </SafeAreaView>
22
- );
45
+ <View style={styles.actions}>
46
+ <Pressable
47
+ onPress={toggleTheme}
48
+ accessibilityRole="button"
49
+ style={[styles.button, { backgroundColor: theme.primary }]}>
50
+ <Text style={[Typography.headline, { color: theme.onPrimary }]}>
51
+ {AppString.toggleTheme}
52
+ </Text>
53
+ </Pressable>
54
+ <Pressable
55
+ onPress={() => setPreference('system')}
56
+ disabled={preference === 'system'}
57
+ accessibilityRole="button"
58
+ style={[outlineButton, preference === 'system' && styles.disabled]}>
59
+ <Text style={[Typography.headline, { color: theme.text }]}>
60
+ {AppString.followSystem}
61
+ </Text>
62
+ </Pressable>
63
+ <Pressable onPress={onLogout} accessibilityRole="button" style={outlineButton}>
64
+ <Text style={[Typography.headline, { color: theme.error }]}>{AppString.logout}</Text>
65
+ </Pressable>
66
+ </View>
67
+ </View>
68
+ </SafeAreaView>
69
+ );
23
70
  };
24
71
 
25
72
  export default HomeScreen;
26
73
 
27
74
  const styles = StyleSheet.create({
28
- container: {
29
- flex: 1,
30
- justifyContent: 'center',
31
- alignItems: 'center',
32
- },
33
- button: {
34
- marginTop: 20,
35
- padding: 12,
36
- borderRadius: 8,
37
- },
75
+ safeArea: {
76
+ flex: 1,
77
+ },
78
+ container: {
79
+ flex: 1,
80
+ justifyContent: 'center',
81
+ paddingHorizontal: horizontalScale(24),
82
+ },
83
+ card: {
84
+ marginTop: verticalScale(32),
85
+ borderRadius: moderateScale(16),
86
+ borderWidth: 1,
87
+ padding: moderateScale(20),
88
+ },
89
+ overline: {
90
+ textTransform: 'uppercase',
91
+ },
92
+ capitalize: {
93
+ marginTop: verticalScale(4),
94
+ textTransform: 'capitalize',
95
+ },
96
+ actions: {
97
+ marginTop: verticalScale(24),
98
+ gap: moderateScale(12),
99
+ },
100
+ button: {
101
+ height: 48,
102
+ borderRadius: moderateScale(12),
103
+ alignItems: 'center',
104
+ justifyContent: 'center',
105
+ },
106
+ outline: {
107
+ borderWidth: 1,
108
+ },
109
+ disabled: {
110
+ opacity: 0.5,
111
+ },
38
112
  });