Skip to content

Commit 8c7e8b3

Browse files
feat: Migrate to Material 3 with dynamic theming
This commit migrates the application to a Material 3 based UI with support for dynamic color theming (Material You). Key changes: - Added `@pchmn/expo-material3-theme` to get system colors on Android 12+. - Created a `styles/theme.js` file to provide a dynamic theme to the app via a `useAppTheme` hook. - Updated `App.js` to use the new dynamic theme with `PaperProvider`. - Refactored all screens in the `screens` directory to use colors and styles from the dynamic theme, replacing hardcoded values. - Updated `MainNavigator.js` and `GroupsStackNavigator.js` to use the dynamic theme for the tab bar and headers, ensuring a consistent look and feel. - Created a `MIGRATION_GUIDE.md` to document the changes.
1 parent ddfe8b2 commit 8c7e8b3

16 files changed

+9359
-331
lines changed

frontend/App.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ import React from 'react';
22
import AppNavigator from './navigation/AppNavigator';
33
import { PaperProvider } from 'react-native-paper';
44
import { AuthProvider } from './context/AuthContext';
5+
import { useAppTheme } from './styles/theme';
6+
7+
const Main = () => {
8+
const theme = useAppTheme();
9+
return (
10+
<PaperProvider theme={theme}>
11+
<AppNavigator />
12+
</PaperProvider>
13+
)
14+
}
515

616
export default function App() {
717
return (
818
<AuthProvider>
9-
<PaperProvider>
10-
<AppNavigator />
11-
</PaperProvider>
19+
<Main />
1220
</AuthProvider>
1321
);
1422
}

frontend/MIGRATION_GUIDE.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Migration to Material 3 with Dynamic Theming
2+
3+
This document outlines the changes made to the application to migrate from a static theme to a Material 3 design with dynamic theming (Material You).
4+
5+
## 1. Project Structure Changes
6+
7+
A new directory `styles` was created to house the theming logic.
8+
9+
- `styles/theme.js`: This file contains the core logic for enabling dynamic theming.
10+
11+
## 2. Key Changes by Folder
12+
13+
### `/` (Root Directory)
14+
15+
- **`App.js`**:
16+
- The `PaperProvider` is now wrapped in a new `Main` component.
17+
- The `Main` component uses the `useAppTheme` hook from `styles/theme.js` to get the dynamic theme and applies it to the `PaperProvider`. This enables app-wide dynamic theming.
18+
19+
### `styles/`
20+
21+
- **`theme.js`**:
22+
- This new file exports a `useAppTheme` hook.
23+
- It uses the `@pchmn/expo-material3-theme` library to get the Material 3 theme based on the user's system colors on Android 12+.
24+
- It provides a fallback to the default light theme for other platforms or older Android versions.
25+
26+
### `screens/`
27+
28+
All screens in this folder have been refactored to use the dynamic theme. The general changes for each screen are:
29+
30+
- **Import `useTheme`**: The `useTheme` hook from `react-native-paper` is imported.
31+
- **Get Theme Object**: The theme object is retrieved using `const theme = useTheme();`.
32+
- **Dynamic Styles**: Hardcoded colors in `StyleSheet` have been replaced with colors from the theme object (e.g., `theme.colors.primary`, `theme.colors.background`, `theme.colors.onSurface`).
33+
- **Removed `StyleSheet.create` from component body**: The `StyleSheet.create` call was moved outside the component body to avoid re-creating the styles on every render. The styles that depend on the theme are created inside the component.
34+
35+
**Example of changes in a screen (`HomeScreen.js`):**
36+
37+
- Hardcoded colors like `'#4CAF50'` and `'white'` were replaced with `theme.colors.primary` and `theme.colors.background`.
38+
- The main view's background color is now set to `theme.colors.background`.
39+
- Text colors are now set to `theme.colors.onSurface` or `theme.colors.onSurfaceVariant` for better readability on different backgrounds.
40+
41+
### `navigation/`
42+
43+
- **`MainNavigator.js`**:
44+
- The bottom tab navigator now uses the dynamic theme.
45+
- `tabBarActiveTintColor` is set to `theme.colors.primary`.
46+
- `tabBarInactiveTintColor` is set to `theme.colors.onSurfaceVariant`.
47+
- `tabBarStyle`'s `backgroundColor` is set to `theme.colors.surface`.
48+
49+
- **`GroupsStackNavigator.js`**:
50+
- The stack navigator's header is now themed.
51+
- `headerStyle`'s `backgroundColor` is set to `theme.colors.surface`.
52+
- `headerTintColor` is set to `theme.colors.onSurface`.
53+
54+
- **`AuthNavigator.js` & `AccountStackNavigator.js`**:
55+
- No changes were needed as these navigators either hide the header or the screens they render already use themed components (`Appbar`).
56+
57+
## 3. New Dependency
58+
59+
- **`@pchmn/expo-material3-theme`**: This library was added to fetch the system's color palette on Android to enable Material You dynamic theming.
60+
61+
These changes ensure that the app has a modern, minimal UI that adapts to the user's device theme, providing a more personalized experience.

0 commit comments

Comments
 (0)