|
| 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