import * as React from 'react';
import { I18nManager, StyleSheet, View, Platform } from 'react-native';
import { DrawerContentScrollView } from '@react-navigation/drawer';
import Constants, { ExecutionEnvironment } from 'expo-constants';
// import * as Updates from 'expo-updates';
import {
Badge,
Button,
Dialog,
Drawer,
MD2Colors,
MD3Colors,
Switch,
Text,
TouchableRipple,
Portal,
} from 'react-native-paper';
import { deviceColorsSupported, isWeb } from '../utils';
import { PreferencesContext, useExampleTheme } from './';
const DrawerItemsData = [
{
label: 'Inbox',
icon: 'inbox',
key: 0,
right: () => 44,
},
{
label: 'Starred',
icon: 'star',
key: 1,
right: ({ color }: { color: string }) => (
),
},
{ label: 'Sent mail', icon: 'send', key: 2 },
{ label: 'Colored label', icon: 'palette', key: 3 },
{
label: 'A very long title that will be truncated',
icon: 'delete',
key: 4,
right: () => ,
},
];
const DrawerCollapsedItemsData = [
{
label: 'Inbox',
focusedIcon: 'inbox',
unfocusedIcon: 'inbox-outline',
key: 0,
badge: 44,
},
{
label: 'Starred',
focusedIcon: 'star',
unfocusedIcon: 'star-outline',
key: 1,
},
{
label: 'Sent mail',
focusedIcon: 'send',
unfocusedIcon: 'send-outline',
key: 2,
},
{
label: 'A very long title that will be truncated',
focusedIcon: 'delete',
unfocusedIcon: 'delete-outline',
key: 3,
},
{
label: 'Full width',
focusedIcon: 'arrow-all',
key: 4,
},
{
focusedIcon: 'bell',
unfocusedIcon: 'bell-outline',
key: 5,
badge: true,
},
];
function DrawerItems() {
const [drawerItemIndex, setDrawerItemIndex] = React.useState(0);
const [showRTLDialog, setShowRTLDialog] = React.useState(false);
const preferences = React.useContext(PreferencesContext);
const _setDrawerItem = (index: number) => setDrawerItemIndex(index);
const { isV3, colors } = useExampleTheme();
const isIOS = Platform.OS === 'ios';
const expoGoExecution =
Constants.executionEnvironment === ExecutionEnvironment.StoreClient;
if (!preferences) throw new Error('PreferencesContext not provided');
const {
toggleShouldUseDeviceColors,
toggleTheme,
toggleRtl: toggleRTL,
toggleThemeVersion,
toggleCollapsed,
toggleCustomFont,
toggleRippleEffect,
customFontLoaded,
rippleEffectEnabled,
collapsed,
rtl: isRTL,
theme: { dark: isDarkTheme },
shouldUseDeviceColors,
} = preferences;
const _handleToggleRTL = () => {
if (expoGoExecution) {
setShowRTLDialog(true);
return;
}
toggleRTL();
I18nManager.forceRTL(!isRTL);
if (isWeb) {
Updates.reloadAsync();
}
};
const _handleDismissRTLDialog = () => {
setShowRTLDialog(false);
};
const coloredLabelTheme = {
colors: isV3
? {
secondaryContainer: MD3Colors.tertiary80,
onSecondaryContainer: MD3Colors.tertiary20,
}
: {
primary: MD2Colors.tealA200,
},
};
return (
{isV3 && collapsed && (
{DrawerCollapsedItemsData.map((props, index) => (
{
_setDrawerItem(index);
index === 4 && toggleCollapsed();
}}
/>
))}
)}
{!collapsed && (
<>
{DrawerItemsData.map((props, index) => (
_setDrawerItem(index)}
/>
))}
{deviceColorsSupported && isV3 ? (
Use device colors *
) : null}
Dark Theme
{!isWeb && (
RTL
)}
MD 2
{isV3 && (
Collapsed drawer *
)}
{isV3 && (
Custom font *
)}
{isIOS ? 'Highlight' : 'Ripple'} effect *
{isV3 && !collapsed && (
* - available only for MD3
)}
React Native Paper Version{' '}
{require('react-native-paper/package.json').version}
>
)}
);
}
const styles = StyleSheet.create({
drawerContent: {
flex: 1,
},
preference: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingVertical: 12,
paddingHorizontal: 16,
},
v3Preference: {
height: 56,
paddingHorizontal: 28,
},
badge: {
alignSelf: 'center',
},
collapsedSection: {
marginTop: 16,
},
annotation: {
marginHorizontal: 24,
marginVertical: 6,
},
});
export default DrawerItems;