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

91 lines
2.6 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-10-13 17:02:14 +05:00
import {Actions} from '../../provider/Actions';
2020-11-20 01:23:05 +05:00
import {DDS} from '../../services/DeviceDetection';
2020-10-13 17:02:14 +05:00
import {eSendEvent} from '../../services/EventManager';
import NavigationService from '../../services/Navigation';
2020-11-20 01:23:05 +05:00
import {eClearSearch} from '../../utils/Events';
import { sideMenuRef } from '../../utils/Refs';
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-10-18 13:15:24 +05:00
if (!ignore && currentScreen !== item.name.toLowerCase()) {
2020-05-10 22:16:03 +05:00
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);
}
2020-11-20 01:23:05 +05:00
if (item.name.toLowerCase() === currentScreen) {
console.log('already here');
}
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-09 20:26:20 +05:00
NavigationService.navigate(item.name);
2020-11-02 20:49:53 +05:00
}
2020-05-10 22:16:03 +05:00
if (item.close) {
2020-11-20 19:09:01 +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',
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
);
};