Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/docs/guides/01-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,3 @@ export default function Main() {
);
}
```

:::note
For MD2 check the following [Material Design 2 default theme](https://github.com/callstack/react-native-paper/blob/main/src/styles/themes/v2/LightTheme.tsx).
:::
133 changes: 14 additions & 119 deletions docs/docs/guides/02-theming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ You can change the theme prop dynamically and all the components will automatica
A theme usually contains the following properties:

- `dark` (`boolean`): whether this is a dark theme or light theme.
- `version`: specify which design system components should follow in the app
- 3 - new Material You (MD3)
- 2 - previous Material Design (MD2)
- `version`: Material You (MD3); kept for compatibility and normalized to `3` by `PaperProvider`
- `mode` (`'adaptive' | 'exact'`): color mode for dark theme (See [Dark Theme](#dark-theme)).
- `roundness` (`number`): roundness of common elements, such as buttons.
- `colors` (`object`): various colors used throughout different elements.
Expand Down Expand Up @@ -229,31 +227,26 @@ export default function Main() {

### Sync dynamic colors with system colors

Using [`pchmn/expo-material3-theme`](https://github.com/pchmn/expo-material3-theme) library you can easily access the Material 3 system colors from Android 12+ devices and seamlessly integrate them into your dynamic theme. Any changes made by the user to the system colors will be automatically reflected in the theme.
React Native Paper provides built-in support for Android dynamic colors through `DynamicLightTheme` and `DynamicDarkTheme`. These themes use React Native's `PlatformColor` API to map all Material Design 3 color roles to Android system colors, so any changes the user makes to their system palette are automatically reflected in the app.

:::info
In case of incompatible devices, the library will revert to a default theme.
Dynamic colors require Android 12 (API 31+). On older Android versions and all other platforms, these themes fall back to the default `LightTheme` / `DarkTheme`.
:::

To get started, follow the [installation instructions](https://github.com/pchmn/expo-material3-theme#installation) and check the following code:

```tsx
import { useMaterial3Theme } from '@pchmn/expo-material3-theme';
import { useColorScheme } from 'react-native';
import { MD3DarkTheme, MD3LightTheme, PaperProvider } from 'react-native-paper';
import {
DynamicDarkTheme,
DynamicLightTheme,
PaperProvider,
} from 'react-native-paper';
import App from './src/App';

export default function Main() {
const colorScheme = useColorScheme();
const { theme } = useMaterial3Theme();

const paperTheme =
colorScheme === 'dark'
? { ...MD3DarkTheme, colors: theme.dark }
: { ...MD3LightTheme, colors: theme.light };
const isDarkMode = useColorScheme() === 'dark';

return (
<PaperProvider theme={paperTheme}>
<PaperProvider theme={isDarkMode ? DynamicDarkTheme : DynamicLightTheme}>
<App />
</PaperProvider>
);
Expand Down Expand Up @@ -471,111 +464,13 @@ export default function HomeScreen() {
}
```

## Material Design 2

Using Material Design 2 is <b>fully supported in React Native Paper v5.x</b>.

### Simple setup

In order to use the Material Design 2 theme you can just pass `{ version: 2 }` to the PaperProvider theme prop:

```js
import * as React from 'react';
import { PaperProvider } from 'react-native-paper';
import App from './src/App';
## Material Design 3

export default function Main() {
return (
<PaperProvider theme={{ version: 2 }}>
<App />
</PaperProvider>
);
}
```

Specifying `{ version: 2 }` tells React Native Paper to use the built in Material Design 2 theme, so you don't have to fully extend it on your own.

### Advanced setup

As with any theme, you can also specify your custom properties within the Material Design 2 theme:

```js
import * as React from 'react';
import { MD2LightTheme, PaperProvider } from 'react-native-paper';
import App from './src/App';

export default function Main() {
const theme = {
...MD2LightTheme,

// Specify a custom property
custom: 'property',

// Specify a custom nested property
colors: {
...MD2LightTheme.colors,
primary: '#fefefe',
},
};

return (
<PaperProvider theme={theme}>
<App />
</PaperProvider>
);
}
```

### Typescript

Due to the amount of changes in the theme's schema shape it falls into the [Advanced theme overrides](#advanced-theme-overrides) category. The steps are identical as with any advanced theme, just make sure to extend the built-in `MD2LightTheme` or `MD2DarkTheme` instead of `MD3LightTheme` or `MD3DarkTheme`.

The final example for Material Design 2 would look like this:

```ts
import * as React from 'react';
import { MD2LightTheme, PaperProvider, useTheme } from 'react-native-paper';
import App from './src/App';

const theme = {
// Extend Material Design 2 theme

...MD2LightTheme, // or MD2DarkTheme

// Specify a custom property
myOwnProperty: true,

// Specify a custom nested property
colors: {
...MD2LightTheme.colors,
myOwnColor: '#BADA55',
},
};

export type AppTheme = typeof theme;

export const useAppTheme = () => useTheme<AppTheme>();

export default function Main() {
return (
<PaperProvider theme={theme}>
<App />
</PaperProvider>
);
}

// App.tsx

export default function App() {
const { theme } = useAppTheme();

return <View style={{ backgroundColor: theme.colors.primary }} />;
}
```
React Native Paper ships with Material Design 3 (Material You) only. Customize the default experience by extending `MD3LightTheme` or `MD3DarkTheme` (see [Extending the theme](#extending-the-theme) and [Advanced theme overrides](#advanced-theme-overrides)).

### Migrating to Material You
### Migrating from Material Design 2

If you are migrating from Material Design 2 (4.x and lower) to Material You (5.x), please refer to our [Migration Guide](https://callstack.github.io/react-native-paper/docs/guides/migration-guide-to-5.0)
If you are upgrading from Material Design 2 (4.x and lower), follow the [Migration Guide](https://callstack.github.io/react-native-paper/docs/guides/migration-guide-to-5.0).

## Applying a theme to a paper component

Expand Down
95 changes: 2 additions & 93 deletions docs/docs/guides/04-fonts.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,99 +47,8 @@ Now, you are able to use `fontFamily` from font files.

## Configuring fonts in ThemeProvider

### Material Design 2

#### Using `configureFonts` helper

To create a custom font, prepare a `fontConfig` object where fonts are divided by platforms. After that, you have to:

* pass the `fontConfig` into `configureFonts` params object property called `config`
* set the params object property `isV3` to `false`.

The `fontConfig` object accepts `ios`, `android`, `macos`, `windows`, `web`, and `native`. Use these to override fonts on particular platforms.

:::info
At a minimum, you need to explicitly pass fonts for `android`, `ios`, and `web`.
:::

```js
import * as React from 'react';
import { configureFonts, MD2LightTheme, PaperProvider } from 'react-native-paper';
import App from './src/App';

const fontConfig = {
web: {
regular: {
fontFamily: 'sans-serif',
fontWeight: 'normal',
},
medium: {
fontFamily: 'sans-serif-medium',
fontWeight: 'normal',
},
light: {
fontFamily: 'sans-serif-light',
fontWeight: 'normal',
},
thin: {
fontFamily: 'sans-serif-thin',
fontWeight: 'normal',
},
},
ios: {
regular: {
fontFamily: 'sans-serif',
fontWeight: 'normal',
},
medium: {
fontFamily: 'sans-serif-medium',
fontWeight: 'normal',
},
light: {
fontFamily: 'sans-serif-light',
fontWeight: 'normal',
},
thin: {
fontFamily: 'sans-serif-thin',
fontWeight: 'normal',
},
},
android: {
regular: {
fontFamily: 'sans-serif',
fontWeight: 'normal',
},
medium: {
fontFamily: 'sans-serif-medium',
fontWeight: 'normal',
},
light: {
fontFamily: 'sans-serif-light',
fontWeight: 'normal',
},
thin: {
fontFamily: 'sans-serif-thin',
fontWeight: 'normal',
},
}
};

const theme = {
...MD2LightTheme,
fonts: configureFonts({config: fontConfig, isV3: false}),
};

export default function Main() {
return (
<PaperProvider theme={theme}>
<App />
</PaperProvider>
);
}
```

:::tip
If you're using TypeScript use `as const` when defining `fontConfig`.
:::note
Older Material Design 2 platform-split font configuration (`configureFonts` with per-platform `ios` / `android` / `web` keys) is no longer supported. Use the Material Design 3 typescale and `configureFonts` as documented below.
:::

### Material Design 3
Expand Down
6 changes: 1 addition & 5 deletions docs/docs/guides/06-recommended-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,4 @@ Material Design themed [date picker](https://material.io/components/date-pickers

## Time Picker
[web-ridge/react-native-paper-dates](https://github.com/web-ridge/react-native-paper-dates)
Material Design themed [time picker](https://material.io/components/time-pickers), maintained by [@RichardLindhout](https://twitter.com/RichardLindhout)

## System Colors
[pchmn/expo-material3-theme](https://github.com/pchmn/expo-material3-theme)
Retrieve Material 3 system colors from Android 12+ devices
Material Design themed [time picker](https://material.io/components/time-pickers), maintained by [@RichardLindhout](https://twitter.com/RichardLindhout)
57 changes: 1 addition & 56 deletions docs/docs/guides/08-theming-with-react-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,9 @@ But how to make them work together?

## Themes adaptation

### Material Design 2

Fortunately, in Material Design 2, both React Navigation and React Native Paper offer very similar API when it comes to theming and theme color structure. It's possible to import them in light and dark variants from both.

```js
import {
DarkTheme as NavigationDarkTheme,
DefaultTheme as NavigationDefaultTheme,
} from '@react-navigation/native';

import {
MD2LightTheme,
MD2DarkTheme,
} from 'react-native-paper';
```

### Material Design 3

From v5, React Native Paper theme colors structure follows the Material Design 3 <i>(known as Material You)</i> colors system, which differs significantly from both the previous Paper's theme and React Navigation theme.
React Native Paper follows the Material Design 3 <i>(Material You)</i> color system, which differs from React Navigation’s default theme shape.

However, to simplify adapting React Navigation theme colors, to use the ones from React Native Paper, it's worth using a utility called `adaptNavigationTheme` – it accepts navigation-compliant themes in both modes and returns their equivalents adjusted to Material Design 3.

Expand Down Expand Up @@ -127,24 +111,6 @@ To make things easier we can use [deepmerge](https://www.npmjs.com/package/deepm
npm install deepmerge
```

### Material Design 2

```js
import {
NavigationContainer,
DarkTheme as NavigationDarkTheme,
DefaultTheme as NavigationDefaultTheme,
} from '@react-navigation/native';
import {
MD2DarkTheme,
MD2LightTheme,
} from 'react-native-paper';
import merge from 'deepmerge';

const CombinedDefaultTheme = merge(MD2LightTheme, NavigationDefaultTheme);
const CombinedDarkTheme = merge(MD2DarkTheme, NavigationDarkTheme);
```

### Material Design 3

```js
Expand All @@ -171,27 +137,6 @@ const CombinedDarkTheme = merge(MD3DarkTheme, DarkTheme);

Alternatively, we could merge those themes using vanilla JavaScript:

### Material Design 2

```js
const CombinedDefaultTheme = {
...MD2LightTheme,
...NavigationDefaultTheme,
colors: {
...MD2LightTheme.colors,
...NavigationDefaultTheme.colors,
},
};
const CombinedDarkTheme = {
...MD2DarkTheme,
...NavigationDarkTheme,
colors: {
...MD2DarkTheme.colors,
...NavigationDarkTheme.colors,
},
};
```

### Material Design 3

```js
Expand Down
Loading
Loading