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).
:::
110 changes: 5 additions & 105 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 @@ -471,111 +469,13 @@ export default function HomeScreen() {
}
```

## Material Design 2
## Material Design 3

Using Material Design 2 is <b>fully supported in React Native Paper v5.x</b>.
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)).

### Simple setup
### Migrating from Material Design 2

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

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 }} />;
}
```

### Migrating to Material You

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
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
37 changes: 6 additions & 31 deletions docs/docs/guides/10-migration-guide-to-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Introducing v5 with Material You

React Native Paper v5 is all about adopting the new Material Design 3 <i>aka</i> Material You. It was released in October 2021 after intense work and effort to make Material You follow a more expressive approach to design.

Paper now supports both Material Design 2 and 3 through the configuration described in [Versioning](#versioning) and is compatible with a handful of API changes.
Current releases use Material Design 3 only; the historical `version: 2` / MD2 theme APIs described below were removed after v5. Use this guide when upgrading older apps to MD3.

# Migration guide to Material You 5.0

Expand Down Expand Up @@ -36,15 +36,12 @@ npx pod-install

### Versioning

Introducing Material You <i>(MD3)</i> into `react-native-paper` doesn't mean dropping previous Material Design <i>(MD2)</i>! On the contrary, both of them will be supported, however, not simultaneously. To specify which design system components should follow in the app, there is a newly created property in [the theme](https://callstack.github.io/react-native-paper/docs/guides/theming#theme-properties) named `version` that accepts one of two values:

* <b>3</b> – <b>(default)</b> new Material You <i>(MD3)</i>,
* <b>2</b> - previous Material Design <i>(MD2)</i>.
In v5, Material You <i>(MD3)</i> became the default theme. Earlier releases also exposed `version: 2` for Material Design 2; that option and MD2 theme exports have since been removed—use MD3 themes (`MD3LightTheme` / `MD3DarkTheme`) only.

```js
theme: {
/* ... */
version: 3 | 2
version: 3
}
```

Expand Down Expand Up @@ -166,35 +163,13 @@ Take a look at the suggested replacement diff:

### Configure fonts

The existing utility called `configureFonts` was adjusted to help users configure their theme fonts in both version, that's why that function, as of today, is going to accept the object with the follwing properties as an argument:
The `configureFonts` helper configures the Material Design 3 typescale. Pass overrides via the `config` object (see [Fonts](https://callstack.github.io/react-native-paper/docs/guides/fonts.html)).

```ts
configureFonts(params)
```

<b>Parameters:</b>

| NAME | TYPE | REQUIRED |
| ----------- | ----------- | ----------- |
| params | object | No |

Valid `params` keys are:

* `config` ([MD2FontsConfig](https://github.com/callstack/react-native-paper/blob/main/src/styles/fonts.tsx#L63) | [MD3FontsConfig](https://github.com/callstack/react-native-paper/blob/main/src/styles/fonts.tsx#L67)) - fonts config object appropriate to the MD version
* `isV3` (boolean) - whether adjusting theme fonts for v3. Default it <b>true</b>.

To use your current font config from <b>v2</b> and migrate to <b>v3</b> there are two requirements:
* the font config previously passed directly into function has to be passed into the params object property called `config`
* the params object property `isV3` has to be set to `false`

```diff
- configureFonts(fontConfig)
+ configureFonts({config: fontConfig, isV3: false})
configureFonts({ config: { bodyLarge: { fontFamily: 'System' } } })
```

:::tip
If you want to check how to use `configureFonts` on MD3, check the [Fonts](https://callstack.github.io/react-native-paper/docs/guides/fonts.html) guide.
:::
Older direct calls like `configureFonts(fontConfig)` and MD2 platform-split configs should be replaced with MD3 variant keys (`displayLarge`, `bodyMedium`, and so on).

## Components

Expand Down
Loading
Loading