You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b354fa9
Browse filesBrowse the repository at this point in the historyBrowse files
feat(theme)!: remove animation.scale and export useReduceMotion (#5235)
The 16 components that multiplied durations by `theme.animation.scale` now read `useReduceMotion()`, which is exported with the `ReduceMotionPreference` type. A component's `theme` prop can no longer turn animations back on under reduce motion, `'auto'` starts from the device setting at launch, and an OS setting change no longer replays Banner, CrossFadeIcon or ActivityIndicator animations.
BREAKING CHANGE: `theme.animation.scale` is removed; pass `reduceMotion="on"` to `PaperProvider` to turn animations off, and read the preference with `useReduceMotion()`.
Copy file name to clipboardExpand all lines: docs/6.x/docs/guides/migration.md
+33-3Lines changed: 33 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,34 @@ const MyComponent = () => {
42
42
};
43
43
```
44
44
45
+
### Reduce motion
46
+
47
+
The `animation` theme key and its `scale` were removed. The new `reduceMotion` prop of `PaperProvider` turns Paper's animations on or off instead:
48
+
49
+
-`'auto'` (default): follows the reduce motion setting of the device.
50
+
-`'on'`: turns Paper's animations off.
51
+
-`'off'`: keeps Paper's animations on, even when the device setting is on.
52
+
53
+
In 5.x, `PaperProvider` set the `scale` itself and replaced any `scale` in the theme passed to it, so a `scale` of `0` only turned animations off in a nested `ThemeProvider` or a component's `theme` prop. To turn animations off, for example in tests, remove that `scale` and pass `reduceMotion="on"` to `PaperProvider`:
If your app was written for a 6.0 alpha build, which also read a `scale` set on `PaperProvider`, remove it from that theme too.
66
+
67
+
Other `scale` values, which made animations slower or faster, have no replacement in 6.0. A `scale` in a component's `theme` prop, such as `theme={{ animation: { scale: 2 } }}`, does nothing now, and it can no longer turn animations back on while reduce motion is on. Paper ignores an `animation` left in your theme. TypeScript reports it in a theme object written inline in the `theme` prop of `PaperProvider` or a component, or typed as `Theme`, but not in the `theme` prop of `ThemeProvider`, which accepts any value, or in an untyped variable that also holds other theme keys.
68
+
69
+
In 5.x, `PaperProvider` also followed the device setting only when you passed no `theme`. In 6.x, `'auto'` follows the device setting with every theme, so if your app passes a custom theme, Paper's animations now stop when the user turns on reduce motion. 6.x also reads the setting when the app starts, while 5.x only reacted when it changed.
70
+
71
+
To follow the same preference in your own components, use the `useReduceMotion()` hook, which returns `true` when reduce motion is on. See [Reduce motion](./theming#reduce-motion) in the theming guide.
72
+
45
73
### Elevation
46
74
47
75
The `elevation` prop no longer accepts a React Native `Animated.Value` in the following components:
@@ -226,7 +254,7 @@ If you import it from Paper's type declarations instead, the path changed:
226
254
227
255
#### `roundness`
228
256
229
-
The `roundness` theme property was removed. Corner radii are now set in `theme.shapes.corner`, a scale of roles from `extraSmall` (4) to `extraExtraLarge` (48), and each component uses one fixed role. Paper ignores a `roundness` left in your theme, and TypeScript only reports it in a theme object written inline in a`theme` prop or typed as `Theme`.
257
+
The `roundness` theme property was removed. Corner radii are now set in `theme.shapes.corner`, a scale of roles from `extraSmall` (4) to `extraExtraLarge` (48), and each component uses one fixed role. Paper ignores a `roundness` left in your theme. TypeScript reports it in a theme object written inline in the`theme` prop of `PaperProvider`or a component, or typed as `Theme`, but not in the `theme` prop of `ThemeProvider`, which accepts any value, or in an untyped variable that also holds other theme keys.
230
258
231
259
In 5.x, each of these components multiplied `roundness` by a fixed number, and the 6.x defaults match the 5.x corners with the default `roundness` of 4. To port a custom `roundness`, set each role to your `roundness` times its multiplier:
232
260
@@ -278,7 +306,7 @@ A component's `theme` prop is merged deeply, so you can set only the role you ne
278
306
279
307
#### Removed keys
280
308
281
-
The 6.x theme has no `version`, `isV3`, `mode` or `animation.defaultAnimationDuration` keys. Paper 6 only supports Material Design 3, so `version` and `isV3` have nothing to select, and `mode` and `defaultAnimationDuration` have no replacement. Remove `version: 3` and `isV3` from your custom theme objects:
309
+
The 6.x theme has no `version`, `isV3`, `mode` or `animation` keys. Paper 6 only supports Material Design 3, so `version` and `isV3` have nothing to select. `mode` and `animation.defaultAnimationDuration` have no replacement, and `animation.scale` is replaced by the `reduceMotion` prop of `PaperProvider`, see [Reduce motion](#reduce-motion). Remove `version: 3` and `isV3` from your custom theme objects:
282
310
283
311
```diff
284
312
const theme = {
@@ -292,7 +320,7 @@ The 6.x theme has no `version`, `isV3`, `mode` or `animation.defaultAnimationDur
292
320
};
293
321
```
294
322
295
-
As with `roundness`, Paper ignores these keys, and TypeScript only reports them in a theme object written inline in a `theme` prop or typed as `Theme`. Code that reads `theme.isV3` gets `undefined` once the key is gone, so a check like `theme.isV3 ? a : b` takes the Material Design 2 branch. Keep only the Material Design 3 branch.
323
+
As with `roundness`, Paper ignores these keys, and TypeScript reports them in the same cases. Code that reads `theme.isV3` gets `undefined` once the key is gone, so a check like `theme.isV3 ? a : b` takes the Material Design 2 branch. Keep only the Material Design 3 branch.
296
324
297
325
#### `configureFonts`
298
326
@@ -390,6 +418,8 @@ On web, `Button`, `Card`, the `Chip` body, `FAB`, `FAB.Extended` and the `FAB.Me
390
418
391
419
Libraries built on Paper may not support 6.x yet. For example, `react-native-paper-dates` 0.24.1 still uses `HelperText`, the 5.x theme exports and `theme.roundness`, so its `DatePickerInput` crashes when it shows a validation error.
392
420
421
+
A library that reads `theme.animation.scale` to turn its own animations off should read `useReduceMotion()` instead. The 6.x theme has no `animation` key, so `theme.animation.scale` throws.
Copy file name to clipboardExpand all lines: docs/6.x/docs/guides/theming.mdx
+46-4Lines changed: 46 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,16 +134,58 @@ A theme usually contains the following properties:
134
134
-`fontWeight`
135
135
-`lineHeight`
136
136
-`fontSize`
137
-
-`animation` (`object`)
138
-
-`scale` - scale for all animations
139
137
140
138
When creating a custom theme, you only need to provide the properties you change. `PaperProvider` merges your theme deeply with the default one, so a nested object such as `shapes` or `motion` keeps every key you leave out.
141
139
142
140
Paper merges a custom theme onto `DarkTheme` when it sets `dark: true`, and onto `LightTheme` otherwise. The examples on this page still spread `LightTheme` or `DarkTheme`: that sets `dark`, and in TypeScript it gives the theme object the full `Theme` shape. Without TypeScript, nested spreads such as `...LightTheme.colors` are optional.
143
141
144
-
If you don't use a custom theme, Paper will automatically turn animations on/off, depending on device settings.
142
+
## Reduce motion
145
143
146
-
Otherwise, your custom theme will need to handle it manually, using React Native's [AccessibilityInfo API](https://reactnative.dev/docs/accessibilityinfo).
144
+
`PaperProvider` takes a `reduceMotion` prop, typed `ReduceMotionPreference`, that turns Paper's animations on or off:
145
+
146
+
-`'auto'` (default): follows the reduce motion setting of the device, read with React Native's [AccessibilityInfo API](https://reactnative.dev/docs/accessibilityinfo).
147
+
-`'on'`: turns Paper's animations off.
148
+
-`'off'`: keeps Paper's animations on, even when the device setting is on.
149
+
150
+
It works the same whether or not you pass a custom `theme`. With `'auto'`, Paper starts from the setting the device had when the app launched and follows every change after that.
151
+
152
+
When reduce motion is on, Paper's components skip their animations. A few still move: the `ActivityIndicator` rotation, the indeterminate `ProgressBar` and the `TouchableRipple` ripple on web. The `TextInput` label and active indicator follow only the device setting: they don't read the `reduceMotion` prop.
153
+
154
+
To turn Paper's animations off in tests and screenshots, whatever the device setting, pass `reduceMotion="on"`:
To follow the same preference in your own components, use the `useReduceMotion()` hook. It returns `true` when reduce motion is on. Reanimated's animations follow the device setting on their own too, so give them `ReduceMotion.Never` to leave the choice to the hook:
0 commit comments