@@ -11,34 +11,45 @@ import { useSystemColorScheme } from './useSystemColorScheme';
1111import MaterialCommunityIcon from '../components/MaterialCommunityIcon' ;
1212import PortalHost from '../components/Portal/PortalHost' ;
1313import { ReduceMotionContext } from '../theme/accessibility/ReduceMotionContext' ;
14+ import {
15+ isDynamicColorSupported ,
16+ lightDynamicColors ,
17+ darkDynamicColors ,
18+ } from '../theme/schemes/DynamicTheme' ;
1419import type { Theme , ThemeProp } from '../types' ;
1520
1621export type Props = {
1722 children : React . ReactNode ;
1823 theme ?: ThemeProp ;
1924 settings ?: Settings ;
2025 reduceMotion ?: ReduceMotionPreference ;
26+ dynamicColor ?: boolean ;
2127} ;
2228
2329const PaperProvider = ( props : Props ) => {
24- const { reduceMotion = 'auto' } = props ;
30+ const { reduceMotion = 'auto' , dynamicColor = false } = props ;
2531
2632 const colorScheme = useSystemColorScheme ( ! props . theme ) ;
2733 const resolvedReduceMotion = useResolvedReduceMotion ( reduceMotion ) ;
2834
2935 const theme = React . useMemo < Theme > ( ( ) => {
30- const scheme = colorScheme === 'dark' ? 'dark' : 'light' ;
31- const base = defaultThemes [ scheme ] ;
32- const userScale = props . theme ?. animation ?. scale ?? 1 ;
36+ const isDark = props . theme ?. dark ?? colorScheme === 'dark' ;
37+ const base = defaultThemes [ isDark ? 'dark' : 'light' ] ;
38+ const dynamicColors =
39+ dynamicColor && isDynamicColorSupported
40+ ? isDark
41+ ? darkDynamicColors
42+ : lightDynamicColors
43+ : undefined ;
44+ const scale = resolvedReduceMotion ? 0 : props . theme ?. animation ?. scale ?? 1 ;
45+
3346 return {
3447 ...base ,
3548 ...props . theme ,
36- animation : {
37- ...props . theme ?. animation ,
38- scale : resolvedReduceMotion ? 0 : userScale ,
39- } ,
49+ colors : { ...base . colors , ...props . theme ?. colors , ...dynamicColors } ,
50+ animation : { ...props . theme ?. animation , scale } ,
4051 } as Theme ;
41- } , [ colorScheme , props . theme , resolvedReduceMotion ] ) ;
52+ } , [ colorScheme , props . theme , resolvedReduceMotion , dynamicColor ] ) ;
4253
4354 const { children, settings } = props ;
4455
0 commit comments