Skip to content

Commit e44bc5a

Browse files
authored
refactor: remove isV3 and MD2 from components (#4727)
1 parent 9a4d323 commit e44bc5a

File tree

156 files changed

+1330
-4952
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+1330
-4952
lines changed

docs/docusaurus.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ const config = {
138138
ListItem: 'List/ListItem',
139139
ListSection: 'List/ListSection',
140140
ListSubheader: 'List/ListSubheader',
141+
ListImage: 'List/ListImage',
141142
},
142143
Menu: {
143144
Menu: 'Menu/Menu',

example/src/Examples/AnimatedFABExample/AnimatedFABExample.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ const AnimatedFABExample = () => {
2929

3030
const isIOS = Platform.OS === 'ios';
3131

32-
const [extended, setExtended] = React.useState<boolean>(true);
33-
const [visible, setVisible] = React.useState<boolean>(true);
34-
32+
const [extended, setExtended] = React.useState(true);
33+
const [visible, setVisible] = React.useState(true);
3534
const [controls, setControls] = React.useState<Controls>(initialControls);
3635

3736
const { current: velocity } = React.useRef<Animated.Value>(

example/src/Examples/BannerExample.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const PHOTOS = Array.from({ length: 24 }).map(
1717
);
1818

1919
const BannerExample = () => {
20-
const [visible, setVisible] = React.useState<boolean>(true);
21-
const [useCustomTheme, setUseCustomTheme] = React.useState<boolean>(false);
2220
const theme = useTheme();
2321

22+
const [visible, setVisible] = React.useState<boolean>(true);
23+
const [useCustomTheme, setUseCustomTheme] = React.useState<boolean>(false);
2424
const [height, setHeight] = React.useState(0);
2525

2626
const handleLayout = ({ nativeEvent }: LayoutChangeEvent) => {

example/src/Examples/ChipExample.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { Chip, List, MD3Colors, Snackbar, Text } from 'react-native-paper';
66

77
import ScreenWrapper from '../ScreenWrapper';
88

9+
const customColor = MD3Colors.error50;
10+
911
const ChipExample = () => {
1012
const [snackbarProperties, setSnackbarProperties] = React.useState({
1113
visible: false,
1214
text: '',
1315
});
14-
const customColor = MD3Colors.error50;
1516

1617
return (
1718
<>

example/src/Examples/ListSectionExample.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { StyleSheet, Image, View } from 'react-native';
33

4-
import { Caption, List, Text, Chip, Divider } from 'react-native-paper';
4+
import { List, Text, Chip, Divider } from 'react-native-paper';
55

66
import ScreenWrapper from '../ScreenWrapper';
77
const ListSectionExample = () => {
@@ -97,7 +97,7 @@ const ListSectionExample = () => {
9797
>
9898
List Item
9999
</Text>
100-
<Caption>Yesterday</Caption>
100+
<Text>Yesterday</Text>
101101
</View>
102102
)}
103103
description={({

example/src/Examples/ProgressBarExample.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ class ClassProgressBar extends React.Component {
2525
const AnimatedProgressBar = Animated.createAnimatedComponent(ClassProgressBar);
2626

2727
const ProgressBarExample = () => {
28-
const [visible, setVisible] = React.useState<boolean>(true);
29-
const [progress, setProgress] = React.useState<number>(0.3);
3028
const theme = useTheme();
29+
30+
const [visible, setVisible] = React.useState(true);
31+
const [progress, setProgress] = React.useState(0.3);
3132
const { current: progressBarValue } = React.useRef(new Animated.Value(0));
3233

3334
const runCustomAnimation = () => {

src/components/ActivityIndicator.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ const ActivityIndicator = ({
6363
theme: themeOverrides,
6464
...rest
6565
}: Props) => {
66-
const theme = useInternalTheme(themeOverrides);
66+
const {
67+
animation: { scale },
68+
colors: { primary },
69+
} = useInternalTheme(themeOverrides);
70+
6771
const { current: timer } = React.useRef<Animated.Value>(
6872
new Animated.Value(0)
6973
);
@@ -75,10 +79,6 @@ const ActivityIndicator = ({
7579
undefined
7680
);
7781

78-
const {
79-
animation: { scale },
80-
} = theme;
81-
8282
const startRotation = React.useCallback(() => {
8383
// Show indicator
8484
Animated.timing(fade, {
@@ -130,7 +130,7 @@ const ActivityIndicator = ({
130130
}
131131
}, [animating, fade, hidesWhenStopped, startRotation, scale, timer]);
132132

133-
const color = indicatorColor || theme.colors?.primary;
133+
const color = indicatorColor || primary;
134134
const size =
135135
typeof indicatorSize === 'string'
136136
? indicatorSize === 'small'

src/components/Appbar/Appbar.tsx

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import * as React from 'react';
22
import {
33
Animated,
4-
Platform,
54
StyleProp,
65
StyleSheet,
76
View,
87
ViewStyle,
98
ColorValue,
109
} from 'react-native';
1110

12-
import color from 'color';
13-
1411
import AppbarContent from './AppbarContent';
1512
import {
1613
AppbarModes,
17-
DEFAULT_APPBAR_HEIGHT,
1814
getAppbarBackgroundColor,
1915
modeAppbarHeight,
2016
renderAppbarContent,
@@ -165,11 +161,10 @@ const Appbar = ({
165161
...rest
166162
}: Props) => {
167163
const theme = useInternalTheme(themeOverrides);
168-
const { isV3 } = theme;
169164
const flattenedStyle = StyleSheet.flatten(style);
170165
const {
171166
backgroundColor: customBackground,
172-
elevation = isV3 ? (elevated ? 2 : 0) : 4,
167+
elevation = elevated ? 2 : 0,
173168
...restStyle
174169
} = (flattenedStyle || {}) as Exclude<typeof flattenedStyle, number> & {
175170
elevation?: number;
@@ -178,34 +173,26 @@ const Appbar = ({
178173

179174
const backgroundColor = getAppbarBackgroundColor(
180175
theme,
181-
elevation,
182176
customBackground,
183177
elevated
184178
);
185179

186180
const isMode = (modeToCompare: AppbarModes) => {
187-
return isV3 && mode === modeToCompare;
181+
return mode === modeToCompare;
188182
};
189183

190184
let isDark = false;
191185

192186
if (typeof dark === 'boolean') {
193187
isDark = dark;
194-
} else if (!isV3) {
195-
isDark =
196-
backgroundColor === 'transparent'
197-
? false
198-
: typeof backgroundColor === 'string'
199-
? !color(backgroundColor).isLight()
200-
: true;
201188
}
202189

203-
const isV3CenterAlignedMode = isV3 && isMode('center-aligned');
190+
const isCenterAlignedMode = isMode('center-aligned');
204191

205192
let shouldCenterContent = false;
206193
let shouldAddLeftSpacing = false;
207194
let shouldAddRightSpacing = false;
208-
if ((!isV3 && Platform.OS === 'ios') || isV3CenterAlignedMode) {
195+
if (isCenterAlignedMode) {
209196
let hasAppbarContent = false;
210197
let leftItemsCount = 0;
211198
let rightItemsCount = 0;
@@ -225,14 +212,12 @@ const Appbar = ({
225212
});
226213

227214
shouldCenterContent =
228-
hasAppbarContent &&
229-
leftItemsCount < 2 &&
230-
rightItemsCount < (isV3 ? 3 : 2);
215+
hasAppbarContent && leftItemsCount < 2 && rightItemsCount < 3;
231216
shouldAddLeftSpacing = shouldCenterContent && leftItemsCount === 0;
232217
shouldAddRightSpacing = shouldCenterContent && rightItemsCount === 0;
233218
}
234219

235-
const spacingStyle = isV3 ? styles.v3Spacing : styles.spacing;
220+
const spacingStyle = styles.v3Spacing;
236221

237222
const insets = {
238223
paddingBottom: safeAreaInsets?.bottom,
@@ -247,26 +232,24 @@ const Appbar = ({
247232
{ backgroundColor },
248233
styles.appbar,
249234
{
250-
height: isV3 ? modeAppbarHeight[mode] : DEFAULT_APPBAR_HEIGHT,
235+
height: modeAppbarHeight[mode],
251236
},
252237
insets,
253238
restStyle,
254-
!theme.isV3 && { elevation },
255239
]}
256240
elevation={elevation as MD3Elevation}
257241
{...rest}
258242
>
259243
{shouldAddLeftSpacing ? <View style={spacingStyle} /> : null}
260-
{(!isV3 || isMode('small') || isMode('center-aligned')) && (
244+
{(isMode('small') || isMode('center-aligned')) && (
261245
<>
262246
{/* Render only the back action at first place */}
263247
{renderAppbarContent({
264248
children,
265249
isDark,
266250
theme,
267-
isV3,
268251
renderOnly: ['Appbar.BackAction'],
269-
shouldCenterContent: isV3CenterAlignedMode || shouldCenterContent,
252+
shouldCenterContent: isCenterAlignedMode || shouldCenterContent,
270253
})}
271254
{/* Render the rest of the content except the back action */}
272255
{renderAppbarContent({
@@ -277,9 +260,8 @@ const Appbar = ({
277260
],
278261
isDark,
279262
theme,
280-
isV3,
281263
renderExcept: ['Appbar.BackAction'],
282-
shouldCenterContent: isV3CenterAlignedMode || shouldCenterContent,
264+
shouldCenterContent: isCenterAlignedMode || shouldCenterContent,
283265
})}
284266
</>
285267
)}
@@ -296,14 +278,12 @@ const Appbar = ({
296278
{renderAppbarContent({
297279
children,
298280
isDark,
299-
isV3,
300281
renderOnly: ['Appbar.BackAction'],
301282
mode,
302283
})}
303284
{renderAppbarContent({
304285
children: filterAppbarActions(children, true),
305286
isDark,
306-
isV3,
307287
renderOnly: ['Appbar.Action'],
308288
mode,
309289
})}
@@ -312,7 +292,6 @@ const Appbar = ({
312292
{renderAppbarContent({
313293
children: filterAppbarActions(children),
314294
isDark,
315-
isV3,
316295
renderExcept: [
317296
'Appbar',
318297
'Appbar.BackAction',
@@ -326,7 +305,6 @@ const Appbar = ({
326305
{renderAppbarContent({
327306
children,
328307
isDark,
329-
isV3,
330308
renderOnly: ['Appbar.Content'],
331309
mode,
332310
})}
@@ -343,9 +321,6 @@ const styles = StyleSheet.create({
343321
alignItems: 'center',
344322
paddingHorizontal: 4,
345323
},
346-
spacing: {
347-
width: 48,
348-
},
349324
v3Spacing: {
350325
width: 52,
351326
},

src/components/Appbar/AppbarAction.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import type {
77
ViewStyle,
88
} from 'react-native';
99

10-
import color from 'color';
1110
import type { ThemeProp } from 'src/types';
1211

1312
import { useInternalTheme } from '../../core/theming';
14-
import { black } from '../../styles/themes/v2/colors';
1513
import { forwardRef } from '../../utils/forwardRef';
1614
import type { IconSource } from '../Icon';
1715
import IconButton from '../IconButton/IconButton';
@@ -97,15 +95,15 @@ const AppbarAction = forwardRef<View, Props>(
9795
}: Props,
9896
ref
9997
) => {
100-
const theme = useInternalTheme(themeOverrides);
98+
const {
99+
colors: { onSurface, onSurfaceVariant },
100+
} = useInternalTheme(themeOverrides);
101101

102102
const actionIconColor = iconColor
103103
? iconColor
104-
: theme.isV3
105-
? isLeading
106-
? theme.colors.onSurface
107-
: theme.colors.onSurfaceVariant
108-
: color(black).alpha(0.54).rgb().string();
104+
: isLeading
105+
? onSurface
106+
: onSurfaceVariant;
109107

110108
return (
111109
<IconButton

0 commit comments

Comments
 (0)