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

409 lines
11 KiB
JavaScript
Raw Normal View History

2019-12-04 11:40:59 +05:00
import React, {useEffect, useState, createRef} from 'react';
import {
ScrollView,
View,
Text,
TouchableOpacity,
SafeAreaView,
Platform,
FlatList,
DeviceEventEmitter,
2019-12-14 16:00:16 +05:00
PixelRatio,
2019-12-04 11:40:59 +05:00
} from 'react-native';
import NavigationService from '../../services/NavigationService';
import {
COLOR_SCHEME,
SIZE,
br,
ph,
pv,
opacity,
FONT,
WEIGHT,
2019-12-07 12:05:15 +05:00
COLOR_SCHEME_DARK,
setColorScheme,
COLOR_SCHEME_LIGHT,
clearThemeUpdateListener,
onThemeUpdate,
2019-12-04 11:40:59 +05:00
} from '../../common/common';
import Icon from 'react-native-vector-icons/Feather';
import {getElevation, w, h, Toast} from '../../utils/utils';
2019-12-07 12:05:15 +05:00
import AsyncStorage from '@react-native-community/async-storage';
import {useForceUpdate} from '../../views/ListsEditor';
import {AnimatedSafeAreaView} from '../../views/Home';
2019-12-14 19:26:44 +05:00
import {useAppContext} from '../../provider/useAppContext';
2019-12-04 11:40:59 +05:00
2019-12-07 12:05:15 +05:00
export const Menu = ({close = () => {}, hide, update = () => {}}) => {
2019-12-14 19:26:44 +05:00
const {colors, changeColorScheme} = useAppContext();
2019-12-07 12:05:15 +05:00
return (
<AnimatedSafeAreaView
transition="backgroundColor"
2019-12-14 16:00:16 +05:00
duration={300}
2019-12-07 12:05:15 +05:00
style={{
2019-12-04 11:40:59 +05:00
height: '100%',
2019-12-07 12:05:15 +05:00
opacity: hide ? 0 : 1,
backgroundColor: colors.night ? colors.navbg : colors.navbg,
2019-12-04 11:40:59 +05:00
}}>
2019-12-10 22:03:39 +05:00
<View
style={{
height: 2,
width: '100%',
marginBottom: 5,
marginTop: Platform.OS == 'ios' ? h * 0.01 : h * 0.03,
}}
/>
2019-12-14 16:00:16 +05:00
2019-12-07 12:05:15 +05:00
<ScrollView
contentContainerStyle={{
justifyContent: 'space-between',
height: '100%',
}}>
<View>
<FlatList
data={[
{
name: 'Home',
icon: 'home',
func: () => NavigationService.push('Home'),
2019-12-07 12:05:15 +05:00
close: true,
},
2019-12-04 11:40:59 +05:00
2019-12-07 12:05:15 +05:00
{
name: 'Notebooks',
icon: 'book',
func: () =>
NavigationService.push('Folders', {
2019-12-07 12:05:15 +05:00
title: 'Notebooks',
}),
close: true,
},
{
name: 'Lists',
icon: 'list',
func: () => NavigationService.push('Lists'),
2019-12-07 12:05:15 +05:00
close: true,
},
{
name: 'Favorites',
icon: 'star',
func: () => NavigationService.push('Favorites'),
2019-12-07 12:05:15 +05:00
close: true,
},
2019-12-04 11:40:59 +05:00
2019-12-07 12:05:15 +05:00
{
name: 'Dark Mode',
icon: 'moon',
func: () => {
if (!colors.night) {
AsyncStorage.setItem(
'theme',
JSON.stringify(COLOR_SCHEME_DARK),
);
2019-12-14 19:26:44 +05:00
changeColorScheme(COLOR_SCHEME_DARK);
2019-12-07 12:05:15 +05:00
} else {
AsyncStorage.setItem(
'theme',
JSON.stringify(COLOR_SCHEME_LIGHT),
);
2019-12-14 19:26:44 +05:00
changeColorScheme(COLOR_SCHEME_LIGHT);
2019-12-07 12:05:15 +05:00
}
},
switch: true,
on: colors.night ? true : false,
close: false,
},
{
name: 'Trash',
icon: 'trash',
func: () => NavigationService.push('Trash'),
2019-12-07 12:05:15 +05:00
close: true,
},
{
name: 'Settings',
icon: 'settings',
func: () => NavigationService.push('Settings'),
2019-12-07 12:05:15 +05:00
close: true,
},
]}
keyExtractor={(item, index) => item.name}
renderItem={({item, index}) => (
<TouchableOpacity
activeOpacity={opacity}
onPress={() => {
item.close === false ? null : close();
2019-12-11 01:10:04 +05:00
2019-12-07 12:05:15 +05:00
item.func();
}}
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
width: '100%',
alignSelf: 'center',
2019-12-04 11:40:59 +05:00
flexDirection: 'row',
2019-12-07 12:05:15 +05:00
justifyContent: 'space-between',
2019-12-14 16:00:16 +05:00
alignItems: 'center',
paddingHorizontal: '5%',
2019-12-14 16:00:16 +05:00
paddingVertical: pv + 5,
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<View
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
flexDirection: 'row',
2019-12-14 16:00:16 +05:00
alignItems: 'center',
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<Icon
style={{
width: 30,
}}
name={item.icon}
color={colors.icon}
size={SIZE.md}
/>
<Text
style={{
2019-12-14 16:00:16 +05:00
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
2019-12-07 12:05:15 +05:00
color: colors.pri,
}}>
{item.name}
</Text>
</View>
{item.switch ? (
<Icon
size={SIZE.lg}
color={item.on ? colors.accent : colors.icon}
name={item.on ? 'toggle-right' : 'toggle-left'}
/>
) : (
undefined
)}
</TouchableOpacity>
)}
/>
2019-12-04 11:40:59 +05:00
2019-12-07 12:05:15 +05:00
<TouchableOpacity
onPress={() => {
close();
NavigationService.navigate('Tags');
}}
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
width: '100%',
alignSelf: 'center',
2019-12-04 11:40:59 +05:00
flexDirection: 'row',
2019-12-07 12:05:15 +05:00
justifyContent: 'space-between',
2019-12-04 11:40:59 +05:00
alignItems: 'flex-end',
paddingHorizontal: '5%',
2019-12-07 12:05:15 +05:00
marginTop: 15,
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<View
2019-12-04 11:40:59 +05:00
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
2019-12-14 16:00:16 +05:00
alignItems: 'center',
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<Icon
style={{
width: 30,
}}
name="tag"
color={colors.icon}
size={SIZE.md}
/>
2019-12-04 11:40:59 +05:00
<Text
style={{
2019-12-14 16:00:16 +05:00
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
2019-12-07 12:05:15 +05:00
color: colors.pri,
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
Tags
2019-12-04 11:40:59 +05:00
</Text>
2019-12-07 12:05:15 +05:00
</View>
</TouchableOpacity>
2019-12-04 11:40:59 +05:00
2019-12-07 12:05:15 +05:00
<ScrollView
contentContainerStyle={{
flexDirection: 'row',
flexWrap: 'wrap',
paddingHorizontal: '5%',
marginBottom: 0,
}}>
{[
'home',
'office',
'work',
'book_notes',
'poem',
'lists',
'water',
].map(item => (
2019-12-04 11:40:59 +05:00
<TouchableOpacity
2019-12-07 12:05:15 +05:00
onPress={() => {
close();
NavigationService.navigate('Notes', {
heading: item,
});
}}
2019-12-04 11:40:59 +05:00
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
2019-12-14 16:00:16 +05:00
padding: 7,
paddingLeft: 3.5,
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<Text
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
fontFamily: WEIGHT.regular,
2019-12-14 16:00:16 +05:00
fontSize: SIZE.xs,
2019-12-07 12:05:15 +05:00
color: colors.icon,
}}>
#{item}
</Text>
2019-12-04 11:40:59 +05:00
</TouchableOpacity>
2019-12-07 12:05:15 +05:00
))}
</ScrollView>
2019-12-04 11:40:59 +05:00
2019-12-07 12:05:15 +05:00
<ScrollView
contentContainerStyle={{
2019-12-04 11:40:59 +05:00
flexDirection: 'row',
2019-12-07 12:05:15 +05:00
flexWrap: 'wrap',
paddingHorizontal: '5%',
marginBottom: 15,
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
{['red', 'yellow', 'green', 'blue', 'purple', 'orange', 'gray'].map(
item => (
<TouchableOpacity
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
margin: 5,
}}>
<View
style={{
2019-12-14 16:00:16 +05:00
width: 35,
height: 35,
2019-12-07 12:05:15 +05:00
backgroundColor: item,
borderRadius: 100,
}}
/>
</TouchableOpacity>
),
)}
</ScrollView>
</View>
2019-12-04 11:40:59 +05:00
2019-12-07 12:05:15 +05:00
{/* <View
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
backgroundColor: '#F3A712',
width: '90%',
alignSelf: 'center',
2019-12-04 11:40:59 +05:00
borderRadius: 5,
2019-12-07 12:05:15 +05:00
flexDirection: 'row',
justifyContent: 'space-between',
2019-12-04 11:40:59 +05:00
alignItems: 'center',
2019-12-07 12:05:15 +05:00
height: 40,
paddingHorizontal: ph,
marginVertical: 10,
2019-12-04 11:40:59 +05:00
}}>
<Text
style={{
fontFamily: WEIGHT.medium,
color: 'white',
}}>
2019-12-07 12:05:15 +05:00
Upgrade to Pro
2019-12-04 11:40:59 +05:00
</Text>
2019-12-07 12:05:15 +05:00
<View
style={{
...getElevation(5),
paddingHorizontal: ph,
backgroundColor: 'white',
paddingVertical: pv - 8,
borderRadius: 5,
}}>
<Icon name="star" color="#FCBA04" size={SIZE.lg} />
</View>
</View> */}
2019-12-04 11:40:59 +05:00
2019-12-07 12:05:15 +05:00
<View
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
width: '100%',
justifyContent: 'space-between',
paddingHorizontal: '5%',
alignItems: 'center',
alignSelf: 'center',
marginBottom: 20,
flexDirection: 'row',
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<TouchableOpacity
onPress={() => {
close();
NavigationService.navigate('Login');
}}
activeOpacity={opacity}
2019-12-04 11:40:59 +05:00
style={{
2019-12-14 16:00:16 +05:00
paddingVertical: pv + 5,
2019-12-07 12:05:15 +05:00
width: '100%',
2019-12-14 16:00:16 +05:00
borderRadius: 5,
justifyContent: 'flex-start',
2019-12-07 12:05:15 +05:00
alignItems: 'center',
2019-12-14 16:00:16 +05:00
flexDirection: 'row',
2019-12-04 11:40:59 +05:00
}}>
2019-12-14 16:00:16 +05:00
<Icon name="log-in" color={colors.accent} size={SIZE.lg} />
2019-12-07 12:05:15 +05:00
<Text
style={{
2019-12-14 16:00:16 +05:00
fontFamily: WEIGHT.regular,
color: colors.accent,
fontSize: SIZE.md,
2019-12-07 12:05:15 +05:00
}}>
2019-12-14 16:00:16 +05:00
{' '}Login
2019-12-07 12:05:15 +05:00
</Text>
</TouchableOpacity>
{/* <Text
style={{
fontFamily: WEIGHT.semibold,
color: colors.accent,
fontSize: SIZE.md,
marginTop: 10,
}}>
Hi, Ammar!
</Text>
<Text
style={{
fontFamily: WEIGHT.regular,
color: colors.accent,
fontSize: SIZE.xs,
marginTop: 10,
}}>
80.45/100 MB
</Text> */}
{/* <View
style={{
borderRadius: 2.5,
backgroundColor: colors.accent,
marginTop: 10,
paddingHorizontal: 5,
paddingVertical: 2,
}}>
<Text
style={{
fontFamily: WEIGHT.bold,
fontSize: SIZE.xxs,
color: 'white',
}}>
Basic User
</Text>
</View> */}
</View>
</ScrollView>
</AnimatedSafeAreaView>
2019-12-07 12:05:15 +05:00
);
};