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

97 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-05-10 22:16:03 +05:00
import React from 'react';
import {Text, 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-10-13 17:02:14 +05:00
import {Actions} from '../../provider/Actions';
import {eSendEvent} from '../../services/EventManager';
import {eClearSearch} from '../../utils/Events';
import NavigationService from '../../services/Navigation';
import {showContext} from '../../utils';
import {PressableButton} from '../PressableButton';
2020-10-13 17:02:14 +05:00
import {SIZE, WEIGHT} from "../../utils/SizeUtils";
import {DDS} from "../../services/DeviceDetection";
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-05-10 22:16:03 +05:00
if (!ignore) {
dispatch({
2020-10-13 17:02:14 +05:00
type: Actions.HEADER_TEXT_STATE,
2020-05-10 22:16:03 +05:00
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}
onLongPress={(event) => {
console.log(event.nativeEvent);
showContext(event, item.name);
}}
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
/>
{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
);
};