diff --git a/example/src/DrawerItems.tsx b/example/src/DrawerItems.tsx index 2d3ca6c202..44d5163cbf 100644 --- a/example/src/DrawerItems.tsx +++ b/example/src/DrawerItems.tsx @@ -9,16 +9,15 @@ import { Button, Dialog, Drawer, - MD2Colors, MD3Colors, Switch, Text, TouchableRipple, Portal, + useTheme, } from 'react-native-paper'; import { deviceColorsSupported, isWeb } from '../utils'; -import { useExampleTheme } from './hooks/useExampleTheme'; import { PreferencesContext } from './PreferencesContext'; const DrawerItemsData = [ @@ -96,7 +95,7 @@ function DrawerItems() { const _setDrawerItem = (index: number) => setDrawerItemIndex(index); - const { isV3, colors } = useExampleTheme(); + const { colors } = useTheme(); const isIOS = Platform.OS === 'ios'; const expoGoExecution = Constants.executionEnvironment === ExecutionEnvironment.StoreClient; @@ -107,7 +106,6 @@ function DrawerItems() { toggleShouldUseDeviceColors, toggleTheme, toggleRtl: toggleRTL, - toggleThemeVersion, toggleCollapsed, toggleCustomFont, toggleRippleEffect, @@ -137,14 +135,10 @@ function DrawerItems() { }; const coloredLabelTheme = { - colors: isV3 - ? { - secondaryContainer: MD3Colors.tertiary80, - onSecondaryContainer: MD3Colors.tertiary20, - } - : { - primary: MD2Colors.tealA200, - }, + colors: { + secondaryContainer: MD3Colors.tertiary80, + onSecondaryContainer: MD3Colors.tertiary20, + }, }; return ( @@ -157,7 +151,7 @@ function DrawerItems() { }, ]} > - {isV3 && collapsed && ( + {collapsed && ( {DrawerCollapsedItemsData.map((props, index) => ( - {deviceColorsSupported && isV3 ? ( + {deviceColorsSupported ? ( - + Use device colors * @@ -198,7 +192,7 @@ function DrawerItems() { ) : null} - + Dark Theme @@ -208,7 +202,7 @@ function DrawerItems() { {!isWeb && ( - + RTL @@ -217,39 +211,26 @@ function DrawerItems() { )} - - - MD 2 + + + Collapsed drawer * - + - {isV3 && ( - - - Collapsed drawer * - - - - - - )} - - {isV3 && ( - - - Custom font * - - - + + + Custom font * + + - - )} + + - + {isIOS ? 'Highlight' : 'Ripple'} effect * @@ -259,7 +240,7 @@ function DrawerItems() { - {isV3 && !collapsed && ( + {!collapsed && ( * - available only for MD3 @@ -301,9 +282,6 @@ const styles = StyleSheet.create({ justifyContent: 'space-between', alignItems: 'center', paddingVertical: 12, - paddingHorizontal: 16, - }, - v3Preference: { height: 56, paddingHorizontal: 28, }, diff --git a/example/src/ExampleList.tsx b/example/src/ExampleList.tsx index 016f085caa..5c00ad6c16 100644 --- a/example/src/ExampleList.tsx +++ b/example/src/ExampleList.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { FlatList } from 'react-native'; import type { StackNavigationProp } from '@react-navigation/stack'; -import { Divider, List } from 'react-native-paper'; +import { Divider, List, useTheme } from 'react-native-paper'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import ActivityIndicatorExample from './Examples/ActivityIndicatorExample'; @@ -49,7 +49,6 @@ import ThemingWithReactNavigation from './Examples/ThemingWithReactNavigation'; import ToggleButtonExample from './Examples/ToggleButtonExample'; import TooltipExample from './Examples/TooltipExample'; import TouchableRippleExample from './Examples/TouchableRippleExample'; -import { useExampleTheme } from './hooks/useExampleTheme'; export const mainExamples: Record< string, @@ -132,16 +131,12 @@ const data = Object.keys(mainExamples).map( export default function ExampleList({ navigation }: Props) { const keyExtractor = (item: { id: string }) => item.id; - const { colors, isV3 } = useExampleTheme(); + const { colors } = useTheme(); const safeArea = useSafeAreaInsets(); const renderItem = ({ item }: { item: Item }) => { const { data, id } = item; - if (!isV3 && data.title === mainExamples.themingWithReactNavigation.title) { - return null; - } - return ( { const [animating, setAnimating] = React.useState(true); - const { isV3 } = useExampleTheme(); return ( @@ -49,7 +41,7 @@ const ActivityIndicatorExample = () => { diff --git a/example/src/Examples/AnimatedFABExample/AnimatedFABExample.tsx b/example/src/Examples/AnimatedFABExample/AnimatedFABExample.tsx index 4bffa05322..38e95a0781 100644 --- a/example/src/Examples/AnimatedFABExample/AnimatedFABExample.tsx +++ b/example/src/Examples/AnimatedFABExample/AnimatedFABExample.tsx @@ -3,13 +3,7 @@ import type { NativeScrollEvent, NativeSyntheticEvent } from 'react-native'; import { Animated, FlatList, Platform, StyleSheet, View } from 'react-native'; import Icon from '@expo/vector-icons/MaterialCommunityIcons'; -import { - Avatar, - MD2Colors, - MD3Colors, - Paragraph, - Text, -} from 'react-native-paper'; +import { Avatar, MD3Colors, Text, useTheme } from 'react-native-paper'; import CustomFAB from './CustomFAB'; import CustomFABControls, { @@ -17,7 +11,6 @@ import CustomFABControls, { initialControls, } from './CustomFABControls'; import { animatedFABExampleData } from '../../../utils'; -import { useExampleTheme } from '../../hooks/useExampleTheme'; type Item = { id: string; @@ -32,7 +25,7 @@ type Item = { }; const AnimatedFABExample = () => { - const { colors, isV3 } = useExampleTheme(); + const { colors } = useTheme(); const isIOS = Platform.OS === 'ios'; @@ -47,63 +40,55 @@ const AnimatedFABExample = () => { const renderItem = React.useCallback( ({ item }: { item: Item }) => { - const TextComponent = isV3 ? Text : Paragraph; - return ( - {item.sender} - - + {item.date} - + - {item.header} - - + {item.message} - + setVisible(!visible)} @@ -114,7 +99,7 @@ const AnimatedFABExample = () => { ); }, - [visible, isV3] + [visible] ); const onScroll = ({ diff --git a/example/src/Examples/AnimatedFABExample/CustomFAB.tsx b/example/src/Examples/AnimatedFABExample/CustomFAB.tsx index ec206bbffc..73d8c05962 100644 --- a/example/src/Examples/AnimatedFABExample/CustomFAB.tsx +++ b/example/src/Examples/AnimatedFABExample/CustomFAB.tsx @@ -9,8 +9,6 @@ import { import { AnimatedFAB } from 'react-native-paper'; -import { useExampleTheme } from '../../hooks/useExampleTheme'; - type CustomFABProps = { animatedValue: Animated.Value; visible: boolean; @@ -31,7 +29,6 @@ const CustomFAB = ({ iconMode, }: CustomFABProps) => { const [isExtended, setIsExtended] = React.useState(true); - const { isV3 } = useExampleTheme(); const isIOS = Platform.OS === 'ios'; @@ -50,7 +47,7 @@ const CustomFAB = ({ icon={'plus'} label={label} extended={isExtended} - uppercase={!isV3} + uppercase={false} onPress={() => console.log('Pressed')} visible={visible} animateFrom={animateFrom} diff --git a/example/src/Examples/AnimatedFABExample/CustomFABControls.tsx b/example/src/Examples/AnimatedFABExample/CustomFABControls.tsx index a612a4234f..30d9d277e8 100644 --- a/example/src/Examples/AnimatedFABExample/CustomFABControls.tsx +++ b/example/src/Examples/AnimatedFABExample/CustomFABControls.tsx @@ -6,9 +6,7 @@ import type { AnimatedFABAnimateFrom, AnimatedFABIconMode, } from 'react-native-paper'; -import { Paragraph, RadioButton, Text } from 'react-native-paper'; - -import { useExampleTheme } from '../../hooks/useExampleTheme'; +import { RadioButton, Text, useTheme } from 'react-native-paper'; export type Controls = { iconMode: AnimatedFABIconMode; @@ -40,19 +38,15 @@ const CustomControl = ({ value, onChange, }: CustomControlProps) => { - const { isV3 } = useExampleTheme(); - const _renderItem = React.useCallback( ({ item }: ListRenderItemInfo<(typeof options)[number]>) => { - const TextComponent = isV3 ? Text : Paragraph; - return ( onChange(item)} style={styles.controlItem} > - {item} + {item} ); }, - [value, onChange, isV3] + [value, onChange] ); const _keyExtractor = React.useCallback( (item: (typeof options)[number]) => item, [] ); - const TextComponent = isV3 ? Text : Paragraph; return ( - {name} + {name} { - const { colors } = useExampleTheme(); + const { colors } = useTheme(); const setIconMode = (newIconMode: AnimatedFABIconMode) => setControls((state) => ({ ...state, iconMode: newIconMode })); diff --git a/example/src/Examples/AppbarExample.tsx b/example/src/Examples/AppbarExample.tsx index 1ebe74bad5..f502c84795 100644 --- a/example/src/Examples/AppbarExample.tsx +++ b/example/src/Examples/AppbarExample.tsx @@ -6,16 +6,14 @@ import { Appbar, FAB, List, - Paragraph, RadioButton, Snackbar, Switch, Text, + useTheme, } from 'react-native-paper'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; -import { yellowA200 } from '../../../src/styles/themes/v2/colors'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; type Props = { @@ -26,22 +24,20 @@ type AppbarModes = 'small' | 'medium' | 'large' | 'center-aligned'; const MORE_ICON = Platform.OS === 'ios' ? 'dots-horizontal' : 'dots-vertical'; const MEDIUM_FAB_HEIGHT = 56; +const HEIGHT = 80; const AppbarExample = ({ navigation }: Props) => { const [showLeftIcon, setShowLeftIcon] = React.useState(true); - const [showSubtitle, setShowSubtitle] = React.useState(true); const [showSearchIcon, setShowSearchIcon] = React.useState(true); const [showMoreIcon, setShowMoreIcon] = React.useState(true); const [showCustomColor, setShowCustomColor] = React.useState(false); - const [showExactTheme, setShowExactTheme] = React.useState(false); const [appbarMode, setAppbarMode] = React.useState('small'); const [showCalendarIcon, setShowCalendarIcon] = React.useState(false); const [showElevated, setShowElevated] = React.useState(false); const [showSnackbar, setShowSnackbar] = React.useState(false); - const theme = useExampleTheme(); + const { colors } = useTheme(); const { bottom, left, right } = useSafeAreaInsets(); - const height = theme.isV3 ? 80 : 56; const isCenterAlignedMode = appbarMode === 'center-aligned'; @@ -51,7 +47,7 @@ const AppbarExample = ({ navigation }: Props) => { { {showLeftIcon && ( navigation.goBack()} /> )} - setShowSnackbar(true)} - /> + setShowSnackbar(true)} /> {isCenterAlignedMode ? false : showCalendarIcon && ( @@ -81,32 +73,23 @@ const AppbarExample = ({ navigation }: Props) => { }, [ navigation, showLeftIcon, - showSubtitle, showSearchIcon, showMoreIcon, showCustomColor, - showExactTheme, appbarMode, showCalendarIcon, isCenterAlignedMode, showElevated, ]); - const TextComponent = theme.isV3 ? Text : Paragraph; - const renderFAB = () => { return ( {}} - style={[ - styles.fab, - theme.isV3 - ? { top: (height - MEDIUM_FAB_HEIGHT) / 2 } - : { bottom: height / 2 + bottom }, - ]} + style={[styles.fab, { top: (HEIGHT - MEDIUM_FAB_HEIGHT) / 2 }]} /> ); }; @@ -114,113 +97,88 @@ const AppbarExample = ({ navigation }: Props) => { const renderDefaultOptions = () => ( <> - Left icon + Left icon - {!theme.isV3 && ( - - Subtitle - - - )} - Search icon + Search icon - More icon + More icon - {theme.isV3 && ( - - Calendar icon - - - )} - Custom Color + Calendar icon + + + + Custom Color - {!theme.isV3 && ( - - Exact Dark Theme - - - )} - {theme.isV3 && ( - - Elevated - - - )} + + Elevated + + ); return ( <> - {theme.isV3 ? ( - - {renderDefaultOptions()} - - ) : ( - renderDefaultOptions() - )} - {theme.isV3 && ( - - - setAppbarMode(value as AppbarModes) - } - > - - Small (default) - - - - Medium - - - - Large - - - - Center-aligned - - - - - )} + + {renderDefaultOptions()} + + + + setAppbarMode(value as AppbarModes) + } + > + + Small (default) + + + + Medium + + + + Large + + + + Center-aligned + + + + {}} /> {}} /> {}} /> {}} /> - {theme.isV3 && renderFAB()} + {renderFAB()} - {!theme.isV3 && renderFAB()} setShowSnackbar(false)} @@ -257,7 +215,8 @@ const styles = StyleSheet.create({ position: 'absolute', right: 16, }, + // eslint-disable-next-line react-native/no-color-literals customColor: { - backgroundColor: yellowA200, + backgroundColor: 'yellow', }, }); diff --git a/example/src/Examples/AvatarExample.tsx b/example/src/Examples/AvatarExample.tsx index b77da80b09..229c2f4a0b 100644 --- a/example/src/Examples/AvatarExample.tsx +++ b/example/src/Examples/AvatarExample.tsx @@ -1,13 +1,11 @@ import * as React from 'react'; import { StyleSheet, View } from 'react-native'; -import { Avatar, List, MD2Colors, MD3Colors } from 'react-native-paper'; +import { Avatar, List, MD3Colors } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const AvatarExample = () => { - const { isV3 } = useExampleTheme(); return ( @@ -16,11 +14,11 @@ const AvatarExample = () => { style={[ styles.avatar, { - backgroundColor: isV3 ? MD3Colors.error70 : MD2Colors.yellow500, + backgroundColor: MD3Colors.error70, }, ]} label="XD" - color={isV3 ? MD3Colors.primary0 : MD2Colors.black} + color={MD3Colors.primary0} /> @@ -32,11 +30,11 @@ const AvatarExample = () => { style={[ styles.avatar, { - backgroundColor: isV3 ? MD3Colors.error70 : MD2Colors.yellow500, + backgroundColor: MD3Colors.error70, }, ]} icon="folder" - color={isV3 ? MD3Colors.primary0 : MD2Colors.black} + color={MD3Colors.primary0} /> diff --git a/example/src/Examples/BadgeExample.tsx b/example/src/Examples/BadgeExample.tsx index 17f0e1b160..3269dc70a8 100644 --- a/example/src/Examples/BadgeExample.tsx +++ b/example/src/Examples/BadgeExample.tsx @@ -5,18 +5,15 @@ import { Badge, IconButton, List, - MD2Colors, MD3Colors, Text, Switch, } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const BadgeExample = () => { const [visible, setVisible] = React.useState(true); - const { isV3 } = useExampleTheme(); return ( @@ -44,9 +41,7 @@ const BadgeExample = () => { style={[ styles.badge, { - backgroundColor: isV3 - ? MD3Colors.primary80 - : MD2Colors.blue500, + backgroundColor: MD3Colors.primary80, }, ]} > @@ -59,11 +54,11 @@ const BadgeExample = () => { - + - + diff --git a/example/src/Examples/BannerExample.tsx b/example/src/Examples/BannerExample.tsx index 0e856e9699..d420f6791c 100644 --- a/example/src/Examples/BannerExample.tsx +++ b/example/src/Examples/BannerExample.tsx @@ -8,9 +8,8 @@ import { View, } from 'react-native'; -import { Banner, FAB, MD2Colors, MD3Colors } from 'react-native-paper'; +import { Banner, FAB, MD3Colors, useTheme } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const PHOTOS = Array.from({ length: 24 }).map( @@ -20,7 +19,7 @@ const PHOTOS = Array.from({ length: 24 }).map( const BannerExample = () => { const [visible, setVisible] = React.useState(true); const [useCustomTheme, setUseCustomTheme] = React.useState(false); - const defaultTheme = useExampleTheme(); + const theme = useTheme(); const [height, setHeight] = React.useState(0); @@ -29,25 +28,16 @@ const BannerExample = () => { setHeight(layoutHeight); }; - const customTheme = !defaultTheme.isV3 - ? { - ...defaultTheme, - colors: { - text: MD2Colors.white, - surface: MD2Colors.blue200, - primary: MD2Colors.purple900, - }, - } - : { - ...defaultTheme, - colors: { - onSurface: MD3Colors.tertiary100, - elevation: { - level1: MD3Colors.tertiary50, - }, - primary: MD3Colors.tertiary10, - }, - }; + const customTheme = { + ...theme, + colors: { + onSurface: MD3Colors.tertiary100, + elevation: { + level1: MD3Colors.tertiary50, + }, + primary: MD3Colors.tertiary10, + }, + }; return ( <> @@ -90,7 +80,7 @@ const BannerExample = () => { onHideAnimationFinished={() => console.log('Completed closing animation') } - theme={useCustomTheme ? customTheme : defaultTheme} + theme={useCustomTheme ? customTheme : theme} style={styles.banner} > Two line text string with two actions. One to two lines is preferable on diff --git a/example/src/Examples/BottomNavigationExample.tsx b/example/src/Examples/BottomNavigationExample.tsx index 6ed5d7add5..c30934c9f7 100644 --- a/example/src/Examples/BottomNavigationExample.tsx +++ b/example/src/Examples/BottomNavigationExample.tsx @@ -17,7 +17,6 @@ import { } from 'react-native-paper'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; type Route = { route: { key: string } }; @@ -49,7 +48,6 @@ const PhotoGallery = ({ route }: Route) => { }; const BottomNavigationExample = ({ navigation }: Props) => { - const { isV3 } = useExampleTheme(); const insets = useSafeAreaInsets(); const [index, setIndex] = React.useState(0); const [menuVisible, setMenuVisible] = React.useState(false); @@ -63,34 +61,25 @@ const BottomNavigationExample = ({ navigation }: Props) => { key: 'album', title: 'Album', focusedIcon: 'image-album', - ...(!isV3 && { color: '#6200ee' }), }, { key: 'library', title: 'Library', focusedIcon: 'inbox', badge: true, - ...(isV3 - ? { unfocusedIcon: 'inbox-outline' } - : { - color: '#2962ff', - }), + unfocusedIcon: 'inbox-outline', }, { key: 'favorites', title: 'Favorites', focusedIcon: 'heart', - ...(isV3 - ? { unfocusedIcon: 'heart-outline' } - : { - color: '#00796b', - }), + unfocusedIcon: 'heart-outline', }, { key: 'purchased', title: 'Purchased', focusedIcon: 'shopping', - ...(isV3 ? { unfocusedIcon: 'shopping-outline' } : { color: '#c51162' }), + unfocusedIcon: 'shopping-outline', }, ]); @@ -112,7 +101,6 @@ const BottomNavigationExample = ({ navigation }: Props) => { setMenuVisible(true)} - {...(!isV3 && { color: 'white' })} /> } > diff --git a/example/src/Examples/ButtonExample.tsx b/example/src/Examples/ButtonExample.tsx index 7ec58f90f4..28fc95df1d 100644 --- a/example/src/Examples/ButtonExample.tsx +++ b/example/src/Examples/ButtonExample.tsx @@ -1,24 +1,25 @@ import * as React from 'react'; import { Image, StyleSheet, View } from 'react-native'; -import { Button, List, Text } from 'react-native-paper'; +import { Button, List, Text, useTheme } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const ButtonExample = () => { - const theme = useExampleTheme(); - - const color = theme.isV3 ? theme.colors.inversePrimary : theme.colors.accent; + const { colors } = useTheme(); return ( - + - - {theme.isV3 && ( - - - - - - - - - - - )} - + + + + + + + + + + + - + - {theme.isV3 && ( - - - - - - - - - - - )} + + + + + + + + + + @@ -371,12 +368,10 @@ const styles = StyleSheet.create({ flexReverse: { flexDirection: 'row-reverse', }, - md3FontStyles: { - lineHeight: 32, - }, fontStyles: { fontWeight: '800', fontSize: 24, + lineHeight: 32, }, flexGrow1Button: { flexGrow: 1, diff --git a/example/src/Examples/CardExample.tsx b/example/src/Examples/CardExample.tsx index 5b12fc08bb..3dc778ae50 100644 --- a/example/src/Examples/CardExample.tsx +++ b/example/src/Examples/CardExample.tsx @@ -7,28 +7,23 @@ import { Card, Chip, IconButton, - Paragraph, Text, + useTheme, } from 'react-native-paper'; import { isWeb } from '../../utils'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import { PreferencesContext } from '../PreferencesContext'; import ScreenWrapper from '../ScreenWrapper'; type Mode = 'elevated' | 'outlined' | 'contained'; const CardExample = () => { - const { colors, isV3 } = useExampleTheme(); + const { colors } = useTheme(); const [selectedMode, setSelectedMode] = React.useState('elevated' as Mode); const [isSelected, setIsSelected] = React.useState(false); const preferences = React.useContext(PreferencesContext); - const modes = isV3 - ? ['elevated', 'outlined', 'contained'] - : ['elevated', 'outlined']; - - const TextComponent = isV3 ? Text : Paragraph; + const modes = ['elevated', 'outlined', 'contained']; return ( @@ -55,30 +50,28 @@ const CardExample = () => { /> - + The Abandoned Ship is a wrecked ship located on Route 108 in Hoenn, originally being a ship named the S.S. Cactus. The second part of the ship can only be accessed by using Dive and contains the Scanner. - + + + + + + + + + This is a card using title and subtitle with specified variants. + - {isV3 && ( - - - - - - This is a card using title and subtitle with specified variants. - - - - )} @@ -96,13 +89,13 @@ const CardExample = () => { )} /> - + Dotted around the Hoenn region, you will find loamy soil, many of which are housing berries. Once you have picked the berries, then you have the ability to use that loamy soil to grow your own berries. These can be any berry and will require attention to get the best crop. - + @@ -160,9 +153,9 @@ const CardExample = () => { - + This is a pressable chameleon. If you press me, I will alert. - + { left={(props) => } /> - + This is a long press only city. If you long press me, I will alert. - + { left={(props) => } /> - + This is pressable card. If you press me, I will switch the theme. - + diff --git a/example/src/Examples/CheckboxExample.tsx b/example/src/Examples/CheckboxExample.tsx index c8ce8c23a7..06088a646a 100644 --- a/example/src/Examples/CheckboxExample.tsx +++ b/example/src/Examples/CheckboxExample.tsx @@ -1,16 +1,8 @@ import * as React from 'react'; import { StyleSheet, View } from 'react-native'; -import { - Checkbox, - MD2Colors, - MD3Colors, - Paragraph, - Text, - TouchableRipple, -} from 'react-native-paper'; +import { Checkbox, MD3Colors, Text, TouchableRipple } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const CheckboxExample = () => { @@ -18,14 +10,11 @@ const CheckboxExample = () => { const [checkedCustom, setCheckedCustom] = React.useState(true); const [indeterminate, setIndeterminate] = React.useState(true); - const { isV3 } = useExampleTheme(); - const TextComponent = isV3 ? Text : Paragraph; - return ( setCheckedNormal(!checkedNormal)}> - Normal + Normal @@ -34,10 +23,10 @@ const CheckboxExample = () => { setCheckedCustom(!checkedCustom)}> - Custom + Custom @@ -46,7 +35,7 @@ const CheckboxExample = () => { setIndeterminate(!indeterminate)}> - Indeterminate + Indeterminate @@ -54,15 +43,15 @@ const CheckboxExample = () => { - Checked (Disabled) + Checked (Disabled) - Unchecked (Disabled) + Unchecked (Disabled) - Indeterminate (Disabled) + Indeterminate (Disabled) diff --git a/example/src/Examples/CheckboxItemExample.tsx b/example/src/Examples/CheckboxItemExample.tsx index 514272788c..acafd709b7 100644 --- a/example/src/Examples/CheckboxItemExample.tsx +++ b/example/src/Examples/CheckboxItemExample.tsx @@ -3,7 +3,6 @@ import { StyleSheet } from 'react-native'; import { Checkbox } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const CheckboxExample = () => { @@ -15,8 +14,6 @@ const CheckboxExample = () => { const [checkedDisabled, setCheckedDisabled] = React.useState(true); const [checkedLabelVariant, setCheckedLabelVariant] = React.useState(true); - const { isV3 } = useExampleTheme(); - return ( { onPress={() => setCheckedDisabled(!checkedDisabled)} disabled /> - {isV3 && ( - setCheckedLabelVariant(!checkedLabelVariant)} - /> - )} + setCheckedLabelVariant(!checkedLabelVariant)} + /> ); }; diff --git a/example/src/Examples/ChipExample.tsx b/example/src/Examples/ChipExample.tsx index 20f0393153..211ebfde49 100644 --- a/example/src/Examples/ChipExample.tsx +++ b/example/src/Examples/ChipExample.tsx @@ -2,16 +2,8 @@ import * as React from 'react'; import { Image, StyleSheet, View } from 'react-native'; import color from 'color'; -import { - Chip, - List, - MD2Colors, - MD3Colors, - Snackbar, - Text, -} from 'react-native-paper'; +import { Chip, List, MD3Colors, Snackbar, Text } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const ChipExample = () => { @@ -19,8 +11,7 @@ const ChipExample = () => { visible: false, text: '', }); - const { isV3 } = useExampleTheme(); - const customColor = isV3 ? MD3Colors.error50 : MD2Colors.purple900; + const customColor = MD3Colors.error50; return ( <> @@ -30,24 +21,20 @@ const ChipExample = () => { {}} style={styles.chip}> Simple - {isV3 && ( - <> - {}} - style={styles.chip} - > - With selected overlay - - {}} style={styles.chip}> - Elevated - - {}}> - Compact chip - - - )} + {}} + style={styles.chip} + > + With selected overlay + + {}} style={styles.chip}> + Elevated + + {}}> + Compact chip + {}} onClose={() => @@ -137,35 +124,31 @@ const ChipExample = () => { {}} style={styles.chip}> Simple - {isV3 && ( - <> - {}} - style={styles.chip} - > - With selected overlay - - {}} - style={styles.chip} - > - Elevated - - {}} - style={styles.chip} - > - Compact chip - - - )} + {}} + style={styles.chip} + > + With selected overlay + + {}} + style={styles.chip} + > + Elevated + + {}} + style={styles.chip} + > + Compact chip + {}} @@ -251,38 +234,34 @@ const ChipExample = () => { - {isV3 && ( - <> - {}} - compact - avatar={ - - } - style={[styles.chip, styles.customBorderRadius]} - > - Compact with custom border radius - - {}} - compact - avatar={ - - } - style={[styles.chip, styles.customBorderRadius]} - > - Compact with custom border radius - - - )} + {}} + compact + avatar={ + + } + style={[styles.chip, styles.customBorderRadius]} + > + Compact with custom border radius + + {}} + compact + avatar={ + + } + style={[styles.chip, styles.customBorderRadius]} + > + Compact with custom border radius + {}} diff --git a/example/src/Examples/DialogExample.tsx b/example/src/Examples/DialogExample.tsx index 4a9de665d7..d926ae6616 100644 --- a/example/src/Examples/DialogExample.tsx +++ b/example/src/Examples/DialogExample.tsx @@ -12,7 +12,6 @@ import { DialogWithRadioBtns, UndismissableDialog, } from './Dialogs'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; type ButtonVisibility = { @@ -21,7 +20,6 @@ type ButtonVisibility = { const DialogExample = () => { const [visible, setVisible] = React.useState({}); - const { isV3 } = useExampleTheme(); const _toggleDialog = (name: string) => () => setVisible({ ...visible, [name]: !visible[name] }); @@ -65,15 +63,13 @@ const DialogExample = () => { > Custom colors - {isV3 && ( - - )} + {Platform.OS === 'android' && ( diff --git a/example/src/Examples/Dialogs/DialogWithDismissableBackButton.tsx b/example/src/Examples/Dialogs/DialogWithDismissableBackButton.tsx index 32512dc91d..689a22b082 100644 --- a/example/src/Examples/Dialogs/DialogWithDismissableBackButton.tsx +++ b/example/src/Examples/Dialogs/DialogWithDismissableBackButton.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; -import { Button, Portal, Dialog, MD2Colors } from 'react-native-paper'; +import { Button, Portal, Dialog, MD3Colors } from 'react-native-paper'; import { TextComponent } from './DialogTextComponent'; @@ -26,7 +26,7 @@ const DialogWithDismissableBackButton = ({ - diff --git a/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx b/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx index 5ef9e7e7f2..5860737e3e 100644 --- a/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx +++ b/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx @@ -1,10 +1,9 @@ import * as React from 'react'; import { ActivityIndicator, Platform, StyleSheet, View } from 'react-native'; -import { Dialog, MD2Colors, MD3Colors, Portal } from 'react-native-paper'; +import { Dialog, MD3Colors, Portal } from 'react-native-paper'; import { TextComponent } from './DialogTextComponent'; -import { useExampleTheme } from '../../hooks/useExampleTheme'; const isIOS = Platform.OS === 'ios'; @@ -15,7 +14,6 @@ const DialogWithLoadingIndicator = ({ visible: boolean; close: () => void; }) => { - const { isV3 } = useExampleTheme(); return ( @@ -23,7 +21,7 @@ const DialogWithLoadingIndicator = ({ diff --git a/example/src/Examples/Dialogs/UndismissableDialog.tsx b/example/src/Examples/Dialogs/UndismissableDialog.tsx index 2af40f4e97..647d3c96d3 100644 --- a/example/src/Examples/Dialogs/UndismissableDialog.tsx +++ b/example/src/Examples/Dialogs/UndismissableDialog.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; -import { Button, Portal, Dialog, MD2Colors } from 'react-native-paper'; +import { Button, Portal, Dialog, MD3Colors } from 'react-native-paper'; import { TextComponent } from './DialogTextComponent'; @@ -18,7 +18,7 @@ const UndismissableDialog = ({ This is an undismissable dialog!! - diff --git a/example/src/Examples/DividerExample.tsx b/example/src/Examples/DividerExample.tsx index bbf5e7efb2..c3c2c6b770 100644 --- a/example/src/Examples/DividerExample.tsx +++ b/example/src/Examples/DividerExample.tsx @@ -1,15 +1,14 @@ import * as React from 'react'; import { FlatList } from 'react-native'; -import { Divider, List } from 'react-native-paper'; +import { Divider, List, useTheme } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const items = ['Apple', 'Banana', 'Coconut', 'Lemon', 'Mango', 'Peach']; const DividerExample = () => { - const { colors } = useExampleTheme(); + const { colors } = useTheme(); return ( diff --git a/example/src/Examples/FABExample.tsx b/example/src/Examples/FABExample.tsx index 0cff916980..e7db1118a7 100644 --- a/example/src/Examples/FABExample.tsx +++ b/example/src/Examples/FABExample.tsx @@ -4,7 +4,6 @@ import { Alert, StyleSheet, View } from 'react-native'; import { FAB, Portal, Text } from 'react-native-paper'; import { isWeb } from '../../utils'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; type FABVariant = 'primary' | 'secondary' | 'tertiary' | 'surface'; @@ -16,7 +15,6 @@ const FABExample = () => { const [toggleStackOnLongPress, setToggleStackOnLongPress] = React.useState(false); const [open, setOpen] = React.useState(false); - const { isV3 } = useExampleTheme(); const variants = ['primary', 'secondary', 'tertiary', 'surface']; const sizes = ['small', 'medium', 'large']; @@ -32,69 +30,49 @@ const FABExample = () => { onPress={() => setVisible(!visible)} /> - {isV3 && ( - <> - - {variants.map((variant) => ( - - {}} - visible={visible} - variant={variant as FABVariant} - /> - {visible && {variant}} - - ))} - - - {sizes.map((size) => ( - - {}} - visible={visible} - size={size as FABSize} - /> - {visible && {size}} - - ))} - - - {modes.map((mode) => ( - - {}} - visible={visible} - mode={mode as FABMode} - /> - {visible && {mode}} - - ))} + + {variants.map((variant) => ( + + {}} + visible={visible} + variant={variant as FABVariant} + /> + {visible && {variant}} - - )} - - {!isV3 && ( - <> + ))} + + + {sizes.map((size) => ( + {}} visible={visible} + size={size as FABSize} /> + {visible && {size}} + + ))} + + + {modes.map((mode) => ( + {}} visible={visible} + mode={mode as FABMode} /> - - )} + {visible && {mode}} + + ))} + + { icon: 'bell', label: 'Remind', onPress: () => {}, - size: isV3 ? 'small' : 'medium', + size: 'small', }, { icon: toggleStackOnLongPress diff --git a/example/src/Examples/IconButtonExample.tsx b/example/src/Examples/IconButtonExample.tsx index 6342b1e144..a776815a37 100644 --- a/example/src/Examples/IconButtonExample.tsx +++ b/example/src/Examples/IconButtonExample.tsx @@ -1,36 +1,11 @@ import * as React from 'react'; import { StyleSheet, View } from 'react-native'; -import { IconButton, List, MD2Colors, MD3Colors } from 'react-native-paper'; +import { IconButton, List, MD3Colors } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const ButtonExample = () => { - const { isV3 } = useExampleTheme(); - if (!isV3) { - return ( - - {}} /> - {}} - /> - {}} loading /> - {}} /> - {}} - style={{ backgroundColor: MD2Colors.lightGreen200 }} - /> - {}} /> - - ); - } - return ( @@ -162,7 +137,7 @@ const ButtonExample = () => { mode="contained" style={styles.slightlyRounded} size={24} - contentStyle={{ padding: 8 }} + contentStyle={styles.padding} iconColor={MD3Colors.tertiary50} onPress={() => {}} /> @@ -200,16 +175,13 @@ const ButtonExample = () => { ButtonExample.title = 'Icon Button'; const styles = StyleSheet.create({ - v2Container: { - flexDirection: 'row', - padding: 8, - }, v3Container: { flexDirection: 'column', }, row: { flexDirection: 'row', paddingHorizontal: 12, + flexWrap: 'wrap', }, square: { borderRadius: 0, @@ -225,6 +197,9 @@ const styles = StyleSheet.create({ borderBottomLeftRadius: 8, borderBottomRightRadius: 6, }, + padding: { + padding: 8, + }, }); export default ButtonExample; diff --git a/example/src/Examples/MenuExample.tsx b/example/src/Examples/MenuExample.tsx index c1164d35b6..027cc5b84d 100644 --- a/example/src/Examples/MenuExample.tsx +++ b/example/src/Examples/MenuExample.tsx @@ -16,7 +16,6 @@ import { TouchableRipple, } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; type ContextualMenuCoord = { x: number; y: number }; @@ -35,7 +34,6 @@ const MenuExample = ({ navigation }: Props) => { const [visible, setVisible] = React.useState({}); const [contextualMenuCoord, setContextualMenuCoor] = React.useState({ x: 0, y: 0 }); - const { isV3 } = useExampleTheme(); const _toggleMenu = (name: string) => () => setVisible({ ...visible, [name]: !visible[name] }); @@ -66,16 +64,12 @@ const MenuExample = ({ navigation }: Props) => { visible={_getVisible('menu1')} onDismiss={_toggleMenu('menu1')} anchor={ - + } > {}} title="Undo" /> {}} title="Redo" /> - + {}} title="Cut" disabled /> {}} title="Copy" disabled /> {}} title="Paste" /> @@ -99,7 +93,7 @@ const MenuExample = ({ navigation }: Props) => { {}} title="Undo" /> {}} title="Redo" /> - + { onPress={() => {}} title="Paste" /> - {isV3 && ( - {}} - title="Share" - /> - )} + {}} + title="Share" + /> { > {}} title="Item 1" /> {}} title="Item 2" /> - + {}} title="Item 3" disabled /> diff --git a/example/src/Examples/ProgressBarExample.tsx b/example/src/Examples/ProgressBarExample.tsx index 565147f4c6..6a910bc348 100644 --- a/example/src/Examples/ProgressBarExample.tsx +++ b/example/src/Examples/ProgressBarExample.tsx @@ -4,13 +4,12 @@ import { View, StyleSheet, Animated } from 'react-native'; import { Button, ProgressBar, - MD2Colors, MD3Colors, ProgressBarProps, Text, + useTheme, } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; class ClassProgressBar extends React.Component { @@ -28,8 +27,7 @@ const AnimatedProgressBar = Animated.createAnimatedComponent(ClassProgressBar); const ProgressBarExample = () => { const [visible, setVisible] = React.useState(true); const [progress, setProgress] = React.useState(0.3); - const theme = useExampleTheme(); - const { isV3 } = theme; + const theme = useTheme(); const { current: progressBarValue } = React.useRef(new Animated.Value(0)); const runCustomAnimation = () => { @@ -64,7 +62,7 @@ const ProgressBarExample = () => { @@ -75,9 +73,9 @@ const ProgressBarExample = () => { diff --git a/example/src/Examples/RadioButtonExample.tsx b/example/src/Examples/RadioButtonExample.tsx index 88bf9ebfb7..7e3b3cf754 100644 --- a/example/src/Examples/RadioButtonExample.tsx +++ b/example/src/Examples/RadioButtonExample.tsx @@ -2,29 +2,24 @@ import * as React from 'react'; import { StyleSheet, View } from 'react-native'; import { - MD2Colors, MD3Colors, - Paragraph, RadioButton, Text, TouchableRipple, } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; type State = 'normal' | 'normal-ios' | 'normal-item' | 'custom'; const RadioButtonExample = () => { const [checked, setChecked] = React.useState('normal'); - const { isV3 } = useExampleTheme(); - const TextComponent = isV3 ? Text : Paragraph; return ( setChecked('normal')}> - Normal - Material Design + Normal - Material Design { setChecked('normal-ios')}> - Normal 2 - IOS + Normal 2 - IOS { setChecked('custom')}> - Custom + Custom @@ -63,11 +58,11 @@ const RadioButtonExample = () => { onPress={() => setChecked('normal-item')} /> - Checked (Disabled) + Checked (Disabled) - Unchecked (Disabled) + Unchecked (Disabled) { const [value, setValue] = React.useState('first'); const [value2, setValue2] = React.useState('first'); - const { colors, isV3 } = useExampleTheme(); - const TextComponent = isV3 ? Text : Paragraph; + const { colors } = useTheme(); return ( @@ -21,15 +19,15 @@ const RadioButtonGroupExample = () => { onValueChange={(value: string) => setValue(value)} > - First + First - Second + Second - Third + Third diff --git a/example/src/Examples/RadioButtonItemExample.tsx b/example/src/Examples/RadioButtonItemExample.tsx index 38eff755a5..e640a1dd0a 100644 --- a/example/src/Examples/RadioButtonItemExample.tsx +++ b/example/src/Examples/RadioButtonItemExample.tsx @@ -3,7 +3,6 @@ import { StyleSheet } from 'react-native'; import { RadioButton } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const RadioButtonItemExample = () => { @@ -15,8 +14,6 @@ const RadioButtonItemExample = () => { const [checkedDisabled, setCheckedDisabled] = React.useState(true); const [checkedLabelVariant, setCheckedLabelVariant] = React.useState(true); - const { isV3 } = useExampleTheme(); - return ( { value="iOS" disabled /> - {isV3 && ( - setCheckedLabelVariant(!checkedLabelVariant)} - value="default" - /> - )} + setCheckedLabelVariant(!checkedLabelVariant)} + value="default" + /> ); }; diff --git a/example/src/Examples/SearchbarExample.tsx b/example/src/Examples/SearchbarExample.tsx index 51a8af3ed8..9ba8a4cfb0 100644 --- a/example/src/Examples/SearchbarExample.tsx +++ b/example/src/Examples/SearchbarExample.tsx @@ -9,9 +9,9 @@ import { Searchbar, Snackbar, Avatar, + useTheme, } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; type Props = { @@ -34,12 +34,12 @@ const SearchExample = ({ navigation }: Props) => { clickableLoading: '', }); - const { isV3, colors } = useExampleTheme(); + const { colors } = useTheme(); return ( <> - {!isV3 && ( + @@ -47,136 +47,122 @@ const SearchExample = ({ navigation }: Props) => { } value={searchQueries.searchBarMode} style={styles.searchbar} + mode="bar" /> - )} - {isV3 && ( - - - setSearchQuery({ ...searchQueries, searchBarMode: query }) - } - value={searchQueries.searchBarMode} - style={styles.searchbar} - mode="bar" - /> - - setSearchQuery({ ...searchQueries, traileringIcon: query }) - } - value={searchQueries.traileringIcon} - traileringIcon={'microphone'} - traileringIconColor={ - isVisible ? MD3Colors.error40 : colors.onSurfaceVariant - } - traileringIconAccessibilityLabel={'microphone button'} - onTraileringIconPress={() => setIsVisible(true)} - style={styles.searchbar} - mode="bar" - /> - - setSearchQuery({ - ...searchQueries, - traileringIconWithRightItem: query, - }) - } - value={searchQueries.traileringIconWithRightItem} - traileringIcon={'microphone'} - traileringIconColor={ - isVisible ? MD3Colors.error40 : colors.onSurfaceVariant - } - traileringIconAccessibilityLabel={'microphone button'} - onTraileringIconPress={() => setIsVisible(true)} - right={(props) => ( - - )} - style={styles.searchbar} - /> - - setSearchQuery({ - ...searchQueries, - rightItem: query, - }) - } - value={searchQueries.rightItem} - right={(props) => ( - - )} - style={styles.searchbar} - /> - - setSearchQuery({ - ...searchQueries, - loadingBarMode: query, - }) - } - value={searchQueries.loadingBarMode} - style={styles.searchbar} - mode="bar" - loading - traileringIcon={'microphone'} - /> - - )} - {isV3 && ( - - - setSearchQuery({ - ...searchQueries, - searchViewMode: query, - }) - } - value={searchQueries.searchViewMode} - style={styles.searchbar} - mode="view" - /> - - setSearchQuery({ - ...searchQueries, - searchWithoutBottomLine: query, - }) - } - value={searchQueries.searchWithoutBottomLine} - style={styles.searchbar} - mode="view" - showDivider={false} - /> - - setSearchQuery({ - ...searchQueries, - loadingViewMode: query, - }) - } - value={searchQueries.loadingViewMode} - style={styles.searchbar} - mode="view" - loading - /> - - )} + + setSearchQuery({ ...searchQueries, traileringIcon: query }) + } + value={searchQueries.traileringIcon} + traileringIcon={'microphone'} + traileringIconColor={ + isVisible ? MD3Colors.error40 : colors.onSurfaceVariant + } + traileringIconAccessibilityLabel={'microphone button'} + onTraileringIconPress={() => setIsVisible(true)} + style={styles.searchbar} + mode="bar" + /> + + setSearchQuery({ + ...searchQueries, + traileringIconWithRightItem: query, + }) + } + value={searchQueries.traileringIconWithRightItem} + traileringIcon={'microphone'} + traileringIconColor={ + isVisible ? MD3Colors.error40 : colors.onSurfaceVariant + } + traileringIconAccessibilityLabel={'microphone button'} + onTraileringIconPress={() => setIsVisible(true)} + right={(props) => ( + + )} + style={styles.searchbar} + /> + + setSearchQuery({ + ...searchQueries, + rightItem: query, + }) + } + value={searchQueries.rightItem} + right={(props) => ( + + )} + style={styles.searchbar} + /> + + setSearchQuery({ + ...searchQueries, + loadingBarMode: query, + }) + } + value={searchQueries.loadingBarMode} + style={styles.searchbar} + mode="bar" + loading + traileringIcon={'microphone'} + /> + + + + setSearchQuery({ + ...searchQueries, + searchViewMode: query, + }) + } + value={searchQueries.searchViewMode} + style={styles.searchbar} + mode="view" + /> + + setSearchQuery({ + ...searchQueries, + searchWithoutBottomLine: query, + }) + } + value={searchQueries.searchWithoutBottomLine} + style={styles.searchbar} + mode="view" + showDivider={false} + /> + + setSearchQuery({ + ...searchQueries, + loadingViewMode: query, + }) + } + value={searchQueries.loadingViewMode} + style={styles.searchbar} + mode="view" + loading + /> + { const preferences = React.useContext(PreferencesContext); - const theme = useExampleTheme(); const [options, setOptions] = React.useState({ showSnackbar: false, @@ -51,17 +49,15 @@ const SnackbarExample = () => { } /> - {theme.isV3 && ( - - Close icon button - - setOptions({ ...options, showCloseIcon: !showCloseIcon }) - } - /> - - )} + + Close icon button + + setOptions({ ...options, showCloseIcon: !showCloseIcon }) + } + /> + Longer message { - const { isV3 } = useExampleTheme(); - const v2Elevation = [1, 2, 4, 8, 12]; - const elevationValues = isV3 ? Array.from({ length: 6 }) : v2Elevation; + const elevationValues = Array.from({ length: 6 }); const renderSurface = (index: number, mode: 'flat' | 'elevated') => ( - {isV3 - ? `Elevation ${index === 1 ? '(default)' : ''} ${index}` - : `${elevationValues[index]}`} + `Elevation ${index === 1 ? '(default)' : ''} ${index}` ); @@ -82,19 +74,12 @@ const styles = StyleSheet.create({ }, surface: { margin: 24, - height: 80, - width: 80, alignItems: 'center', justifyContent: 'center', - }, - v3Surface: { borderRadius: 16, height: 200, width: 200, - alignItems: 'center', - justifyContent: 'center', }, - horizontalSurfacesContainer: { flexDirection: 'row', justifyContent: 'space-between', diff --git a/example/src/Examples/SwitchExample.tsx b/example/src/Examples/SwitchExample.tsx index a1bff15dc4..51baa12b01 100644 --- a/example/src/Examples/SwitchExample.tsx +++ b/example/src/Examples/SwitchExample.tsx @@ -1,24 +1,14 @@ import * as React from 'react'; import { Platform, StyleSheet, View } from 'react-native'; -import { - MD2Colors, - MD3Colors, - Paragraph, - Switch, - Text, - TouchableRipple, -} from 'react-native-paper'; +import { MD3Colors, Switch, Text, TouchableRipple } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const SwitchExample = () => { const [valueNormal, setNormalValue] = React.useState(true); const [valueCustom, setCustomValue] = React.useState(true); - const { isV3 } = useExampleTheme(); - const switchValueNormalLabel = `switch ${ valueNormal === true ? 'on' : 'off' }`; @@ -26,13 +16,11 @@ const SwitchExample = () => { valueCustom === true ? 'on' : 'off' }`; - const TextComponent = isV3 ? Text : Paragraph; - return Platform.OS === 'android' ? ( setNormalValue(!valueNormal)}> - Normal {switchValueNormalLabel} + Normal {switchValueNormalLabel} @@ -40,47 +28,44 @@ const SwitchExample = () => { setCustomValue(!valueCustom)}> - Custom {switchValueCustomlLabel} + Custom {switchValueCustomlLabel} - + - Switch on (disabled) + Switch on (disabled) - Switch off (disabled) + Switch off (disabled) ) : ( - Normal {switchValueNormalLabel} + Normal {switchValueNormalLabel} setNormalValue(!valueNormal)} /> - Custom {switchValueCustomlLabel} + Custom {switchValueCustomlLabel} setCustomValue(!valueCustom)} - color={isV3 ? MD3Colors.tertiary50 : MD2Colors.blue500} + color={MD3Colors.tertiary50} /> - Switch on (disabled) + Switch on (disabled) - Switch off (disabled) + Switch off (disabled) diff --git a/example/src/Examples/TextExample.tsx b/example/src/Examples/TextExample.tsx index 4bd1572359..1cb96edfaf 100644 --- a/example/src/Examples/TextExample.tsx +++ b/example/src/Examples/TextExample.tsx @@ -2,25 +2,17 @@ import * as React from 'react'; import { Platform, StyleSheet, View } from 'react-native'; import { - Caption, configureFonts, - Headline, MD3LightTheme, - Paragraph, PaperProvider, - Subheading, customText, - Title, } from 'react-native-paper'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const Text = customText<'customVariant'>(); const TextExample = () => { - const { isV3 } = useExampleTheme(); - const fontConfig = { customVariant: { fontFamily: Platform.select({ @@ -44,75 +36,61 @@ const TextExample = () => { return ( - {!isV3 && ( - <> - Caption - Paragraph - Subheading - Title - Headline - - )} - - {isV3 && ( - <> - - Display Large - - - Display Medium - - - Display small - + + Display Large + + + Display Medium + + + Display small + - - Headline Large - - - Headline Medium - - - Headline Small - + + Headline Large + + + Headline Medium + + + Headline Small + - - Title Large - - - Title Medium - - - Title Small - + + Title Large + + + Title Medium + + + Title Small + - - Label Large - - - Label Medium - - - Label Small - + + Label Large + + + Label Medium + + + Label Small + - - Body Large - - - Body Medium - - - Body Small - + + Body Large + + + Body Medium + + + Body Small + - - - Custom Variant - - - - )} + + + Custom Variant + + ); diff --git a/example/src/Examples/TextInputExample.tsx b/example/src/Examples/TextInputExample.tsx index 7102abd0b6..376dd57818 100644 --- a/example/src/Examples/TextInputExample.tsx +++ b/example/src/Examples/TextInputExample.tsx @@ -13,13 +13,12 @@ import { configureFonts, HelperText, List, - MD2Colors, MD3Colors, TextInput, + useTheme, } from 'react-native-paper'; import { inputReducer, State } from '../../utils'; -import { useExampleTheme } from '../hooks/useExampleTheme'; import ScreenWrapper from '../ScreenWrapper'; const MAX_LENGTH = 20; @@ -125,7 +124,7 @@ const TextInputExample = () => { const _isUsernameValid = (name: string) => /^[a-zA-Z]*$/.test(name); - const theme = useExampleTheme(); + const { colors } = useTheme(); const inputActionHandler = (type: keyof State, payload: string) => dispatch({ @@ -138,11 +137,7 @@ const TextInputExample = () => { const newColors = { ...state.iconsColor, - [name]: !color - ? theme.isV3 - ? theme.colors.primary - : theme.colors?.accent - : undefined, + [name]: !color ? colors.primary : undefined, }; dispatch({ @@ -431,9 +426,7 @@ const TextInputExample = () => { right={ - focused ? theme.colors?.primary : undefined - } + color={(focused) => (focused ? colors.primary : undefined)} /> } /> @@ -572,9 +565,7 @@ const TextInputExample = () => { * @@ -604,12 +595,8 @@ const TextInputExample = () => { onChangeText={(flatUnderlineColors) => inputActionHandler('flatUnderlineColors', flatUnderlineColors) } - underlineColor={ - theme.isV3 ? MD3Colors.primary70 : MD2Colors.pink400 - } - activeUnderlineColor={ - theme.isV3 ? MD3Colors.tertiary50 : MD2Colors.amber900 - } + underlineColor={MD3Colors.primary70} + activeUnderlineColor={MD3Colors.tertiary50} /> { onChangeText={(outlinedColors) => inputActionHandler('outlinedColors', outlinedColors) } - outlineColor={ - theme.isV3 ? MD3Colors.primary70 : MD2Colors.pink400 - } - activeOutlineColor={ - theme.isV3 ? MD3Colors.tertiary50 : MD2Colors.amber900 - } + outlineColor={MD3Colors.primary70} + activeOutlineColor={MD3Colors.tertiary50} /> { placeholder="Custom colors" /> - {fontsLoaded && theme.isV3 ? ( + {fontsLoaded && ( { }} /> - ) : null} + )} void; toggleRtl: () => void; - toggleThemeVersion: () => void; toggleCollapsed: () => void; toggleCustomFont: () => void; toggleRippleEffect: () => void; toggleShouldUseDeviceColors?: () => void; - theme: MD2Theme | MD3Theme; + theme: MD3Theme; rtl: boolean; collapsed: boolean; customFontLoaded: boolean; diff --git a/example/src/ScreenWrapper.tsx b/example/src/ScreenWrapper.tsx index eee3b5f58d..d810689ecb 100644 --- a/example/src/ScreenWrapper.tsx +++ b/example/src/ScreenWrapper.tsx @@ -8,10 +8,9 @@ import { ViewStyle, } from 'react-native'; +import { useTheme } from 'react-native-paper'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; -import { useExampleTheme } from './hooks/useExampleTheme'; - type Props = ScrollViewProps & { children: React.ReactNode; withScrollView?: boolean; @@ -26,14 +25,14 @@ export default function ScreenWrapper({ contentContainerStyle, ...rest }: Props) { - const theme = useExampleTheme(); + const { colors } = useTheme(); const insets = useSafeAreaInsets(); const containerStyle = [ styles.container, { - backgroundColor: theme.colors.background, + backgroundColor: colors.background, paddingBottom: insets.bottom, paddingLeft: insets.left, paddingRight: insets.left, diff --git a/example/src/hooks/useExampleTheme.ts b/example/src/hooks/useExampleTheme.ts deleted file mode 100644 index 9196f044b0..0000000000 --- a/example/src/hooks/useExampleTheme.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { MD2Theme, MD3Theme, useTheme } from 'react-native-paper'; - -export const useExampleTheme = () => useTheme(); diff --git a/example/src/index.native.tsx b/example/src/index.native.tsx index 0878a1f13b..c6bba2b1bd 100644 --- a/example/src/index.native.tsx +++ b/example/src/index.native.tsx @@ -9,13 +9,7 @@ import { useFonts } from 'expo-font'; import { useKeepAwake } from 'expo-keep-awake'; import { StatusBar } from 'expo-status-bar'; import * as Updates from 'expo-updates'; -import { - PaperProvider, - MD2DarkTheme, - MD2LightTheme, - MD3DarkTheme, - MD3LightTheme, -} from 'react-native-paper'; +import { PaperProvider, MD3DarkTheme, MD3LightTheme } from 'react-native-paper'; import { SafeAreaInsetsContext } from 'react-native-safe-area-context'; import DrawerItems from './DrawerItems'; @@ -49,7 +43,6 @@ export default function PaperExample() { const [shouldUseDeviceColors, setShouldUseDeviceColors] = React.useState(true); const [isDarkMode, setIsDarkMode] = React.useState(false); - const [themeVersion, setThemeVersion] = React.useState<2 | 3>(3); const [rtl, setRtl] = React.useState( I18nManager.getConstants().isRTL ); @@ -59,10 +52,6 @@ export default function PaperExample() { const { theme: mdTheme } = useMaterial3Theme(); const theme = React.useMemo(() => { - if (themeVersion === 2) { - return isDarkMode ? MD2DarkTheme : MD2LightTheme; - } - if (!deviceColorsSupported || !shouldUseDeviceColors) { return isDarkMode ? MD3DarkTheme : MD3LightTheme; } @@ -70,7 +59,7 @@ export default function PaperExample() { return isDarkMode ? { ...MD3DarkTheme, colors: mdTheme.dark } : { ...MD3LightTheme, colors: mdTheme.light }; - }, [isDarkMode, mdTheme, shouldUseDeviceColors, themeVersion]); + }, [isDarkMode, mdTheme, shouldUseDeviceColors]); React.useEffect(() => { const restoreState = async () => { @@ -144,12 +133,6 @@ export default function PaperExample() { toggleCollapsed: () => setCollapsed(!collapsed), toggleCustomFont: () => setCustomFont(!customFontLoaded), toggleRippleEffect: () => setRippleEffectEnabled(!rippleEffectEnabled), - toggleThemeVersion: () => { - setCustomFont(false); - setCollapsed(false); - setThemeVersion((oldThemeVersion) => (oldThemeVersion === 2 ? 3 : 2)); - setRippleEffectEnabled(true); - }, customFontLoaded, rippleEffectEnabled, collapsed, @@ -213,7 +196,7 @@ export default function PaperExample() { ); }} - + diff --git a/example/src/index.tsx b/example/src/index.tsx index 76607763f1..ce4df07253 100644 --- a/example/src/index.tsx +++ b/example/src/index.tsx @@ -5,13 +5,7 @@ import { createDrawerNavigator } from '@react-navigation/drawer'; import { InitialState, NavigationContainer } from '@react-navigation/native'; import { useFonts } from 'expo-font'; import { useKeepAwake } from 'expo-keep-awake'; -import { - PaperProvider, - MD3DarkTheme, - MD3LightTheme, - MD2DarkTheme, - MD2LightTheme, -} from 'react-native-paper'; +import { PaperProvider, MD3DarkTheme, MD3LightTheme } from 'react-native-paper'; import { SafeAreaInsetsContext } from 'react-native-safe-area-context'; import DrawerItems from './DrawerItems'; @@ -43,18 +37,13 @@ export default function PaperExample() { >(); const [isDarkMode, setIsDarkMode] = React.useState(false); - const [themeVersion, setThemeVersion] = React.useState<2 | 3>(3); const [collapsed, setCollapsed] = React.useState(false); const [customFontLoaded, setCustomFont] = React.useState(false); const [rippleEffectEnabled, setRippleEffectEnabled] = React.useState(true); const theme = React.useMemo(() => { - if (themeVersion === 2) { - return isDarkMode ? MD2DarkTheme : MD2LightTheme; - } - return isDarkMode ? MD3DarkTheme : MD3LightTheme; - }, [isDarkMode, themeVersion]); + }, [isDarkMode]); React.useEffect(() => { const restoreState = async () => { @@ -112,12 +101,6 @@ export default function PaperExample() { const preferences = React.useMemo( () => ({ toggleTheme: () => setIsDarkMode((oldValue) => !oldValue), - toggleThemeVersion: () => { - setCustomFont(false); - setCollapsed(false); - setThemeVersion((oldThemeVersion) => (oldThemeVersion === 2 ? 3 : 2)); - setRippleEffectEnabled(true); - }, toggleCollapsed: () => setCollapsed(!collapsed), toggleCustomFont: () => setCustomFont(!customFontLoaded), toggleRippleEffect: () => setRippleEffectEnabled(!rippleEffectEnabled), diff --git a/src/babel/__fixtures__/rewrite-imports/code.js b/src/babel/__fixtures__/rewrite-imports/code.js index cc5e6d0b5c..6509ef2f67 100644 --- a/src/babel/__fixtures__/rewrite-imports/code.js +++ b/src/babel/__fixtures__/rewrite-imports/code.js @@ -5,7 +5,6 @@ import { Button, FAB, Appbar, - MD2Colors, MD3Colors, NonExistent, NonExistentSecond as Stuff, diff --git a/src/babel/__fixtures__/rewrite-imports/output.js b/src/babel/__fixtures__/rewrite-imports/output.js index ecaff8d814..7204b0ca33 100644 --- a/src/babel/__fixtures__/rewrite-imports/output.js +++ b/src/babel/__fixtures__/rewrite-imports/output.js @@ -4,7 +4,6 @@ import BottomNavigation from "react-native-paper/lib/module/components/BottomNav import Button from "react-native-paper/lib/module/components/Button/Button"; import FAB from "react-native-paper/lib/module/components/FAB"; import Appbar from "react-native-paper/lib/module/components/Appbar"; -import * as MD2Colors from "react-native-paper/lib/module/styles/themes/v2/colors"; import { MD3Colors } from "react-native-paper/lib/module/styles/themes/v3/tokens"; import { NonExistent, NonExistentSecond as Stuff } from "react-native-paper/lib/module/index.js"; import { ThemeProvider } from "react-native-paper/lib/module/core/theming"; diff --git a/src/components/ActivityIndicator.tsx b/src/components/ActivityIndicator.tsx index 5a3b9f8736..5ec96229a1 100644 --- a/src/components/ActivityIndicator.tsx +++ b/src/components/ActivityIndicator.tsx @@ -45,10 +45,10 @@ const DURATION = 2400; * ## Usage * ```js * import * as React from 'react'; - * import { ActivityIndicator, MD2Colors } from 'react-native-paper'; + * import { ActivityIndicator, MD3Colors } from 'react-native-paper'; * * const MyComponent = () => ( - * + * * ); * * export default MyComponent; diff --git a/src/components/Badge.tsx b/src/components/Badge.tsx index 54c70770f2..452d098555 100644 --- a/src/components/Badge.tsx +++ b/src/components/Badge.tsx @@ -88,7 +88,8 @@ const Badge = ({ const { backgroundColor = theme.isV3 ? theme.colors.error - : theme.colors?.notification, + : // @ts-expect-error TODO: Remove it + theme.colors?.notification, ...restStyle } = (StyleSheet.flatten(style) || {}) as TextStyle; @@ -109,7 +110,6 @@ const Badge = ({ backgroundColor, color: textColor, fontSize: size * 0.5, - ...(!theme.isV3 && theme.fonts.regular), lineHeight: size / fontScale, height: size, minWidth: size, diff --git a/src/components/Surface.tsx b/src/components/Surface.tsx index fc551f688d..0a369fb80d 100644 --- a/src/components/Surface.tsx +++ b/src/components/Surface.tsx @@ -10,7 +10,7 @@ import { } from 'react-native'; import { useInternalTheme } from '../core/theming'; -import overlay, { isAnimatedValue } from '../styles/overlay'; +import { isAnimatedValue } from '../styles/overlay'; import shadow from '../styles/shadow'; import type { ThemeProp, MD3Elevation } from '../types'; import { forwardRef } from '../utils/forwardRef'; @@ -53,30 +53,6 @@ export type Props = Omit, 'style'> & { ref?: React.RefObject; }; -const MD2Surface = forwardRef( - ({ style, theme: overrideTheme, ...rest }: Omit, ref) => { - const { elevation = 4 } = (StyleSheet.flatten(style) || {}) as ViewStyle; - const { dark: isDarkTheme, mode, colors } = useInternalTheme(overrideTheme); - - return ( - - ); - } -); - const outerLayerStyleProperties: (keyof ViewStyle)[] = [ 'position', 'alignSelf', @@ -269,13 +245,6 @@ const Surface = forwardRef( ) => { const theme = useInternalTheme(overridenTheme); - if (!theme.isV3) - return ( - - {children} - - ); - const { colors } = theme; const inputRange = [0, 1, 2, 3, 4, 5]; diff --git a/src/core/PaperProvider.tsx b/src/core/PaperProvider.tsx index 51839a5fc7..abeaf2590d 100644 --- a/src/core/PaperProvider.tsx +++ b/src/core/PaperProvider.tsx @@ -77,14 +77,12 @@ const PaperProvider = (props: Props) => { }, [props.theme, isOnlyVersionInTheme]); const theme = React.useMemo(() => { - const themeVersion = props.theme?.version || 3; const scheme = colorScheme || 'light'; - const defaultThemeBase = defaultThemesByVersion[themeVersion][scheme]; + const defaultThemeBase = defaultThemesByVersion[scheme]; const extendedThemeBase = { ...defaultThemeBase, ...props.theme, - version: themeVersion, animation: { ...props.theme?.animation, scale: reduceMotionEnabled ? 0 : 1, @@ -93,7 +91,8 @@ const PaperProvider = (props: Props) => { return { ...extendedThemeBase, - isV3: extendedThemeBase.version === 3, + // TODO: Remove it completely + isV3: true, }; }, [colorScheme, props.theme, reduceMotionEnabled]); diff --git a/src/core/theming.tsx b/src/core/theming.tsx index 44223f032a..fe4c67a0bf 100644 --- a/src/core/theming.tsx +++ b/src/core/theming.tsx @@ -3,12 +3,7 @@ import type { ComponentType } from 'react'; import { $DeepPartial, createTheming } from '@callstack/react-theme-provider'; import color from 'color'; -import { - MD2DarkTheme, - MD2LightTheme, - MD3DarkTheme, - MD3LightTheme, -} from '../styles/themes'; +import { MD3DarkTheme, MD3LightTheme } from '../styles/themes'; import type { InternalTheme, MD3Theme, @@ -37,29 +32,16 @@ export const withInternalTheme = ( ) => withTheme(WrappedComponent); export const defaultThemesByVersion = { - 2: { - light: MD2LightTheme, - dark: MD2DarkTheme, - }, - 3: { - light: MD3LightTheme, - dark: MD3DarkTheme, - }, + light: MD3LightTheme, + dark: MD3DarkTheme, }; -export const getTheme = < - Scheme extends boolean = false, - IsVersion3 extends boolean = true ->( - isDark: Scheme = false as Scheme, - isV3: IsVersion3 = true as IsVersion3 -): (typeof defaultThemesByVersion)[IsVersion3 extends true - ? 3 - : 2][Scheme extends true ? 'dark' : 'light'] => { - const themeVersion = isV3 ? 3 : 2; +export const getTheme = ( + isDark: Scheme = false as Scheme +): (typeof defaultThemesByVersion)[Scheme extends true ? 'dark' : 'light'] => { const scheme = isDark ? 'dark' : 'light'; - return defaultThemesByVersion[themeVersion][scheme]; + return defaultThemesByVersion[scheme]; }; // eslint-disable-next-line no-redeclare diff --git a/src/index.tsx b/src/index.tsx index 1b20528787..40757a1158 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -13,15 +13,12 @@ export * from './styles/themes'; export { default as Provider } from './core/PaperProvider'; export { default as PaperProvider } from './core/PaperProvider'; export { default as shadow } from './styles/shadow'; -export { default as overlay } from './styles/overlay'; export { default as configureFonts } from './styles/fonts'; import * as Avatar from './components/Avatar/Avatar'; import * as Drawer from './components/Drawer/Drawer'; import * as List from './components/List/List'; -import * as MD2Colors from './styles/themes/v2/colors'; -export { MD2Colors }; export { Avatar, List, Drawer }; export * from './components/FAB/AnimatedFAB'; @@ -161,7 +158,6 @@ export type { } from './react-navigation'; export type { - MD2Theme, MD3Theme, ThemeBase, MD3Elevation, diff --git a/src/styles/fonts.tsx b/src/styles/fonts.tsx index e3b5017fc4..8d26388853 100644 --- a/src/styles/fonts.tsx +++ b/src/styles/fonts.tsx @@ -1,69 +1,6 @@ -import { Platform, PlatformOSType } from 'react-native'; - -import type { Fonts, MD3Type, MD3Typescale, MD3TypescaleKey } from '../types'; +import type { MD3Type, MD3Typescale, MD3TypescaleKey } from '../types'; import { typescale } from './themes/v3/tokens'; -export const fontConfig = { - web: { - regular: { - fontFamily: 'Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif', - fontWeight: '400' as '400', - }, - medium: { - fontFamily: 'Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif', - fontWeight: '500' as '500', - }, - light: { - fontFamily: 'Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif', - fontWeight: '300' as '300', - }, - thin: { - fontFamily: 'Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif', - fontWeight: '100' as '100', - }, - }, - ios: { - regular: { - fontFamily: 'System', - fontWeight: '400' as '400', - }, - medium: { - fontFamily: 'System', - fontWeight: '500' as '500', - }, - light: { - fontFamily: 'System', - fontWeight: '300' as '300', - }, - thin: { - fontFamily: 'System', - fontWeight: '100' as '100', - }, - }, - default: { - regular: { - fontFamily: 'sans-serif', - fontWeight: 'normal' as 'normal', - }, - medium: { - fontFamily: 'sans-serif-medium', - fontWeight: 'normal' as 'normal', - }, - light: { - fontFamily: 'sans-serif-light', - fontWeight: 'normal' as 'normal', - }, - thin: { - fontFamily: 'sans-serif-thin', - fontWeight: 'normal' as 'normal', - }, - }, -}; - -type MD2FontsConfig = { - [platform in PlatformOSType | 'default']?: Fonts; -}; - type MD3FontsConfig = | { [key in MD3TypescaleKey]: Partial; @@ -73,11 +10,6 @@ type MD3FontsConfig = } | Partial; -function configureV2Fonts(config: MD2FontsConfig): Fonts { - const fonts = Platform.select({ ...fontConfig, ...config }) as Fonts; - return fonts; -} - function configureV3Fonts( config: MD3FontsConfig ): MD3Typescale | (MD3Typescale & { [key: string]: MD3Type }) { @@ -110,34 +42,20 @@ function configureV3Fonts( ); } -// eslint-disable-next-line no-redeclare -export default function configureFonts(params: { isV3: false }): Fonts; -// eslint-disable-next-line no-redeclare -export default function configureFonts(params: { - config?: MD2FontsConfig; - isV3: false; -}): Fonts; // eslint-disable-next-line no-redeclare export default function configureFonts(params?: { config?: Partial; - isV3?: true; }): MD3Typescale; // eslint-disable-next-line no-redeclare export default function configureFonts(params?: { config?: Partial>>; - isV3?: true; }): MD3Typescale; // eslint-disable-next-line no-redeclare export default function configureFonts(params: { config: Record; - isV3?: true; }): MD3Typescale & { [key: string]: MD3Type }; // eslint-disable-next-line no-redeclare export default function configureFonts(params?: any) { - const { isV3 = true, config } = params || {}; - - if (isV3) { - return configureV3Fonts(config); - } - return configureV2Fonts(config); + const { config } = params || {}; + return configureV3Fonts(config); } diff --git a/src/styles/overlay.tsx b/src/styles/overlay.tsx index f9e6f8f9a5..7af142bbf3 100644 --- a/src/styles/overlay.tsx +++ b/src/styles/overlay.tsx @@ -1,70 +1,5 @@ import { Animated } from 'react-native'; -import color from 'color'; - -import { MD2DarkTheme } from './themes/v2/DarkTheme'; - export const isAnimatedValue = ( it: number | string | Animated.AnimatedInterpolation ): it is Animated.Value => it instanceof Animated.Value; - -export default function overlay( - elevation: T, - surfaceColor: string = MD2DarkTheme.colors?.surface -): T extends number ? string : Animated.AnimatedInterpolation { - if (isAnimatedValue(elevation)) { - const inputRange = [0, 1, 2, 3, 8, 24]; - - // @ts-expect-error: TS doesn't seem to refine the type correctly - return elevation.interpolate({ - inputRange, - outputRange: inputRange.map((elevation) => { - return calculateColor(surfaceColor, elevation); - }), - }); - } - - // @ts-expect-error: TS doesn't seem to refine the type correctly - return calculateColor(surfaceColor, elevation); -} - -function calculateColor(surfaceColor: string, elevation: number = 1) { - let overlayTransparency: number; - if (elevation >= 1 && elevation <= 24) { - overlayTransparency = elevationOverlayTransparency[elevation]; - } else if (elevation > 24) { - overlayTransparency = elevationOverlayTransparency[24]; - } else { - overlayTransparency = elevationOverlayTransparency[1]; - } - return color(surfaceColor) - .mix(color('white'), overlayTransparency * 0.01) - .hex(); -} - -const elevationOverlayTransparency: Record = { - 1: 5, - 2: 7, - 3: 8, - 4: 9, - 5: 10, - 6: 11, - 7: 11.5, - 8: 12, - 9: 12.5, - 10: 13, - 11: 13.5, - 12: 14, - 13: 14.25, - 14: 14.5, - 15: 14.75, - 16: 15, - 17: 15.12, - 18: 15.24, - 19: 15.36, - 20: 15.48, - 21: 15.6, - 22: 15.72, - 23: 15.84, - 24: 16, -}; diff --git a/src/styles/shadow.tsx b/src/styles/shadow.tsx index dcc11e8b65..57cc3612de 100644 --- a/src/styles/shadow.tsx +++ b/src/styles/shadow.tsx @@ -1,73 +1,12 @@ import { Animated } from 'react-native'; -import * as MD2Colors from './themes/v2/colors'; import { MD3Colors } from './themes/v3/tokens'; -const SHADOW_COLOR = MD2Colors.black; -const SHADOW_OPACITY = 0.24; const MD3_SHADOW_OPACITY = 0.3; const MD3_SHADOW_COLOR = MD3Colors.primary0; -export default function shadow( - elevation: number | Animated.Value = 0, - isV3 = false -) { - return isV3 ? v3Shadow(elevation) : v2Shadow(elevation); -} - -function v2Shadow(elevation: number | Animated.Value = 0) { - if (elevation instanceof Animated.Value) { - const inputRange = [0, 1, 2, 3, 8, 24]; - - return { - shadowColor: SHADOW_COLOR, - shadowOffset: { - width: new Animated.Value(0), - height: elevation.interpolate({ - inputRange, - outputRange: [0, 0.5, 0.75, 2, 7, 23], - }), - }, - shadowOpacity: elevation.interpolate({ - inputRange: [0, 1], - outputRange: [0, SHADOW_OPACITY], - extrapolate: 'clamp', - }), - shadowRadius: elevation.interpolate({ - inputRange, - outputRange: [0, 0.75, 1.5, 3, 8, 24], - }), - }; - } else { - if (elevation === 0) { - return {}; - } - - let height, radius; - switch (elevation) { - case 1: - height = 0.5; - radius = 0.75; - break; - case 2: - height = 0.75; - radius = 1.5; - break; - default: - height = elevation - 1; - radius = elevation; - } - - return { - shadowColor: SHADOW_COLOR, - shadowOffset: { - width: 0, - height, - }, - shadowOpacity: SHADOW_OPACITY, - shadowRadius: radius, - }; - } +export default function shadow(elevation: number | Animated.Value = 0) { + return v3Shadow(elevation); } function v3Shadow(elevation: number | Animated.Value = 0) { diff --git a/src/styles/themes/index.ts b/src/styles/themes/index.ts index 3db1a460ad..39bcb6648c 100644 --- a/src/styles/themes/index.ts +++ b/src/styles/themes/index.ts @@ -1,4 +1,2 @@ export { MD3LightTheme } from './v3/LightTheme'; export { MD3DarkTheme } from './v3/DarkTheme'; -export { MD2LightTheme } from './v2/LightTheme'; -export { MD2DarkTheme } from './v2/DarkTheme'; diff --git a/src/styles/themes/v2/DarkTheme.tsx b/src/styles/themes/v2/DarkTheme.tsx deleted file mode 100644 index 9eaa576dcb..0000000000 --- a/src/styles/themes/v2/DarkTheme.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import color from 'color'; - -import { black, pinkA100, white } from './colors'; -import { MD2LightTheme } from './LightTheme'; -import type { Fonts, MD2Theme } from '../../../types'; -import configureFonts from '../../fonts'; - -export const MD2DarkTheme: MD2Theme = { - ...MD2LightTheme, - dark: true, - mode: 'adaptive', - version: 2, - isV3: false, - colors: { - ...MD2LightTheme.colors, - primary: '#BB86FC', - accent: '#03dac6', - background: '#121212', - surface: '#121212', - error: '#CF6679', - onSurface: '#FFFFFF', - text: white, - disabled: color(white).alpha(0.38).rgb().string(), - placeholder: color(white).alpha(0.54).rgb().string(), - backdrop: color(black).alpha(0.5).rgb().string(), - notification: pinkA100, - tooltip: 'rgba(230, 225, 229, 1)', - }, - fonts: configureFonts({ isV3: false }) as Fonts, -}; diff --git a/src/styles/themes/v2/LightTheme.tsx b/src/styles/themes/v2/LightTheme.tsx deleted file mode 100644 index 8566bdcc40..0000000000 --- a/src/styles/themes/v2/LightTheme.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import color from 'color'; - -import { black, pinkA400, white } from './colors'; -import type { Fonts, MD2Theme } from '../../../types'; -import configureFonts from '../../fonts'; - -export const MD2LightTheme: MD2Theme = { - dark: false, - roundness: 4, - version: 2, - isV3: false, - colors: { - primary: '#6200ee', - accent: '#03dac4', - background: '#f6f6f6', - surface: white, - error: '#B00020', - text: black, - onSurface: '#000000', - disabled: color(black).alpha(0.26).rgb().string(), - placeholder: color(black).alpha(0.54).rgb().string(), - backdrop: color(black).alpha(0.5).rgb().string(), - notification: pinkA400, - tooltip: 'rgba(28, 27, 31, 1)', - }, - fonts: configureFonts({ isV3: false }) as Fonts, - animation: { - scale: 1.0, - }, -}; diff --git a/src/styles/themes/v2/colors.tsx b/src/styles/themes/v2/colors.tsx index 89f6192f08..e57f2c0fee 100644 --- a/src/styles/themes/v2/colors.tsx +++ b/src/styles/themes/v2/colors.tsx @@ -1,277 +1,3 @@ -export const transparent = 'rgba(255, 255, 255, 0)'; - -export const red50 = '#ffebee'; -export const red100 = '#ffcdd2'; -export const red200 = '#ef9a9a'; -export const red300 = '#e57373'; -export const red400 = '#ef5350'; -export const red500 = '#f44336'; -export const red600 = '#e53935'; -export const red700 = '#d32f2f'; -export const red800 = '#c62828'; -export const red900 = '#b71c1c'; -export const redA100 = '#ff8a80'; -export const redA200 = '#ff5252'; -export const redA400 = '#ff1744'; -export const redA700 = '#d50000'; - -export const pink50 = '#fce4ec'; -export const pink100 = '#f8bbd0'; -export const pink200 = '#f48fb1'; -export const pink300 = '#f06292'; -export const pink400 = '#ec407a'; -export const pink500 = '#e91e63'; -export const pink600 = '#d81b60'; -export const pink700 = '#c2185b'; -export const pink800 = '#ad1457'; -export const pink900 = '#880e4f'; -export const pinkA100 = '#ff80ab'; -export const pinkA200 = '#ff4081'; -export const pinkA400 = '#f50057'; -export const pinkA700 = '#c51162'; - -export const purple50 = '#f3e5f5'; -export const purple100 = '#e1bee7'; -export const purple200 = '#ce93d8'; -export const purple300 = '#ba68c8'; -export const purple400 = '#ab47bc'; -export const purple500 = '#9c27b0'; -export const purple600 = '#8e24aa'; -export const purple700 = '#7b1fa2'; -export const purple800 = '#6a1b9a'; -export const purple900 = '#4a148c'; -export const purpleA100 = '#ea80fc'; -export const purpleA200 = '#e040fb'; -export const purpleA400 = '#d500f9'; -export const purpleA700 = '#aa00ff'; - -export const deepPurple50 = '#ede7f6'; -export const deepPurple100 = '#d1c4e9'; -export const deepPurple200 = '#b39ddb'; -export const deepPurple300 = '#9575cd'; -export const deepPurple400 = '#7e57c2'; -export const deepPurple500 = '#673ab7'; -export const deepPurple600 = '#5e35b1'; -export const deepPurple700 = '#512da8'; -export const deepPurple800 = '#4527a0'; -export const deepPurple900 = '#311b92'; -export const deepPurpleA100 = '#b388ff'; -export const deepPurpleA200 = '#7c4dff'; -export const deepPurpleA400 = '#651fff'; -export const deepPurpleA700 = '#6200ea'; - -export const indigo50 = '#e8eaf6'; -export const indigo100 = '#c5cae9'; -export const indigo200 = '#9fa8da'; -export const indigo300 = '#7986cb'; -export const indigo400 = '#5c6bc0'; -export const indigo500 = '#3f51b5'; -export const indigo600 = '#3949ab'; -export const indigo700 = '#303f9f'; -export const indigo800 = '#283593'; -export const indigo900 = '#1a237e'; -export const indigoA100 = '#8c9eff'; -export const indigoA200 = '#536dfe'; -export const indigoA400 = '#3d5afe'; -export const indigoA700 = '#304ffe'; - -export const blue50 = '#e3f2fd'; -export const blue100 = '#bbdefb'; -export const blue200 = '#90caf9'; -export const blue300 = '#64b5f6'; -export const blue400 = '#42a5f5'; -export const blue500 = '#2196f3'; -export const blue600 = '#1e88e5'; -export const blue700 = '#1976d2'; -export const blue800 = '#1565c0'; -export const blue900 = '#0d47a1'; -export const blueA100 = '#82b1ff'; -export const blueA200 = '#448aff'; -export const blueA400 = '#2979ff'; -export const blueA700 = '#2962ff'; - -export const lightBlue50 = '#e1f5fe'; -export const lightBlue100 = '#b3e5fc'; -export const lightBlue200 = '#81d4fa'; -export const lightBlue300 = '#4fc3f7'; -export const lightBlue400 = '#29b6f6'; -export const lightBlue500 = '#03a9f4'; -export const lightBlue600 = '#039be5'; -export const lightBlue700 = '#0288d1'; -export const lightBlue800 = '#0277bd'; -export const lightBlue900 = '#01579b'; -export const lightBlueA100 = '#80d8ff'; -export const lightBlueA200 = '#40c4ff'; -export const lightBlueA400 = '#00b0ff'; -export const lightBlueA700 = '#0091ea'; - -export const cyan50 = '#e0f7fa'; -export const cyan100 = '#b2ebf2'; -export const cyan200 = '#80deea'; -export const cyan300 = '#4dd0e1'; -export const cyan400 = '#26c6da'; -export const cyan500 = '#00bcd4'; -export const cyan600 = '#00acc1'; -export const cyan700 = '#0097a7'; -export const cyan800 = '#00838f'; -export const cyan900 = '#006064'; -export const cyanA100 = '#84ffff'; -export const cyanA200 = '#18ffff'; -export const cyanA400 = '#00e5ff'; -export const cyanA700 = '#00b8d4'; - -export const teal50 = '#e0f2f1'; -export const teal100 = '#b2dfdb'; -export const teal200 = '#80cbc4'; -export const teal300 = '#4db6ac'; -export const teal400 = '#26a69a'; -export const teal500 = '#009688'; -export const teal600 = '#00897b'; -export const teal700 = '#00796b'; -export const teal800 = '#00695c'; -export const teal900 = '#004d40'; -export const tealA100 = '#a7ffeb'; -export const tealA200 = '#64ffda'; -export const tealA400 = '#1de9b6'; -export const tealA700 = '#00bfa5'; - -export const green50 = '#e8f5e9'; -export const green100 = '#c8e6c9'; -export const green200 = '#a5d6a7'; -export const green300 = '#81c784'; -export const green400 = '#66bb6a'; -export const green500 = '#4caf50'; -export const green600 = '#43a047'; -export const green700 = '#388e3c'; -export const green800 = '#2e7d32'; -export const green900 = '#1b5e20'; -export const greenA100 = '#b9f6ca'; -export const greenA200 = '#69f0ae'; -export const greenA400 = '#00e676'; -export const greenA700 = '#00c853'; - -export const lightGreen50 = '#f1f8e9'; -export const lightGreen100 = '#dcedc8'; -export const lightGreen200 = '#c5e1a5'; -export const lightGreen300 = '#aed581'; -export const lightGreen400 = '#9ccc65'; -export const lightGreen500 = '#8bc34a'; -export const lightGreen600 = '#7cb342'; -export const lightGreen700 = '#689f38'; -export const lightGreen800 = '#558b2f'; -export const lightGreen900 = '#33691e'; -export const lightGreenA100 = '#ccff90'; -export const lightGreenA200 = '#b2ff59'; -export const lightGreenA400 = '#76ff03'; -export const lightGreenA700 = '#64dd17'; - -export const lime50 = '#f9fbe7'; -export const lime100 = '#f0f4c3'; -export const lime200 = '#e6ee9c'; -export const lime300 = '#dce775'; -export const lime400 = '#d4e157'; -export const lime500 = '#cddc39'; -export const lime600 = '#c0ca33'; -export const lime700 = '#afb42b'; -export const lime800 = '#9e9d24'; -export const lime900 = '#827717'; -export const limeA100 = '#f4ff81'; -export const limeA200 = '#eeff41'; -export const limeA400 = '#c6ff00'; -export const limeA700 = '#aeea00'; - -export const yellow50 = '#fffde7'; -export const yellow100 = '#fff9c4'; -export const yellow200 = '#fff59d'; -export const yellow300 = '#fff176'; -export const yellow400 = '#ffee58'; -export const yellow500 = '#ffeb3b'; -export const yellow600 = '#fdd835'; -export const yellow700 = '#fbc02d'; -export const yellow800 = '#f9a825'; -export const yellow900 = '#f57f17'; -export const yellowA100 = '#ffff8d'; -export const yellowA200 = '#ffff00'; -export const yellowA400 = '#ffea00'; -export const yellowA700 = '#ffd600'; - -export const amber50 = '#fff8e1'; -export const amber100 = '#ffecb3'; -export const amber200 = '#ffe082'; -export const amber300 = '#ffd54f'; -export const amber400 = '#ffca28'; -export const amber500 = '#ffc107'; -export const amber600 = '#ffb300'; -export const amber700 = '#ffa000'; -export const amber800 = '#ff8f00'; -export const amber900 = '#ff6f00'; -export const amberA100 = '#ffe57f'; -export const amberA200 = '#ffd740'; -export const amberA400 = '#ffc400'; -export const amberA700 = '#ffab00'; - -export const orange50 = '#fff3e0'; -export const orange100 = '#ffe0b2'; -export const orange200 = '#ffcc80'; -export const orange300 = '#ffb74d'; -export const orange400 = '#ffa726'; -export const orange500 = '#ff9800'; -export const orange600 = '#fb8c00'; -export const orange700 = '#f57c00'; -export const orange800 = '#ef6c00'; -export const orange900 = '#e65100'; -export const orangeA100 = '#ffd180'; -export const orangeA200 = '#ffab40'; -export const orangeA400 = '#ff9100'; -export const orangeA700 = '#ff6d00'; - -export const deepOrange50 = '#fbe9e7'; -export const deepOrange100 = '#ffccbc'; -export const deepOrange200 = '#ffab91'; -export const deepOrange300 = '#ff8a65'; -export const deepOrange400 = '#ff7043'; -export const deepOrange500 = '#ff5722'; -export const deepOrange600 = '#f4511e'; -export const deepOrange700 = '#e64a19'; -export const deepOrange800 = '#d84315'; -export const deepOrange900 = '#bf360c'; -export const deepOrangeA100 = '#ff9e80'; -export const deepOrangeA200 = '#ff6e40'; -export const deepOrangeA400 = '#ff3d00'; -export const deepOrangeA700 = '#dd2c00'; - -export const brown50 = '#efebe9'; -export const brown100 = '#d7ccc8'; -export const brown200 = '#bcaaa4'; -export const brown300 = '#a1887f'; -export const brown400 = '#8d6e63'; -export const brown500 = '#795548'; -export const brown600 = '#6d4c41'; -export const brown700 = '#5d4037'; -export const brown800 = '#4e342e'; -export const brown900 = '#3e2723'; - -export const blueGrey50 = '#eceff1'; -export const blueGrey100 = '#cfd8dc'; -export const blueGrey200 = '#b0bec5'; -export const blueGrey300 = '#90a4ae'; -export const blueGrey400 = '#78909c'; -export const blueGrey500 = '#607d8b'; -export const blueGrey600 = '#546e7a'; -export const blueGrey700 = '#455a64'; -export const blueGrey800 = '#37474f'; -export const blueGrey900 = '#263238'; - -export const grey50 = '#fafafa'; -export const grey100 = '#f5f5f5'; -export const grey200 = '#eeeeee'; -export const grey300 = '#e0e0e0'; -export const grey400 = '#bdbdbd'; -export const grey500 = '#9e9e9e'; -export const grey600 = '#757575'; -export const grey700 = '#616161'; -export const grey800 = '#424242'; -export const grey900 = '#212121'; - +// TODO: Remove it completely export const black = '#000000'; export const white = '#ffffff'; diff --git a/src/types.tsx b/src/types.tsx index 175131cab3..cfa37779d0 100644 --- a/src/types.tsx +++ b/src/types.tsx @@ -19,30 +19,8 @@ export type Font = { fontStyle?: 'normal' | 'italic' | undefined; }; -export type Fonts = { - regular: Font; - medium: Font; - light: Font; - thin: Font; -}; - type Mode = 'adaptive' | 'exact'; -export type MD2Colors = { - primary: string; - background: string; - surface: string; - accent: string; - error: string; - text: string; - onSurface: string; - disabled: string; - placeholder: string; - backdrop: string; - notification: string; - tooltip: string; -}; - export type MD3Colors = { primary: string; primaryContainer: string; @@ -132,14 +110,7 @@ export type MD3Theme = ThemeBase & { fonts: MD3Typescale; }; -export type MD2Theme = ThemeBase & { - version: 2; - isV3: false; - colors: MD2Colors; - fonts: Fonts; -}; - -export type InternalTheme = MD2Theme | MD3Theme; +export type InternalTheme = MD3Theme; // MD3 types export enum MD3TypescaleKey {