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

91 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-05-10 22:16:03 +05:00
import React from 'react';
2020-09-21 13:01:37 +05:00
import { Text, View } from 'react-native';
2020-05-10 22:16:03 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2020-09-21 13:01:37 +05:00
import { SIZE, WEIGHT } from '../../common/common';
import { useTracked } from '../../provider';
import { ACTIONS } from '../../provider/actions';
import { eSendEvent } from '../../services/eventManager';
import { eClearSearch } from '../../services/events';
import NavigationService from '../../services/NavigationService';
import { PressableButton } from '../PressableButton';
2020-05-10 22:16:03 +05:00
2020-09-29 23:14:07 +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 = () => {
if (!ignore) {
dispatch({
type: ACTIONS.HEADER_TEXT_STATE,
state: {
heading: item.name,
},
});
eSendEvent(eClearSearch);
}
item.func();
if (item.close) {
2020-09-21 13:01:37 +05:00
NavigationService.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',
2020-09-18 20:54:49 +05:00
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={SIZE.md + 1}
/>
{noTextMode ? null : (
<Text
style={{
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
2020-09-07 21:23:38 +05:00
color: colors.heading,
2020-05-10 22:16:03 +05:00
}}>
{item.name}
</Text>
)}
</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
);
};