Skip to content
Open
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
36 changes: 36 additions & 0 deletions docs/6.x/docs/guides/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ Components no longer read values from the `style` prop to derive other styles, s

- `Appbar` and `Appbar.Header`: `backgroundColor` and the border radius props (`borderRadius`, `borderTopLeftRadius` etc.) replace `style.backgroundColor` and the border radius in `style`
- `Avatar.Icon`, `Avatar.Image` and `Avatar.Text`: `backgroundColor` replaces `style.backgroundColor`
- `Banner`: `backgroundColor` replaces `style.backgroundColor`
- `Button`: `iconSize` replaces `labelStyle.fontSize` for the size of the icon and the loading indicator
- `Button`: `textColor` replaces `labelStyle.color` for the color of the icon and the loading indicator
- `Card`: `borderColor` replaces `style.borderColor` for the outline color
- `Menu`: `backgroundColor` replaces `contentStyle.backgroundColor`

`Tooltip` no longer reads positioning styles from the wrapped element. Apply them to a parent `View` wrapping the `Tooltip`, see [Tooltip](#tooltip).

Expand Down Expand Up @@ -558,6 +560,24 @@ e.g.:
+ </View>
```

### Banner

The banner background is now `theme.colors.surfaceContainerLow` by default and no longer depends on the `elevation` prop, which only controls the shadow. If you customized `theme.colors.elevation.level1` to change the banner background, customize `theme.colors.surfaceContainerLow` instead. With `LightTheme` and `DarkTheme`, the rendered color at the default `elevation` of `1` is unchanged. A banner with `elevation={0}` is no longer transparent. With `DynamicLightTheme` and `DynamicDarkTheme` on Android 12 and newer, the banner now uses the system surface color. To change the background of a single banner, use the new `backgroundColor` prop.

```diff
const theme = {
...LightTheme,
colors: {
...LightTheme.colors,
- elevation: {
- ...LightTheme.colors.elevation,
- level1: '#ffd8e4',
- },
+ surfaceContainerLow: '#ffd8e4',
},
};
```

### Surface

- The `elevation` prop no longer accepts a React Native `Animated.Value`. Any `elevation` changes are animated automatically.
Expand Down Expand Up @@ -887,6 +907,22 @@ The icon is 24dp, in `theme.colors.secondary`. `Dialog.Icon`'s `color` and `size

### Menu

The menu background is now `theme.colors.surfaceContainer` by default, following the Material Design 3 spec, and no longer depends on the `elevation` prop, which only controls the shadow. If you customized `theme.colors.elevation.level2` to change the menu background, customize `theme.colors.surfaceContainer` instead. With `LightTheme` and `DarkTheme`, the rendered color at the default `elevation` of `2` is unchanged. A menu with `elevation={0}` is no longer transparent. With `DynamicLightTheme` and `DynamicDarkTheme` on Android 12 and newer, the menu now uses the system surface color. To change the background of a single menu, use the new `backgroundColor` prop.

```diff
const theme = {
...LightTheme,
colors: {
...LightTheme.colors,
- elevation: {
- ...LightTheme.colors.elevation,
- level2: '#ffd8e4',
- },
+ surfaceContainer: '#ffd8e4',
},
};
```

The `overlayAccessibilityLabel` prop was renamed to `dismissAccessibilityLabel`:

```diff
Expand Down
2 changes: 1 addition & 1 deletion docs/6.x/docs/guides/theming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ A theme usually contains the following properties:
- `errorContainer`
- `onErrorContainer`

> Surfaces at elevation levels 0-5 are tinted via color overlays based on the primary color, such as app bars or menus. The addition of a grade from 0-5 introduces tonal variation to the surface baseline.
> Surfaces at elevation levels 1-5 use neutral surface tones, such as app bars. Menus and banners use the `surfaceContainer` and `surfaceContainerLow` roles instead. The addition of a grade from 0-5 introduces tonal variation to the surface baseline.
- `elevation` (`object`)
- `level0` - transparent
- `level1` - 5% opacity
Expand Down
3 changes: 2 additions & 1 deletion docs/src/data/themeColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const themeColors = {
},
Banner: {
'-': {
backgroundColor: 'theme.colors.surfaceContainerLow',
textColor: 'theme.colors.onSurface',
'action textColor': 'theme.colors.primary',
},
Expand Down Expand Up @@ -290,7 +291,7 @@ export const themeColors = {
},
Menu: {
'-': {
backgroundColor: 'theme.colors.elevation.level2',
backgroundColor: 'theme.colors.surfaceContainer',
},
},
'Menu.Item': {
Expand Down
5 changes: 1 addition & 4 deletions example/src/Examples/BannerExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ const BannerExample = () => {
colors: {
...defaultTheme.colors,
onSurface: Palette.tertiary100,
elevation: {
...defaultTheme.colors.elevation,
level1: Palette.tertiary50,
},
surfaceContainerLow: Palette.tertiary50,
primary: Palette.tertiary10,
},
};
Expand Down
10 changes: 9 additions & 1 deletion src/components/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import type {
ColorValue,
LayoutChangeEvent,
StyleProp,
ViewProps,
Expand Down Expand Up @@ -67,9 +68,14 @@ export type Props = Omit<ViewProps, 'style'> & {
contentStyle?: StyleProp<ViewStyle>;
/**
* @supported Available in v5.x with theme version 3
* Changes Banner shadow and background on iOS and Android.
* Changes Banner shadow on iOS and Android. The banner background is
* `theme.colors.surfaceContainerLow` and is not affected by `elevation`.
*/
elevation?: Elevation;
/**
* Background color of the banner. Overrides `theme.colors.surfaceContainerLow`.
*/
backgroundColor?: ColorValue;
/**
* Specifies the largest possible scale a text font can reach.
*/
Expand Down Expand Up @@ -143,6 +149,7 @@ const Banner = ({
actions = [],
contentStyle,
elevation = 1,
backgroundColor,
style,
theme: themeOverrides,
onShowAnimationFinished = () => {},
Expand Down Expand Up @@ -211,6 +218,7 @@ const Banner = ({
{...rest}
style={[surfaceStyle, style]}
theme={theme}
backgroundColor={backgroundColor ?? colors.surfaceContainerLow}
elevation={elevation}
>
<View style={[styles.wrapper, contentStyle]}>
Expand Down
15 changes: 12 additions & 3 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'react-native';
import type { KeyboardEvent as RNKeyboardEvent } from 'react-native';
import type {
ColorValue,
EmitterSubscription,
LayoutRectangle,
NativeEventSubscription,
Expand Down Expand Up @@ -83,14 +84,18 @@ export type Props = {
contentStyle?: StyleProp<SurfaceStyle>;
style?: StyleProp<ViewStyle>;
/**
* Elevation level of the menu's content. Shadow styles are calculated based on this value. Default `backgroundColor` is taken from the corresponding `theme.colors.elevation` property. By default equals `2`.
* Elevation level of the menu's content. Shadow styles are calculated based on this value. The menu background is `theme.colors.surfaceContainer` per the MD3 spec and is not affected by `elevation`. By default equals `2`.
* @supported Available in v5.x with theme version 3
*/
elevation?: Elevation;
/**
* Background color of the menu's content. Overrides `theme.colors.surfaceContainer`.
*/
backgroundColor?: ColorValue;
/**
* Mode of the menu's content.
* - `elevated` - Surface with a shadow and background color corresponding to set `elevation` value.
* - `flat` - Surface without a shadow, with the background color corresponding to set `elevation` value.
* - `elevated` - Surface with a shadow corresponding to set `elevation` value.
* - `flat` - Surface without a shadow.
*
* @supported Available in v5.x with theme version 3
*/
Expand Down Expand Up @@ -203,6 +208,7 @@ const Menu = ({
contentStyle,
style,
elevation = DEFAULT_ELEVATION,
backgroundColor,
mode = DEFAULT_MODE,
children,
theme: themeOverrides,
Expand Down Expand Up @@ -699,6 +705,9 @@ const Menu = ({
>
<Surface
mode={mode}
backgroundColor={
backgroundColor ?? theme.colors.surfaceContainer
}
borderRadius={theme.shapes.corner.extraSmall}
style={[
styles.shadowMenuContainer,
Expand Down
28 changes: 27 additions & 1 deletion src/components/__tests__/Banner.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { act } from '@testing-library/react-native';
import * as Reanimated from 'react-native-reanimated';

import PaperProvider from '../../core/PaperProvider';
import { render } from '../../test-utils';
import { render, screen } from '../../test-utils';
import { LightTheme } from '../../theme/schemes';
import { Palette } from '../../theme/tokens';
import Banner from '../Banner';

jest.mock('react-native-reanimated', () => {
Expand Down Expand Up @@ -119,6 +121,30 @@ it('renders visible banner, with action buttons and with image', async () => {
expect(tree).toMatchSnapshot();
});

it('renders banner on the theme surface container background', async () => {
await render(
<Banner visible testID="banner">
Text
</Banner>
);

expect(screen.getByTestId('banner')).toHaveStyle({
backgroundColor: LightTheme.colors.surfaceContainerLow,
});
});

it('renders banner with a custom background color', async () => {
await render(
<Banner visible testID="banner" backgroundColor={Palette.error60}>
Text
</Banner>
);

expect(screen.getByTestId('banner')).toHaveStyle({
backgroundColor: Palette.error60,
});
});

it('render visible banner, with custom theme', async () => {
const tree = (
await render(
Expand Down
28 changes: 26 additions & 2 deletions src/components/__tests__/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as Reanimated from 'react-native-reanimated';
import PaperProvider from '../../core/PaperProvider';
import { render } from '../../test-utils';
import { LightTheme } from '../../theme/schemes';
import { Palette } from '../../theme/tokens';
import type { Elevation } from '../../theme/types';
import Button from '../Button/Button';
import Menu from '../Menu/Menu';
Expand Down Expand Up @@ -172,7 +173,7 @@ const ViewPrototype: ComponentRef<typeof View> = View.prototype;
const elevations: Elevation[] = [0, 1, 2, 3, 4, 5];

elevations.forEach((elevation) =>
it(`renders menu with background color based on elevation value = ${elevation}`, async () => {
it(`keeps the same menu background at elevation ${elevation}`, async () => {
const testID = 'menu-with-elevation';

await render(
Expand All @@ -192,11 +193,34 @@ elevations.forEach((elevation) =>
);

expect(screen.getByTestId(testID)).toHaveStyle({
backgroundColor: LightTheme.colors.elevation[`level${elevation}`],
backgroundColor: LightTheme.colors.surfaceContainer,
});
})
);

it('renders menu with a custom background color', async () => {
const testID = 'menu-with-background-color';

await render(
<Portal.Host>
<Menu
visible
onDismiss={jest.fn()}
anchor={<Button mode="outlined">Open menu</Button>}
mode="flat"
backgroundColor={Palette.error60}
testID={testID}
>
<Menu.Item onPress={jest.fn()} title="Undo" />
</Menu>
</Portal.Host>
);

expect(screen.getByTestId(testID)).toHaveStyle({
backgroundColor: Palette.error60,
});
});

it('uses the default anchorPosition of top', async () => {
const testID = 'top-positioned-menu';
const dimensionsSpy = jest.spyOn(Dimensions, 'get').mockReturnValue({
Expand Down
Loading