@@ -12,6 +12,11 @@ import { useSystemColorScheme } from './useSystemColorScheme';
1212import MaterialCommunityIcon from '../components/MaterialCommunityIcon' ;
1313import PortalHost from '../components/Portal/PortalHost' ;
1414import { ReduceMotionContext } from '../theme/accessibility/ReduceMotionContext' ;
15+ import {
16+ isDynamicColorSupported ,
17+ lightDynamicColors ,
18+ darkDynamicColors ,
19+ } from '../theme/schemes/DynamicTheme' ;
1520import type { ThemeProp } from '../types' ;
1621
1722export type Props = {
@@ -20,28 +25,33 @@ export type Props = {
2025 settings ?: Settings ;
2126 direction ?: Direction ;
2227 reduceMotion ?: ReduceMotionPreference ;
28+ dynamicColor ?: boolean ;
2329} ;
2430
2531const PaperProvider = ( props : Props ) => {
26- const { reduceMotion = 'auto' } = props ;
32+ const { reduceMotion = 'auto' , dynamicColor = false } = props ;
2733
2834 const colorScheme = useSystemColorScheme ( ! props . theme ) ;
2935 const resolvedReduceMotion = useResolvedReduceMotion ( reduceMotion ) ;
3036
3137 const theme = React . useMemo ( ( ) => {
32- const scheme = colorScheme === 'dark' ? 'dark' : 'light' ;
33- const defaultThemeBase = defaultThemes [ scheme ] ;
34- const userScale = props . theme ?. animation ?. scale ?? 1 ;
38+ const isDark = props . theme ?. dark ?? colorScheme === 'dark' ;
39+ const base = defaultThemes [ isDark ? 'dark' : 'light' ] ;
40+ const dynamicColors =
41+ dynamicColor && isDynamicColorSupported
42+ ? isDark
43+ ? darkDynamicColors
44+ : lightDynamicColors
45+ : undefined ;
46+ const scale = resolvedReduceMotion ? 0 : props . theme ?. animation ?. scale ?? 1 ;
3547
3648 return {
37- ...defaultThemeBase ,
49+ ...base ,
3850 ...props . theme ,
39- animation : {
40- ...props . theme ?. animation ,
41- scale : resolvedReduceMotion ? 0 : userScale ,
42- } ,
51+ colors : { ...base . colors , ...props . theme ?. colors , ...dynamicColors } ,
52+ animation : { ...props . theme ?. animation , scale } ,
4353 } ;
44- } , [ colorScheme , props . theme , resolvedReduceMotion ] ) ;
54+ } , [ colorScheme , props . theme , resolvedReduceMotion , dynamicColor ] ) ;
4555
4656 const { children, settings } = props ;
4757
0 commit comments