@@ -7,6 +7,11 @@ import { defaultThemes, ThemeProvider } from './theming';
77import MaterialCommunityIcon from '../components/MaterialCommunityIcon' ;
88import PortalHost from '../components/Portal/PortalHost' ;
99import { useAccessibleTheme } from '../theme/accessibility' ;
10+ import {
11+ isDynamicColorSupported ,
12+ lightDynamicColors ,
13+ darkDynamicColors ,
14+ } from '../theme/schemes/DynamicTheme' ;
1015import type { Theme , ThemeProp } from '../types' ;
1116
1217export type Props = {
@@ -19,10 +24,17 @@ export type Props = {
1924 * accessibility in your own code.
2025 */
2126 accessibilityAdapters ?: boolean ;
27+ /**
28+ * Whether to use Android Material You (dynamic) colors from the system wallpaper seed.
29+ * When `true`, dynamic colors override `theme.colors` on Android API 31+.
30+ * Falls back silently on unsupported platforms and API levels.
31+ * Set to `false` (default) when providing a fully custom color theme.
32+ */
33+ dynamicColor ?: boolean ;
2234} ;
2335
2436const PaperProvider = ( props : Props ) => {
25- const { accessibilityAdapters = true } = props ;
37+ const { accessibilityAdapters = true , dynamicColor = false } = props ;
2638
2739 const colorSchemeName =
2840 ( ! props . theme && Appearance ?. getColorScheme ( ) ) || 'light' ;
@@ -59,17 +71,28 @@ const PaperProvider = (props: Props) => {
5971 } , [ props . theme ] ) ;
6072
6173 const rawTheme = React . useMemo ( ( ) => {
62- const scheme = colorScheme === 'dark' ? 'dark' : 'light' ;
74+ const effectiveDark = props . theme ?. dark ?? colorScheme === 'dark' ;
75+ const scheme = effectiveDark ? 'dark' : 'light' ;
6376 const base = defaultThemes [ scheme ] ;
77+ const isDynamic = dynamicColor && isDynamicColorSupported ;
78+ const dynamicColors = isDynamic
79+ ? scheme === 'dark'
80+ ? darkDynamicColors
81+ : lightDynamicColors
82+ : null ;
6483 return {
6584 ...base ,
6685 ...props . theme ,
86+ ...( dynamicColors
87+ ? { colors : { ...base . colors , ...dynamicColors } }
88+ : { } ) ,
6789 animation : {
6890 ...props . theme ?. animation ,
6991 scale : props . theme ?. animation ?. scale ?? 1 ,
7092 } ,
71- } as Theme ;
72- } , [ colorScheme , props . theme ] ) ;
93+ dynamic : isDynamic ,
94+ } as unknown as Theme ;
95+ } , [ colorScheme , props . theme , dynamicColor ] ) ;
7396
7497 const theme = useAccessibleTheme ( rawTheme , accessibilityAdapters !== false ) ;
7598
0 commit comments