-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathPaperProvider.tsx
More file actions
72 lines (61 loc) · 2.28 KB
/
Copy pathPaperProvider.tsx
File metadata and controls
72 lines (61 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import * as React from 'react';
import { getDefaultDirection, LocaleProvider, type Direction } from './locale';
import SafeAreaProviderCompat from './SafeAreaProviderCompat';
import { Provider as SettingsProvider, Settings } from './settings';
import { defaultThemes, ThemeProvider } from './theming';
import {
useResolvedReduceMotion,
type ReduceMotionPreference,
} from './useResolvedReduceMotion';
import { useSystemColorScheme } from './useSystemColorScheme';
import MaterialCommunityIcon from '../components/MaterialCommunityIcon';
import PortalHost from '../components/Portal/PortalHost';
import { ReduceMotionContext } from '../theme/accessibility/ReduceMotionContext';
import type { ThemeProp } from '../types';
export type Props = {
children: React.ReactNode;
theme?: ThemeProp;
settings?: Settings;
direction?: Direction;
reduceMotion?: ReduceMotionPreference;
};
const PaperProvider = (props: Props) => {
const { reduceMotion = 'auto' } = props;
const colorScheme = useSystemColorScheme(!props.theme);
const resolvedReduceMotion = useResolvedReduceMotion(reduceMotion);
const theme = React.useMemo(() => {
const isDark = props.theme?.dark ?? colorScheme === 'dark';
const base = defaultThemes[isDark ? 'dark' : 'light'];
const scale = resolvedReduceMotion ? 0 : props.theme?.animation?.scale ?? 1;
return {
...base,
...props.theme,
colors: { ...base.colors, ...props.theme?.colors },
animation: { ...props.theme?.animation, scale },
};
}, [colorScheme, props.theme, resolvedReduceMotion]);
const { children, settings } = props;
const direction = props.direction ?? getDefaultDirection();
const settingsValue = React.useMemo(
() => ({
icon: MaterialCommunityIcon,
rippleEffectEnabled: true,
...settings,
}),
[settings]
);
return (
<SafeAreaProviderCompat>
<PortalHost>
<SettingsProvider value={settingsValue}>
<ReduceMotionContext.Provider value={resolvedReduceMotion}>
<LocaleProvider direction={direction}>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</LocaleProvider>
</ReduceMotionContext.Provider>
</SettingsProvider>
</PortalHost>
</SafeAreaProviderCompat>
);
};
export default PaperProvider;