11import * as React from 'react' ;
2- import { Appearance , ColorSchemeName } from 'react-native' ;
32
43import SafeAreaProviderCompat from './SafeAreaProviderCompat' ;
54import { Provider as SettingsProvider , Settings } from './settings' ;
65import { defaultThemes , ThemeProvider } from './theming' ;
6+ import { useSystemColorScheme } from './useSystemColorScheme' ;
77import MaterialCommunityIcon from '../components/MaterialCommunityIcon' ;
88import PortalHost from '../components/Portal/PortalHost' ;
99import { ReduceMotionContext } from '../theme/accessibility/ReduceMotionContext' ;
@@ -23,42 +23,9 @@ export type Props = {
2323const PaperProvider = ( props : Props ) => {
2424 const { reduceMotion = 'auto' } = props ;
2525
26- const colorSchemeName =
27- ( ! props . theme && Appearance ?. getColorScheme ( ) ) || 'light' ;
28-
29- const [ colorScheme , setColorScheme ] =
30- React . useState < ColorSchemeName > ( colorSchemeName ) ;
31-
26+ const colorScheme = useSystemColorScheme ( ! props . theme ) ;
3227 const resolvedReduceMotion = useResolvedReduceMotion ( reduceMotion ) ;
3328
34- const handleAppearanceChange = (
35- preferences : Appearance . AppearancePreferences
36- ) => {
37- const { colorScheme } = preferences ;
38- setColorScheme ( colorScheme ) ;
39- } ;
40-
41- React . useEffect ( ( ) => {
42- let appearanceSubscription :
43- | ReturnType < typeof Appearance . addChangeListener >
44- | undefined ;
45- if ( ! props . theme ) {
46- appearanceSubscription = Appearance ?. addChangeListener (
47- handleAppearanceChange
48- ) as typeof appearanceSubscription ;
49- }
50- return ( ) => {
51- if ( ! props . theme ) {
52- if ( appearanceSubscription ) {
53- appearanceSubscription . remove ( ) ;
54- } else {
55- // @ts -expect-error: We keep deprecated listener remove method for backwards compat with old RN versions
56- Appearance ?. removeChangeListener ( handleAppearanceChange ) ;
57- }
58- }
59- } ;
60- } , [ props . theme ] ) ;
61-
6229 const theme = React . useMemo < Theme > ( ( ) => {
6330 const scheme = colorScheme === 'dark' ? 'dark' : 'light' ;
6431 const base = defaultThemes [ scheme ] ;
0 commit comments