Files
notesnook/apps/mobile/src/components/Menu/MenuListItem.js

84 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-05-10 22:16:03 +05:00
import React from 'react';
2020-11-20 01:23:05 +05:00
import {View} from 'react-native';
2020-05-10 22:16:03 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {useTracked} from '../../provider';
2020-11-20 01:23:05 +05:00
import {DDS} from '../../services/DeviceDetection';
2020-11-26 16:22:32 +05:00
import Navigation from '../../services/Navigation';
2020-11-20 01:23:05 +05:00
import {SIZE} from '../../utils/SizeUtils';
import {PressableButton} from '../PressableButton';
2020-11-09 20:26:20 +05:00
import Paragraph from '../Typography/Paragraph';
2020-05-10 22:16:03 +05:00
export const MenuListItem = ({item, index, noTextMode, ignore, testID}) => {
2020-05-10 22:16:03 +05:00
const [state, dispatch] = useTracked();
const {currentScreen, colors} = state;
const _onPress = (event) => {
2020-11-02 20:49:53 +05:00
if (item.func) {
2020-11-09 20:26:20 +05:00
item.func();
2020-11-02 20:49:53 +05:00
} else {
2020-11-26 16:22:32 +05:00
Navigation.navigate(
item.name,
{
menu: true,
},
{
heading: item.name,
id: item.name.toLowerCase() + '_navigation',
},
);
2020-11-02 20:49:53 +05:00
}
2020-05-10 22:16:03 +05:00
if (item.close) {
2020-11-26 16:22:32 +05:00
Navigation.closeDrawer();
2020-05-10 22:16:03 +05:00
}
};
return (
2020-09-08 22:22:33 +05:00
<PressableButton
2020-09-29 23:14:07 +05:00
testID={testID}
2020-09-08 14:36:25 +05:00
key={item.name + index}
2020-05-10 22:16:03 +05:00
onPress={_onPress}
2020-09-08 22:22:33 +05:00
color={
currentScreen === item.name.toLowerCase() ? colors.shade : 'transparent'
}
selectedColor={colors.accent}
alpha={!colors.night ? -0.02 : 0.02}
opacity={0.12}
customStyle={{
2020-05-10 22:16:03 +05:00
width: '100%',
alignSelf: 'center',
2020-09-08 22:22:33 +05:00
borderRadius: 0,
2020-05-10 22:16:03 +05:00
flexDirection: 'row',
2020-09-08 22:22:33 +05:00
paddingHorizontal: noTextMode ? 0 : 8,
2020-05-10 22:16:03 +05:00
justifyContent: noTextMode ? 'center' : 'space-between',
alignItems: 'center',
height: 50,
2020-05-10 22:16:03 +05:00
}}>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
}}>
<Icon
style={{
minWidth: noTextMode ? 5 : 35,
textAlignVertical: 'center',
textAlign: 'left',
}}
name={item.icon}
color={colors.accent}
size={DDS.isTab ? SIZE.md + 5 : SIZE.md + 1}
2020-05-10 22:16:03 +05:00
/>
2020-11-09 20:26:20 +05:00
{noTextMode ? null : <Paragraph size={SIZE.md}>{item.name}</Paragraph>}
2020-05-10 22:16:03 +05:00
</View>
{item.switch && !noTextMode ? (
<Icon
size={SIZE.lg}
color={item.on ? colors.accent : colors.icon}
name={item.on ? 'toggle-switch' : 'toggle-switch-off'}
/>
2020-09-07 21:23:38 +05:00
) : undefined}
2020-09-08 22:22:33 +05:00
</PressableButton>
2020-05-10 22:16:03 +05:00
);
};