Skip to content

Commit 2ffd3a1

Browse files
committed
docs: update documentation
1 parent b663a75 commit 2ffd3a1

5 files changed

Lines changed: 111 additions & 204 deletions

File tree

docs/docs/guides/01-getting-started.mdx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,19 @@ export default function Main() {
162162

163163
## Customization
164164

165-
You can provide a custom theme to customize the colors, typescales etc. with the `Provider` component. Check the [Material Design 3 default theme](https://github.com/callstack/react-native-paper/blob/main/src/styles/themes/v3/LightTheme.tsx) to see what customization options are supported.
165+
You can provide a custom theme to customize the colors, typescales etc. with the `Provider` component. Check the [default theme](https://github.com/callstack/react-native-paper/blob/main/src/theme/schemes/LightTheme.tsx) to see what customization options are supported.
166166

167167
Example:
168168

169169
```js
170170
import * as React from 'react';
171-
import {
172-
MD3LightTheme as DefaultTheme,
173-
PaperProvider,
174-
} from 'react-native-paper';
171+
import { LightTheme, PaperProvider } from 'react-native-paper';
175172
import App from './src/App';
176173

177174
const theme = {
178-
...DefaultTheme,
175+
...LightTheme,
179176
colors: {
180-
...DefaultTheme.colors,
177+
...LightTheme.colors,
181178
primary: 'tomato',
182179
secondary: 'yellow',
183180
},

docs/docs/guides/02-theming.mdx

Lines changed: 70 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function Main() {
2828
}
2929
```
3030

31-
By default React Native Paper will apply the [Material You theme (MD3)](https://github.com/callstack/react-native-paper/blob/main/src/styles/themes/v3/LightTheme.tsx) if no `theme` or `version` prop is passed to the `PaperProvider`.
31+
By default React Native Paper will apply `LightTheme` if no `theme` prop is passed to the `PaperProvider`, automatically switching to `DarkTheme` when the device color scheme is dark.
3232

3333
## Accessing theme properties
3434

@@ -62,12 +62,9 @@ export default withTheme(PaymentScreen);
6262

6363
You can change the theme prop dynamically and all the components will automatically update to reflect the new theme.
6464

65-
A theme usually contains the following properties:
65+
A theme contains the following properties:
6666

6767
- `dark` (`boolean`): whether this is a dark theme or light theme.
68-
- `version`: Material You (MD3); kept for compatibility and normalized to `3` by `PaperProvider`
69-
- `mode` (`'adaptive' | 'exact'`): color mode for dark theme (See [Dark Theme](#dark-theme)).
70-
- `roundness` (`number`): roundness of common elements, such as buttons.
7168
- `colors` (`object`): various colors used throughout different elements.
7269

7370
> The primary key color is used to derive roles for key components across the UI, such as the FAB, prominent buttons, active states, as well as the tint of elevated surfaces.
@@ -143,34 +140,38 @@ A theme usually contains the following properties:
143140
- `fontWeight`
144141
- `lineHeight`
145142
- `fontSize`
146-
- `animation` (`object`)
147-
- `scale` - scale for all animations
148-
149-
When creating a custom theme, you will need to provide all of these properties.
150-
151-
If you don't use a custom theme, Paper will automatically turn animations on/off, depending on device settings.
152-
153-
Otherwise, your custom theme will need to handle it manually, using React Native's [AccessibilityInfo API](https://reactnative.dev/docs/accessibilityinfo).
143+
- `state` (`object`): interaction state opacity layers per the Material Design 3 spec.
144+
- `opacity` - opacities for each interaction state: `hovered` (0.08), `focused` (0.1), `pressed` (0.1), `dragged` (0.16), `disabled` (0.38), `enabled` (1.0)
145+
- `shapes` (`object`): corner radius tokens per the Material Design 3 shape scale.
146+
- `none` · `extraSmall` · `small` · `medium` · `large` · `largeIncreased` · `extraLarge` · `extraLargeIncreased` · `extraExtraLarge` · `full`
147+
- `motion` (`object`): animation tokens: spring physics, easing curves, and durations.
148+
- `spring` - spring stiffness/damping configs for `fast`, `default`, and `slow` speeds, each with `spatial` and `effects` variants
149+
- `easing` - cubic bezier easing curves: `emphasized`, `emphasizedAccelerate`, `emphasizedDecelerate`, `standard`, `standardAccelerate`, `standardDecelerate`, `legacy`, and more
150+
- `duration` - duration milestones in ms: `short1` (50 ms) through `extraLong4`
151+
- `prefersReducedMotion` (`boolean`) - automatically set from device accessibility settings by `PaperProvider`
152+
- `elevation` (`object`): maps elevation level names to their numeric values (`level0``level5`).
153+
- `roundness` (`number`): **Deprecated.** Use `theme.shapes.*` instead.
154+
- `animation` (`object`): **Deprecated.** Use `theme.motion.*` instead.
155+
- `scale` - **Deprecated.** Use `theme.motion.prefersReducedMotion` instead.
156+
157+
`PaperProvider` automatically reflects the device's "Reduce Motion" accessibility setting into `theme.motion.prefersReducedMotion` (and the legacy `theme.animation.scale`). To opt out and handle accessibility yourself, pass `accessibilityAdapters={false}` to `PaperProvider`.
154158

155159
## Extending the theme
156160

157161
Keeping your own properties in the theme is fully supported by our library:
158162

159163
```js
160164
import * as React from 'react';
161-
import {
162-
MD3LightTheme as DefaultTheme,
163-
PaperProvider,
164-
} from 'react-native-paper';
165+
import { LightTheme, PaperProvider } from 'react-native-paper';
165166
import App from './src/App';
166167

167168
const theme = {
168-
...DefaultTheme,
169+
...LightTheme,
169170
// Specify custom property
170171
myOwnProperty: true,
171172
// Specify custom property in nested object
172173
colors: {
173-
...DefaultTheme.colors,
174+
...LightTheme.colors,
174175
myOwnColor: '#BADA55',
175176
},
176177
};
@@ -187,7 +188,7 @@ export default function Main() {
187188
## Creating dynamic theme colors
188189

189190
Dynamic Color Themes allows for generating two color schemes lightScheme and darkScheme, based on the provided source color.
190-
Created schemes are following the Material Design 3 color system and covering colors structure from the Paper theme. User may generate these schemes using the following tool:
191+
Created schemes follow the Material Design 3 color system and cover the full color structure of the Paper theme. Use the tool below to generate them:
191192

192193
<DynamicColorTheme />
193194

@@ -205,14 +206,11 @@ Once we have copied the color schemes from the generated JSON above, we can use
205206

206207
```jsx
207208
import * as React from 'react';
208-
import {
209-
MD3LightTheme as DefaultTheme,
210-
PaperProvider,
211-
} from 'react-native-paper';
209+
import { LightTheme, PaperProvider } from 'react-native-paper';
212210
import App from './src/App';
213211

214212
const theme = {
215-
...DefaultTheme,
213+
...LightTheme,
216214
colors: yourGeneratedLightOrDarkScheme.colors, // Copy it from the color codes scheme and then use it here
217215
};
218216

@@ -227,11 +225,7 @@ export default function Main() {
227225

228226
### Sync dynamic colors with system colors
229227

230-
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.
231-
232-
:::info
233-
Dynamic colors require Android 12 (API 31+). On older Android versions and all other platforms, these themes fall back to the default `LightTheme` / `DarkTheme`.
234-
:::
228+
React Native Paper supports Android Material Design dynamic colors (wallpaper-seeded colors) via the pre-built `DynamicLightTheme` and `DynamicDarkTheme` objects. These use React Native's `PlatformColor` API to map all color roles to the system palette:
235229

236230
```tsx
237231
import { useColorScheme } from 'react-native';
@@ -253,9 +247,13 @@ export default function Main() {
253247
}
254248
```
255249

250+
:::info
251+
Dynamic colors require Android 12 (API 31+). On unsupported platforms and older Android versions, `DynamicLightTheme` and `DynamicDarkTheme` fall back to the static `LightTheme` and `DarkTheme` so consumer code stays platform-agnostic. Use the exported `isDynamicColorSupported` constant if you need to gate UI on platform support.
252+
:::
253+
256254
## Adapting React Navigation theme
257255

258-
The `adaptNavigationTheme` function takes an existing React Navigation theme and returns a React Navigation theme using the colors from Material Design 3. This theme can be passed to `NavigationContainer` so that React Navigation's UI elements have the same color scheme as Paper.
256+
The `adaptNavigationTheme` function takes an existing React Navigation theme and returns a React Navigation theme using Paper's color scheme. Pass the result to `NavigationContainer` so that React Navigation's UI elements match Paper's colors.
259257

260258
```ts
261259
adaptNavigationTheme(themes);
@@ -306,21 +304,24 @@ Valid `themes` keys are:
306304

307305
```ts
308306
// App.tsx
309-
import { NavigationContainer, DefaultTheme } from '@react-navigation/native';
307+
import {
308+
NavigationContainer,
309+
DefaultTheme as NavigationDefaultTheme,
310+
} from '@react-navigation/native';
310311
import { createStackNavigator } from '@react-navigation/stack';
311312
import {
312313
PaperProvider,
313-
MD3LightTheme,
314+
LightTheme,
314315
adaptNavigationTheme,
315316
} from 'react-native-paper';
316317
const Stack = createStackNavigator();
317-
const { LightTheme } = adaptNavigationTheme({
318-
reactNavigationLight: DefaultTheme,
318+
const { LightTheme: NavigationLightTheme } = adaptNavigationTheme({
319+
reactNavigationLight: NavigationDefaultTheme,
319320
});
320321
export default function App() {
321322
return (
322-
<PaperProvider theme={MD3LightTheme}>
323-
<NavigationContainer theme={LightTheme}>
323+
<PaperProvider theme={LightTheme}>
324+
<NavigationContainer theme={NavigationLightTheme}>
324325
<Stack.Navigator initialRouteName="Home">
325326
<Stack.Screen name="Home" component={HomeScreen} />
326327
<Stack.Screen name="Details" component={DetailsScreen} />
@@ -343,29 +344,19 @@ There are two supported ways of overriding the theme:
343344
change the built-in schema shape
344345
</i>
345346

346-
:::caution
347-
TypeScript support for `withTheme` is currently limited to <b>Material You (MD3)</b> theme only.
348-
349-
<i>
350-
We are planning to provide a better support of handling custom theme overrides
351-
in future releases.
352-
</i>
353-
:::
354-
355347
### Simple built-in theme overrides
356348

357349
You can provide a `theme` prop with a theme object with the same properties as the default theme:
358350

359351
```js
360352
import * as React from 'react';
361-
import { MD3LightTheme, PaperProvider } from 'react-native-paper';
353+
import { LightTheme, PaperProvider } from 'react-native-paper';
362354
import App from './src/App';
363355

364356
const theme = {
365-
...MD3LightTheme, // or MD3DarkTheme
366-
roundness: 2,
357+
...LightTheme, // or DarkTheme
367358
colors: {
368-
...MD3LightTheme.colors,
359+
...LightTheme.colors,
369360
primary: '#3498db',
370361
secondary: '#f1c40f',
371362
tertiary: '#a1b2c3',
@@ -389,18 +380,18 @@ If you need to modify the built-in theme schema by adding a new property or chan
389380

390381
```ts
391382
import * as React from 'react';
392-
import { MD3LightTheme, PaperProvider } from 'react-native-paper';
383+
import { LightTheme, PaperProvider } from 'react-native-paper';
393384
import App from './src/App';
394385

395386
const theme = {
396-
...MD3LightTheme,
387+
...LightTheme,
397388

398389
// Specify a custom property
399390
custom: 'property',
400391

401392
// Specify a custom property in nested object
402393
colors: {
403-
...MD3LightTheme.colors,
394+
...LightTheme.colors,
404395
brandPrimary: '#fefefe',
405396
brandSecondary: 'red',
406397
},
@@ -419,18 +410,18 @@ export default function Main() {
419410

420411
```ts
421412
import * as React from 'react';
422-
import { MD3LightTheme, PaperProvider, useTheme } from 'react-native-paper';
413+
import { LightTheme, PaperProvider, useTheme } from 'react-native-paper';
423414
import App from './src/App';
424415

425416
const theme = {
426-
...MD3LightTheme,
417+
...LightTheme,
427418

428419
// Specify a custom property
429420
custom: 'property',
430421

431422
// Specify a custom property in nested object
432423
colors: {
433-
...MD3LightTheme.colors,
424+
...LightTheme.colors,
434425
brandPrimary: '#fefefe',
435426
brandSecondary: 'red',
436427
},
@@ -466,7 +457,7 @@ export default function HomeScreen() {
466457

467458
## Material Design 3
468459

469-
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)).
460+
React Native Paper implements Material Design 3 exclusively. Customize the default experience by extending `LightTheme` or `DarkTheme` (see [Extending the theme](#extending-the-theme) and [Advanced theme overrides](#advanced-theme-overrides)).
470461

471462
## Applying a theme to a paper component
472463

@@ -509,19 +500,32 @@ Now you can use your `FancyButton` component everywhere instead of using `Button
509500

510501
## Dark Theme
511502

512-
Since 3.0 we adapt dark theme to follow [Material design guidelines](https://material.io/design/color/dark-theme.html). <br/>
513-
In contrast to light theme, dark theme by default uses `surface` colour instead of `primary` on large components like `AppBar` or `BottomNavigation`.<br/>
514-
The dark theme adds a white overlay with opacity depending on elevation of surfaces. It uses it for the better accentuation of surface elevation. Using only shadow is highly imperceptible on dark surfaces.
503+
React Native Paper follows the [Material Design 3 dark theme guidelines](https://m3.material.io/styles/color/dark-theme). Dark surfaces use tonal color overlays derived from the primary color to convey elevation.
504+
505+
`PaperProvider` automatically switches between `LightTheme` and `DarkTheme` based on the device color scheme. If you pass a custom `theme` prop, it is used as-is; you can toggle dark mode by changing `theme.dark` or swapping between your own light and dark theme objects.
506+
507+
### Using the operating system preferences
515508

516-
We are aware that users often use dark theme in their own ways and may not want to use the default dark theme features from the guidelines.<br/>
517-
That's why if you are using dark theme you can switch between two dark theme `mode`s:
509+
To follow the device's light/dark preference with your own themes, read it with React Native's `useColorScheme()` hook and pick the matching theme:
510+
511+
```tsx
512+
import * as React from 'react';
513+
import { useColorScheme } from 'react-native';
514+
import { DarkTheme, LightTheme, PaperProvider } from 'react-native-paper';
515+
import App from './src/App';
518516

519-
- `exact` where everything is like it was before. `Appbar` and `BottomNavigation` will still use primary colour by default.<br/>
520-
- `adaptive` where we follow [Material design guidelines](https://material.io/design/color/dark-theme.html), the surface will use white overlay with opacity to show elevation, `Appbar` and `BottomNavigation` will use surface colour as a background.
517+
export default function Main() {
518+
const scheme = useColorScheme();
521519

522-
If you don't use a custom theme, Paper will automatically change between the default theme and the default dark theme, depending on device settings.
520+
return (
521+
<PaperProvider theme={scheme === 'dark' ? DarkTheme : LightTheme}>
522+
<App />
523+
</PaperProvider>
524+
);
525+
}
526+
```
523527

524-
Otherwise, your custom theme will need to handle it manually, using React Native's [Appearance API](https://reactnative.dev/docs/appearance).
528+
The hook re-renders when the OS theme changes, so the swap is live.
525529

526530
## Gotchas
527531

docs/docs/guides/04-fonts.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,9 @@ Now, you are able to use `fontFamily` from font files.
4747
4848
## Configuring fonts in ThemeProvider
4949
50-
:::note
51-
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.
52-
:::
53-
54-
### Material Design 3
55-
5650
#### Variants
5751
58-
In the latest version fonts in theme are structured based on the `variant` keys e.g. `displayLarge` or `bodyMedium` which are then used in `Text`'s component throughout the whole library.
52+
Fonts in the theme are structured based on `variant` keys, e.g. `displayLarge` or `bodyMedium`, which are used by `Text` throughout the library.
5953
6054
:::info
6155
The default `fontFamily` is different per particular platfrom:
@@ -317,7 +311,7 @@ If any component uses Paper's `Text` component, without specified <b>variant</b>
317311
318312
```js
319313
import * as React from 'react';
320-
import { configureFonts, MD3LightTheme, PaperProvider } from 'react-native-paper';
314+
import { configureFonts, LightTheme, PaperProvider } from 'react-native-paper';
321315
import App from './src/App';
322316

323317
const fontConfig = {
@@ -335,7 +329,7 @@ const fontConfig = {
335329
};
336330

337331
const theme = {
338-
...MD3LightTheme,
332+
...LightTheme,
339333
fonts: configureFonts({config: fontConfig}),
340334
};
341335

@@ -362,7 +356,7 @@ export const Text = customText<'customVariant'>()
362356
363357
```js
364358
import * as React from 'react';
365-
import { configureFonts, MD3LightTheme, PaperProvider } from 'react-native-paper';
359+
import { configureFonts, LightTheme, PaperProvider } from 'react-native-paper';
366360
import App from './src/App';
367361

368362
const fontConfig = {
@@ -374,7 +368,7 @@ const fontConfig = {
374368
};
375369

376370
const theme = {
377-
...MD3LightTheme,
371+
...LightTheme,
378372
fonts: configureFonts({config: fontConfig}),
379373
};
380374

@@ -391,15 +385,15 @@ export default function Main() {
391385
392386
```js
393387
import * as React from 'react';
394-
import { configureFonts, MD3LightTheme, PaperProvider } from 'react-native-paper';
388+
import { configureFonts, LightTheme, PaperProvider } from 'react-native-paper';
395389
import App from './src/App';
396390

397391
const fontConfig = {
398392
fontFamily: 'NotoSans'
399393
};
400394

401395
const theme = {
402-
...MD3LightTheme,
396+
...LightTheme,
403397
fonts: configureFonts({config: fontConfig}),
404398
};
405399

0 commit comments

Comments
 (0)