-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathprovider.tsx
More file actions
136 lines (118 loc) · 3.83 KB
/
Copy pathprovider.tsx
File metadata and controls
136 lines (118 loc) · 3.83 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import type { ComponentType } from 'react';
import { $DeepPartial, createTheming } from '@callstack/react-theme-provider';
import { DarkTheme, LightTheme } from './schemes';
import type { Theme, NavigationTheme } from './types';
export const {
ThemeProvider,
withTheme,
useTheme: useAppTheme,
} = createTheming<unknown>(LightTheme);
export function useTheme<T = Theme>(overrides?: $DeepPartial<T>) {
return useAppTheme<T>(overrides);
}
export const useInternalTheme = (
themeOverrides: $DeepPartial<Theme> | undefined
) => useAppTheme<Theme>(themeOverrides);
export const withInternalTheme = <Props extends { theme: Theme }, C>(
WrappedComponent: ComponentType<Props & { theme: Theme }> & C
) => withTheme<Props, C>(WrappedComponent);
export const defaultThemes = {
light: LightTheme,
dark: DarkTheme,
};
export const getTheme = <Scheme extends boolean = false>(
isDark: Scheme = false as Scheme
): (typeof defaultThemes)[Scheme extends true ? 'dark' : 'light'] => {
const scheme = isDark ? 'dark' : 'light';
return defaultThemes[scheme];
};
// eslint-disable-next-line no-redeclare
export function adaptNavigationTheme<T extends NavigationTheme>(themes: {
reactNavigationLight: T;
materialLight?: Theme;
}): {
LightTheme: NavigationTheme;
};
// eslint-disable-next-line no-redeclare
export function adaptNavigationTheme<T extends NavigationTheme>(themes: {
reactNavigationDark: T;
materialDark?: Theme;
}): {
DarkTheme: NavigationTheme;
};
// eslint-disable-next-line no-redeclare
export function adaptNavigationTheme<
TLight extends NavigationTheme,
TDark extends NavigationTheme
>(themes: {
reactNavigationLight: TLight;
reactNavigationDark: TDark;
materialLight?: Theme;
materialDark?: Theme;
}): { LightTheme: TLight; DarkTheme: TDark };
// eslint-disable-next-line no-redeclare
export function adaptNavigationTheme(themes: any) {
const {
reactNavigationLight,
reactNavigationDark,
materialLight,
materialDark,
} = themes;
const MD3Themes = {
light: materialLight || LightTheme,
dark: materialDark || DarkTheme,
};
const result: { LightTheme?: any; DarkTheme?: any } = {};
if (reactNavigationLight) {
result.LightTheme = getAdaptedTheme(reactNavigationLight, MD3Themes.light);
}
if (reactNavigationDark) {
result.DarkTheme = getAdaptedTheme(reactNavigationDark, MD3Themes.dark);
}
return result;
}
const getAdaptedTheme = <T extends NavigationTheme>(
theme: T,
materialTheme: Theme
): T => {
const base = {
...theme,
colors: {
...theme.colors,
primary: materialTheme.colors.primary,
background: materialTheme.colors.background,
card: materialTheme.colors.surfaceContainer,
text: materialTheme.colors.onSurface,
border: materialTheme.colors.outline,
notification: materialTheme.colors.error,
},
};
if ('fonts' in theme) {
return {
...base,
fonts: {
regular: {
fontFamily: materialTheme.fonts.bodyMedium.fontFamily,
fontWeight: materialTheme.fonts.bodyMedium.fontWeight,
letterSpacing: materialTheme.fonts.bodyMedium.letterSpacing,
},
medium: {
fontFamily: materialTheme.fonts.titleMedium.fontFamily,
fontWeight: materialTheme.fonts.titleMedium.fontWeight,
letterSpacing: materialTheme.fonts.titleMedium.letterSpacing,
},
bold: {
fontFamily: materialTheme.fonts.headlineSmall.fontFamily,
fontWeight: materialTheme.fonts.headlineSmall.fontWeight,
letterSpacing: materialTheme.fonts.headlineSmall.letterSpacing,
},
heavy: {
fontFamily: materialTheme.fonts.headlineLarge.fontFamily,
fontWeight: materialTheme.fonts.headlineLarge.fontWeight,
letterSpacing: materialTheme.fonts.headlineLarge.letterSpacing,
},
},
};
}
return base;
};