(props: Props)
| 21 | }; |
| 22 | |
| 23 | const PaperProvider = (props: Props) => { |
| 24 | const isOnlyVersionInTheme = |
| 25 | props.theme && Object.keys(props.theme).length === 1 && props.theme.version; |
| 26 | |
| 27 | const colorSchemeName = |
| 28 | ((!props.theme || isOnlyVersionInTheme) && Appearance?.getColorScheme()) || |
| 29 | 'light'; |
| 30 | |
| 31 | const [reduceMotionEnabled, setReduceMotionEnabled] = |
| 32 | React.useState<boolean>(false); |
| 33 | const [colorScheme, setColorScheme] = |
| 34 | React.useState<ColorSchemeName>(colorSchemeName); |
| 35 | |
| 36 | const handleAppearanceChange = ( |
| 37 | preferences: Appearance.AppearancePreferences |
| 38 | ) => { |
| 39 | const { colorScheme } = preferences; |
| 40 | setColorScheme(colorScheme); |
| 41 | }; |
| 42 | |
| 43 | React.useEffect(() => { |
| 44 | let subscription: NativeEventSubscription | undefined; |
| 45 | |
| 46 | if (!props.theme) { |
| 47 | subscription = addEventListener( |
| 48 | AccessibilityInfo, |
| 49 | 'reduceMotionChanged', |
| 50 | setReduceMotionEnabled |
| 51 | ); |
| 52 | } |
| 53 | return () => { |
| 54 | if (!props.theme) { |
| 55 | subscription?.remove(); |
| 56 | } |
| 57 | }; |
| 58 | }, [props.theme]); |
| 59 | |
| 60 | React.useEffect(() => { |
| 61 | let appearanceSubscription: NativeEventSubscription | undefined; |
| 62 | if (!props.theme || isOnlyVersionInTheme) { |
| 63 | appearanceSubscription = Appearance?.addChangeListener( |
| 64 | handleAppearanceChange |
| 65 | ) as NativeEventSubscription | undefined; |
| 66 | } |
| 67 | return () => { |
| 68 | if (!props.theme || isOnlyVersionInTheme) { |
| 69 | if (appearanceSubscription) { |
| 70 | appearanceSubscription.remove(); |
| 71 | } else { |
| 72 | // @ts-expect-error: We keep deprecated listener remove method for backwards compat with old RN versions |
| 73 | Appearance?.removeChangeListener(handleAppearanceChange); |
| 74 | } |
| 75 | } |
| 76 | }; |
| 77 | }, [props.theme, isOnlyVersionInTheme]); |
| 78 | |
| 79 | const theme = React.useMemo(() => { |
| 80 | const themeVersion = props.theme?.version || 3; |
nothing calls this directly
no test coverage detected
searching dependent graphs…