Skip to content

Commit 64b3745

Browse files
committed
refactor: remove MD2 from all examples
1 parent 41cb4f3 commit 64b3745

28 files changed

+581
-810
lines changed

example/src/DrawerItems.tsx

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import {
1414
Text,
1515
TouchableRipple,
1616
Portal,
17+
useTheme,
1718
} from 'react-native-paper';
1819

1920
import { deviceColorsSupported, isWeb } from '../utils';
20-
import { useExampleTheme } from './hooks/useExampleTheme';
2121
import { PreferencesContext } from './PreferencesContext';
2222

2323
const DrawerItemsData = [
@@ -95,7 +95,7 @@ function DrawerItems() {
9595

9696
const _setDrawerItem = (index: number) => setDrawerItemIndex(index);
9797

98-
const { isV3, colors } = useExampleTheme();
98+
const { colors } = useTheme();
9999
const isIOS = Platform.OS === 'ios';
100100
const expoGoExecution =
101101
Constants.executionEnvironment === ExecutionEnvironment.StoreClient;
@@ -151,7 +151,7 @@ function DrawerItems() {
151151
},
152152
]}
153153
>
154-
{isV3 && collapsed && (
154+
{collapsed && (
155155
<Drawer.Section style={styles.collapsedSection}>
156156
{DrawerCollapsedItemsData.map((props, index) => (
157157
<Drawer.CollapsedItem
@@ -181,9 +181,9 @@ function DrawerItems() {
181181
</Drawer.Section>
182182

183183
<Drawer.Section title="Preferences">
184-
{deviceColorsSupported && isV3 ? (
184+
{deviceColorsSupported ? (
185185
<TouchableRipple onPress={toggleShouldUseDeviceColors}>
186-
<View style={[styles.preference, isV3 && styles.v3Preference]}>
186+
<View style={styles.preference}>
187187
<Text variant="labelLarge">Use device colors *</Text>
188188
<View pointerEvents="none">
189189
<Switch value={shouldUseDeviceColors} />
@@ -192,7 +192,7 @@ function DrawerItems() {
192192
</TouchableRipple>
193193
) : null}
194194
<TouchableRipple onPress={toggleTheme}>
195-
<View style={[styles.preference, isV3 && styles.v3Preference]}>
195+
<View style={styles.preference}>
196196
<Text variant="labelLarge">Dark Theme</Text>
197197
<View pointerEvents="none">
198198
<Switch value={isDarkTheme} />
@@ -202,7 +202,7 @@ function DrawerItems() {
202202

203203
{!isWeb && (
204204
<TouchableRipple onPress={_handleToggleRTL}>
205-
<View style={[styles.preference, isV3 && styles.v3Preference]}>
205+
<View style={styles.preference}>
206206
<Text variant="labelLarge">RTL</Text>
207207
<View pointerEvents="none">
208208
<Switch value={isRTL} />
@@ -211,30 +211,26 @@ function DrawerItems() {
211211
</TouchableRipple>
212212
)}
213213

214-
{isV3 && (
215-
<TouchableRipple onPress={toggleCollapsed}>
216-
<View style={[styles.preference, isV3 && styles.v3Preference]}>
217-
<Text variant="labelLarge">Collapsed drawer *</Text>
218-
<View pointerEvents="none">
219-
<Switch value={collapsed} />
220-
</View>
214+
<TouchableRipple onPress={toggleCollapsed}>
215+
<View style={styles.preference}>
216+
<Text variant="labelLarge">Collapsed drawer *</Text>
217+
<View pointerEvents="none">
218+
<Switch value={collapsed} />
221219
</View>
222-
</TouchableRipple>
223-
)}
220+
</View>
221+
</TouchableRipple>
224222

225-
{isV3 && (
226-
<TouchableRipple onPress={toggleCustomFont}>
227-
<View style={[styles.preference, isV3 && styles.v3Preference]}>
228-
<Text variant="labelLarge">Custom font *</Text>
229-
<View pointerEvents="none">
230-
<Switch value={customFontLoaded} />
231-
</View>
223+
<TouchableRipple onPress={toggleCustomFont}>
224+
<View style={styles.preference}>
225+
<Text variant="labelLarge">Custom font *</Text>
226+
<View pointerEvents="none">
227+
<Switch value={customFontLoaded} />
232228
</View>
233-
</TouchableRipple>
234-
)}
229+
</View>
230+
</TouchableRipple>
235231

236232
<TouchableRipple onPress={toggleRippleEffect}>
237-
<View style={[styles.preference, isV3 && styles.v3Preference]}>
233+
<View style={styles.preference}>
238234
<Text variant="labelLarge">
239235
{isIOS ? 'Highlight' : 'Ripple'} effect *
240236
</Text>
@@ -244,7 +240,7 @@ function DrawerItems() {
244240
</View>
245241
</TouchableRipple>
246242
</Drawer.Section>
247-
{isV3 && !collapsed && (
243+
{!collapsed && (
248244
<Text variant="bodySmall" style={styles.annotation}>
249245
* - available only for MD3
250246
</Text>
@@ -286,9 +282,6 @@ const styles = StyleSheet.create({
286282
justifyContent: 'space-between',
287283
alignItems: 'center',
288284
paddingVertical: 12,
289-
paddingHorizontal: 16,
290-
},
291-
v3Preference: {
292285
height: 56,
293286
paddingHorizontal: 28,
294287
},

example/src/ExampleList.tsx

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

44
import type { StackNavigationProp } from '@react-navigation/stack';
5-
import { Divider, List } from 'react-native-paper';
5+
import { Divider, List, useTheme } from 'react-native-paper';
66
import { useSafeAreaInsets } from 'react-native-safe-area-context';
77

88
import ActivityIndicatorExample from './Examples/ActivityIndicatorExample';
@@ -49,7 +49,6 @@ import ThemingWithReactNavigation from './Examples/ThemingWithReactNavigation';
4949
import ToggleButtonExample from './Examples/ToggleButtonExample';
5050
import TooltipExample from './Examples/TooltipExample';
5151
import TouchableRippleExample from './Examples/TouchableRippleExample';
52-
import { useExampleTheme } from './hooks/useExampleTheme';
5352

5453
export const mainExamples: Record<
5554
string,
@@ -132,16 +131,12 @@ const data = Object.keys(mainExamples).map(
132131
export default function ExampleList({ navigation }: Props) {
133132
const keyExtractor = (item: { id: string }) => item.id;
134133

135-
const { colors, isV3 } = useExampleTheme();
134+
const { colors } = useTheme();
136135
const safeArea = useSafeAreaInsets();
137136

138137
const renderItem = ({ item }: { item: Item }) => {
139138
const { data, id } = item;
140139

141-
if (!isV3 && data.title === mainExamples.themingWithReactNavigation.title) {
142-
return null;
143-
}
144-
145140
return (
146141
<List.Item
147142
unstable_pressDelay={65}

example/src/Examples/AnimatedFABExample/AnimatedFABExample.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ import type { NativeScrollEvent, NativeSyntheticEvent } from 'react-native';
33
import { Animated, FlatList, Platform, StyleSheet, View } from 'react-native';
44

55
import Icon from '@expo/vector-icons/MaterialCommunityIcons';
6-
import { Avatar, MD3Colors, Text } from 'react-native-paper';
6+
import { Avatar, MD3Colors, Text, useTheme } from 'react-native-paper';
77

88
import CustomFAB from './CustomFAB';
99
import CustomFABControls, {
1010
Controls,
1111
initialControls,
1212
} from './CustomFABControls';
1313
import { animatedFABExampleData } from '../../../utils';
14-
import { useExampleTheme } from '../../hooks/useExampleTheme';
1514

1615
type Item = {
1716
id: string;
@@ -26,7 +25,7 @@ type Item = {
2625
};
2726

2827
const AnimatedFABExample = () => {
29-
const { colors } = useExampleTheme();
28+
const { colors } = useTheme();
3029

3130
const isIOS = Platform.OS === 'ios';
3231

example/src/Examples/AnimatedFABExample/CustomFAB.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import {
99

1010
import { AnimatedFAB } from 'react-native-paper';
1111

12-
import { useExampleTheme } from '../../hooks/useExampleTheme';
13-
1412
type CustomFABProps = {
1513
animatedValue: Animated.Value;
1614
visible: boolean;
@@ -31,7 +29,6 @@ const CustomFAB = ({
3129
iconMode,
3230
}: CustomFABProps) => {
3331
const [isExtended, setIsExtended] = React.useState(true);
34-
const { isV3 } = useExampleTheme();
3532

3633
const isIOS = Platform.OS === 'ios';
3734

@@ -50,7 +47,7 @@ const CustomFAB = ({
5047
icon={'plus'}
5148
label={label}
5249
extended={isExtended}
53-
uppercase={!isV3}
50+
uppercase={false}
5451
onPress={() => console.log('Pressed')}
5552
visible={visible}
5653
animateFrom={animateFrom}

example/src/Examples/AnimatedFABExample/CustomFABControls.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import type {
66
AnimatedFABAnimateFrom,
77
AnimatedFABIconMode,
88
} from 'react-native-paper';
9-
import { Paragraph, RadioButton, Text } from 'react-native-paper';
10-
11-
import { useExampleTheme } from '../../hooks/useExampleTheme';
9+
import { RadioButton, Text, useTheme } from 'react-native-paper';
1210

1311
export type Controls = {
1412
iconMode: AnimatedFABIconMode;
@@ -40,19 +38,15 @@ const CustomControl = ({
4038
value,
4139
onChange,
4240
}: CustomControlProps) => {
43-
const { isV3 } = useExampleTheme();
44-
4541
const _renderItem = React.useCallback(
4642
({ item }: ListRenderItemInfo<(typeof options)[number]>) => {
47-
const TextComponent = isV3 ? Text : Paragraph;
48-
4943
return (
5044
<TouchableOpacity
5145
accessibilityRole="button"
5246
onPress={() => onChange(item)}
5347
style={styles.controlItem}
5448
>
55-
<TextComponent variant="labelLarge">{item}</TextComponent>
49+
<Text variant="labelLarge">{item}</Text>
5650

5751
<RadioButton
5852
value="dynamic"
@@ -61,18 +55,17 @@ const CustomControl = ({
6155
</TouchableOpacity>
6256
);
6357
},
64-
[value, onChange, isV3]
58+
[value, onChange]
6559
);
6660

6761
const _keyExtractor = React.useCallback(
6862
(item: (typeof options)[number]) => item,
6963
[]
7064
);
71-
const TextComponent = isV3 ? Text : Paragraph;
7265

7366
return (
7467
<View style={styles.controlWrapper}>
75-
<TextComponent variant="labelLarge">{name}</TextComponent>
68+
<Text variant="labelLarge">{name}</Text>
7669

7770
<FlatList
7871
horizontal
@@ -90,7 +83,7 @@ const CustomFABControls = ({
9083
setControls,
9184
controls: { animateFrom, iconMode },
9285
}: Props) => {
93-
const { colors } = useExampleTheme();
86+
const { colors } = useTheme();
9487

9588
const setIconMode = (newIconMode: AnimatedFABIconMode) =>
9689
setControls((state) => ({ ...state, iconMode: newIconMode }));

0 commit comments

Comments
 (0)