Skip to content

Commit ce31b01

Browse files
committed
refactor: remove MD2 theme related code
1 parent 08d5ed9 commit ce31b01

File tree

17 files changed

+33
-693
lines changed

17 files changed

+33
-693
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ lib/
7171
!.yarn/plugins
7272
!.yarn/releases
7373
!.yarn/sdks
74-
!.yarn/versions
74+
!.yarn/versions
75+
76+
example/ios/*

example/src/DrawerItems.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
Button,
1010
Dialog,
1111
Drawer,
12-
MD2Colors,
1312
MD3Colors,
1413
Switch,
1514
Text,
@@ -107,7 +106,6 @@ function DrawerItems() {
107106
toggleShouldUseDeviceColors,
108107
toggleTheme,
109108
toggleRtl: toggleRTL,
110-
toggleThemeVersion,
111109
toggleCollapsed,
112110
toggleCustomFont,
113111
toggleRippleEffect,
@@ -137,14 +135,10 @@ function DrawerItems() {
137135
};
138136

139137
const coloredLabelTheme = {
140-
colors: isV3
141-
? {
142-
secondaryContainer: MD3Colors.tertiary80,
143-
onSecondaryContainer: MD3Colors.tertiary20,
144-
}
145-
: {
146-
primary: MD2Colors.tealA200,
147-
},
138+
colors: {
139+
secondaryContainer: MD3Colors.tertiary80,
140+
onSecondaryContainer: MD3Colors.tertiary20,
141+
},
148142
};
149143

150144
return (
@@ -217,15 +211,6 @@ function DrawerItems() {
217211
</TouchableRipple>
218212
)}
219213

220-
<TouchableRipple onPress={toggleThemeVersion}>
221-
<View style={[styles.preference, isV3 && styles.v3Preference]}>
222-
<Text variant="labelLarge">MD 2</Text>
223-
<View pointerEvents="none">
224-
<Switch value={!isV3} />
225-
</View>
226-
</View>
227-
</TouchableRipple>
228-
229214
{isV3 && (
230215
<TouchableRipple onPress={toggleCollapsed}>
231216
<View style={[styles.preference, isV3 && styles.v3Preference]}>

example/src/index.native.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ import { useFonts } from 'expo-font';
99
import { useKeepAwake } from 'expo-keep-awake';
1010
import { StatusBar } from 'expo-status-bar';
1111
import * as Updates from 'expo-updates';
12-
import {
13-
PaperProvider,
14-
MD2DarkTheme,
15-
MD2LightTheme,
16-
MD3DarkTheme,
17-
MD3LightTheme,
18-
} from 'react-native-paper';
12+
import { PaperProvider, MD3DarkTheme, MD3LightTheme } from 'react-native-paper';
1913
import { SafeAreaInsetsContext } from 'react-native-safe-area-context';
2014

2115
import DrawerItems from './DrawerItems';
@@ -49,7 +43,7 @@ export default function PaperExample() {
4943
const [shouldUseDeviceColors, setShouldUseDeviceColors] =
5044
React.useState(true);
5145
const [isDarkMode, setIsDarkMode] = React.useState(false);
52-
const [themeVersion, setThemeVersion] = React.useState<2 | 3>(3);
46+
const [_, setThemeVersion] = React.useState<2 | 3>(3);
5347
const [rtl, setRtl] = React.useState<boolean>(
5448
I18nManager.getConstants().isRTL
5549
);
@@ -59,18 +53,14 @@ export default function PaperExample() {
5953

6054
const { theme: mdTheme } = useMaterial3Theme();
6155
const theme = React.useMemo(() => {
62-
if (themeVersion === 2) {
63-
return isDarkMode ? MD2DarkTheme : MD2LightTheme;
64-
}
65-
6656
if (!deviceColorsSupported || !shouldUseDeviceColors) {
6757
return isDarkMode ? MD3DarkTheme : MD3LightTheme;
6858
}
6959

7060
return isDarkMode
7161
? { ...MD3DarkTheme, colors: mdTheme.dark }
7262
: { ...MD3LightTheme, colors: mdTheme.light };
73-
}, [isDarkMode, mdTheme, shouldUseDeviceColors, themeVersion]);
63+
}, [isDarkMode, mdTheme, shouldUseDeviceColors]);
7464

7565
React.useEffect(() => {
7666
const restoreState = async () => {

example/src/index.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ import { createDrawerNavigator } from '@react-navigation/drawer';
55
import { InitialState, NavigationContainer } from '@react-navigation/native';
66
import { useFonts } from 'expo-font';
77
import { useKeepAwake } from 'expo-keep-awake';
8-
import {
9-
PaperProvider,
10-
MD3DarkTheme,
11-
MD3LightTheme,
12-
MD2DarkTheme,
13-
MD2LightTheme,
14-
} from 'react-native-paper';
8+
import { PaperProvider, MD3DarkTheme, MD3LightTheme } from 'react-native-paper';
159
import { SafeAreaInsetsContext } from 'react-native-safe-area-context';
1610

1711
import DrawerItems from './DrawerItems';
@@ -43,18 +37,14 @@ export default function PaperExample() {
4337
>();
4438

4539
const [isDarkMode, setIsDarkMode] = React.useState(false);
46-
const [themeVersion, setThemeVersion] = React.useState<2 | 3>(3);
40+
const [_, setThemeVersion] = React.useState<2 | 3>(3);
4741
const [collapsed, setCollapsed] = React.useState(false);
4842
const [customFontLoaded, setCustomFont] = React.useState(false);
4943
const [rippleEffectEnabled, setRippleEffectEnabled] = React.useState(true);
5044

5145
const theme = React.useMemo(() => {
52-
if (themeVersion === 2) {
53-
return isDarkMode ? MD2DarkTheme : MD2LightTheme;
54-
}
55-
5646
return isDarkMode ? MD3DarkTheme : MD3LightTheme;
57-
}, [isDarkMode, themeVersion]);
47+
}, [isDarkMode]);
5848

5949
React.useEffect(() => {
6050
const restoreState = async () => {

src/components/Badge.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ const Badge = ({
8888
const {
8989
backgroundColor = theme.isV3
9090
? theme.colors.error
91-
: theme.colors?.notification,
91+
: // @ts-expect-error TODO: Remove it
92+
theme.colors?.notification,
9293
...restStyle
9394
} = (StyleSheet.flatten(style) || {}) as TextStyle;
9495

@@ -109,7 +110,6 @@ const Badge = ({
109110
backgroundColor,
110111
color: textColor,
111112
fontSize: size * 0.5,
112-
...(!theme.isV3 && theme.fonts.regular),
113113
lineHeight: size / fontScale,
114114
height: size,
115115
minWidth: size,

src/components/Surface.tsx

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from 'react-native';
1111

1212
import { useInternalTheme } from '../core/theming';
13-
import overlay, { isAnimatedValue } from '../styles/overlay';
13+
import { isAnimatedValue } from '../styles/overlay';
1414
import shadow from '../styles/shadow';
1515
import type { ThemeProp, MD3Elevation } from '../types';
1616
import { forwardRef } from '../utils/forwardRef';
@@ -53,30 +53,6 @@ export type Props = Omit<React.ComponentPropsWithRef<typeof View>, 'style'> & {
5353
ref?: React.RefObject<View>;
5454
};
5555

56-
const MD2Surface = forwardRef<View, Props>(
57-
({ style, theme: overrideTheme, ...rest }: Omit<Props, 'elevation'>, ref) => {
58-
const { elevation = 4 } = (StyleSheet.flatten(style) || {}) as ViewStyle;
59-
const { dark: isDarkTheme, mode, colors } = useInternalTheme(overrideTheme);
60-
61-
return (
62-
<Animated.View
63-
ref={ref}
64-
{...rest}
65-
style={[
66-
{
67-
backgroundColor:
68-
isDarkTheme && mode === 'adaptive'
69-
? overlay(elevation, colors?.surface)
70-
: colors?.surface,
71-
},
72-
elevation ? shadow(elevation) : null,
73-
style,
74-
]}
75-
/>
76-
);
77-
}
78-
);
79-
8056
const outerLayerStyleProperties: (keyof ViewStyle)[] = [
8157
'position',
8258
'alignSelf',
@@ -269,13 +245,6 @@ const Surface = forwardRef<View, Props>(
269245
) => {
270246
const theme = useInternalTheme(overridenTheme);
271247

272-
if (!theme.isV3)
273-
return (
274-
<MD2Surface {...props} theme={theme} style={style} ref={ref}>
275-
{children}
276-
</MD2Surface>
277-
);
278-
279248
const { colors } = theme;
280249

281250
const inputRange = [0, 1, 2, 3, 4, 5];

src/core/PaperProvider.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,12 @@ const PaperProvider = (props: Props) => {
7777
}, [props.theme, isOnlyVersionInTheme]);
7878

7979
const theme = React.useMemo(() => {
80-
const themeVersion = props.theme?.version || 3;
8180
const scheme = colorScheme || 'light';
82-
const defaultThemeBase = defaultThemesByVersion[themeVersion][scheme];
81+
const defaultThemeBase = defaultThemesByVersion[scheme];
8382

8483
const extendedThemeBase = {
8584
...defaultThemeBase,
8685
...props.theme,
87-
version: themeVersion,
8886
animation: {
8987
...props.theme?.animation,
9088
scale: reduceMotionEnabled ? 0 : 1,
@@ -93,7 +91,8 @@ const PaperProvider = (props: Props) => {
9391

9492
return {
9593
...extendedThemeBase,
96-
isV3: extendedThemeBase.version === 3,
94+
// TODO: Remove it completely
95+
isV3: true,
9796
};
9897
}, [colorScheme, props.theme, reduceMotionEnabled]);
9998

src/core/theming.tsx

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ import type { ComponentType } from 'react';
33
import { $DeepPartial, createTheming } from '@callstack/react-theme-provider';
44
import color from 'color';
55

6-
import {
7-
MD2DarkTheme,
8-
MD2LightTheme,
9-
MD3DarkTheme,
10-
MD3LightTheme,
11-
} from '../styles/themes';
6+
import { MD3DarkTheme, MD3LightTheme } from '../styles/themes';
127
import type {
138
InternalTheme,
149
MD3Theme,
@@ -37,29 +32,16 @@ export const withInternalTheme = <Props extends { theme: InternalTheme }, C>(
3732
) => withTheme<Props, C>(WrappedComponent);
3833

3934
export const defaultThemesByVersion = {
40-
2: {
41-
light: MD2LightTheme,
42-
dark: MD2DarkTheme,
43-
},
44-
3: {
45-
light: MD3LightTheme,
46-
dark: MD3DarkTheme,
47-
},
35+
light: MD3LightTheme,
36+
dark: MD3DarkTheme,
4837
};
4938

50-
export const getTheme = <
51-
Scheme extends boolean = false,
52-
IsVersion3 extends boolean = true
53-
>(
54-
isDark: Scheme = false as Scheme,
55-
isV3: IsVersion3 = true as IsVersion3
56-
): (typeof defaultThemesByVersion)[IsVersion3 extends true
57-
? 3
58-
: 2][Scheme extends true ? 'dark' : 'light'] => {
59-
const themeVersion = isV3 ? 3 : 2;
39+
export const getTheme = <Scheme extends boolean = false>(
40+
isDark: Scheme = false as Scheme
41+
): (typeof defaultThemesByVersion)[Scheme extends true ? 'dark' : 'light'] => {
6042
const scheme = isDark ? 'dark' : 'light';
6143

62-
return defaultThemesByVersion[themeVersion][scheme];
44+
return defaultThemesByVersion[scheme];
6345
};
6446

6547
// eslint-disable-next-line no-redeclare

src/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ export * from './styles/themes';
1313
export { default as Provider } from './core/PaperProvider';
1414
export { default as PaperProvider } from './core/PaperProvider';
1515
export { default as shadow } from './styles/shadow';
16-
export { default as overlay } from './styles/overlay';
1716
export { default as configureFonts } from './styles/fonts';
1817

1918
import * as Avatar from './components/Avatar/Avatar';
2019
import * as Drawer from './components/Drawer/Drawer';
2120
import * as List from './components/List/List';
22-
import * as MD2Colors from './styles/themes/v2/colors';
2321

24-
export { MD2Colors };
2522
export { Avatar, List, Drawer };
2623

2724
export * from './components/FAB/AnimatedFAB';
@@ -161,7 +158,6 @@ export type {
161158
} from './react-navigation';
162159

163160
export type {
164-
MD2Theme,
165161
MD3Theme,
166162
ThemeBase,
167163
MD3Elevation,

0 commit comments

Comments
 (0)