Files
notesnook/apps/mobile/App.js

164 lines
4.0 KiB
JavaScript
Raw Normal View History

2019-12-04 11:29:40 +05:00
import React, {useState, useEffect} from 'react';
2019-11-17 16:02:19 +05:00
import NavigationService, {
AppContainer,
} from './src/services/NavigationService';
2019-11-23 06:25:22 +05:00
import {
StatusBar,
View,
SafeAreaView,
TouchableOpacity,
DeviceEventEmitter,
Platform,
2019-12-04 11:29:40 +05:00
Text,
2019-11-23 06:25:22 +05:00
} from 'react-native';
2019-12-04 11:29:40 +05:00
import {COLOR_SCHEME, SIZE, opacity, WEIGHT, pv, ph} from './src/common/common';
2019-11-17 17:48:56 +05:00
import Icon from 'react-native-vector-icons/Ionicons';
import ActionButton from 'react-native-action-button';
2019-11-28 21:40:37 +05:00
import Storage from 'notes-core/api/database';
2019-11-27 21:44:52 +05:00
import StorageInterface from './src/utils/storage';
2019-11-29 11:31:43 +05:00
import * as Animatable from 'react-native-animatable';
2019-12-04 11:29:40 +05:00
import {h} from './src/utils/utils';
import {Toast} from './src/components/Toast';
2019-12-04 11:40:59 +05:00
import {Menu} from './src/components/Menu';
2019-12-04 11:29:40 +05:00
2019-11-15 01:17:59 +05:00
const App = () => {
2019-11-17 17:48:56 +05:00
const [colors, setColors] = useState(COLOR_SCHEME);
2019-11-23 06:25:22 +05:00
const [fab, setFab] = useState(true);
2019-11-29 11:31:43 +05:00
const [sidebar, setSidebar] = useState('30%');
2019-11-23 06:25:22 +05:00
2019-11-17 16:02:19 +05:00
useEffect(() => {
2019-12-04 11:29:40 +05:00
if (Platform.OS === 'android') {
StatusBar.setBackgroundColor('transparent');
StatusBar.setTranslucent(true);
StatusBar.setBarStyle('dark-content');
}
}, []);
useEffect(() => {
2019-11-29 11:31:43 +05:00
DeviceEventEmitter.addListener('openSidebar', () => {
setSidebar('30%');
});
DeviceEventEmitter.addListener('closeSidebar', () => {
setSidebar('0%');
});
2019-11-23 06:25:22 +05:00
return () => {
2019-11-29 11:31:43 +05:00
DeviceEventEmitter.removeListener('openSidebar', () => {
setSidebar('30%');
});
DeviceEventEmitter.removeListener('closeSidebar', () => {
setSidebar('0%');
});
2019-11-23 06:25:22 +05:00
};
2019-11-29 11:31:43 +05:00
}, []);
2019-12-04 11:29:40 +05:00
useEffect(() => {
DeviceEventEmitter.addListener('hide', () => {
setFab(false);
});
DeviceEventEmitter.addListener('show', () => {
setFab(true);
});
return () => {
DeviceEventEmitter.removeListener('hide', () => {
setFab(false);
});
DeviceEventEmitter.removeListener('show', () => {
setFab(true);
});
};
}, []);
2019-11-17 16:02:19 +05:00
return (
2019-11-29 11:31:43 +05:00
<View
style={{
width: '100%',
height: '100%',
flexDirection: 'row',
}}>
2019-11-30 19:56:40 +05:00
{Platform.isPad ? (
<Animatable.View
transition="width"
duration={200}
style={{
width: sidebar,
}}>
2019-12-04 11:40:59 +05:00
<Menu
2019-11-30 19:56:40 +05:00
colors={colors}
close={() => {
setSidebar('0%');
}}
/>{' '}
: undefined
</Animatable.View>
) : (
2019-12-04 11:29:40 +05:00
undefined
)}
2019-11-30 19:56:40 +05:00
2019-11-17 17:48:56 +05:00
<AppContainer
2019-11-29 11:31:43 +05:00
style={{
2019-11-30 19:56:40 +05:00
width: Platform.isPad ? '70%' : '100%',
2019-11-29 11:31:43 +05:00
height: '100%',
}}
2019-11-17 17:48:56 +05:00
ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
/>
2019-12-04 11:29:40 +05:00
<Toast />
2019-11-23 06:25:22 +05:00
{fab ? (
<ActionButton elevation={5} buttonColor={colors.accent}>
<ActionButton.Item
buttonColor="#9b59b6"
textStyle={{
fontFamily: WEIGHT.regular,
2019-11-17 17:48:56 +05:00
color: 'white',
}}
2019-11-23 06:25:22 +05:00
title=""
hideShadow={true}
2019-11-29 11:31:43 +05:00
onPress={() => {
NavigationService.navigate('Editor');
}}>
2019-11-23 06:25:22 +05:00
<Icon
name="md-create"
style={{
fontSize: 20,
height: 22,
color: 'white',
}}
/>
</ActionButton.Item>
<ActionButton.Item
textStyle={{
fontFamily: WEIGHT.regular,
2019-11-17 17:48:56 +05:00
color: 'white',
}}
2019-11-23 06:25:22 +05:00
hideShadow={true}
buttonColor="#3498db"
title=""
onPress={() => {
NavigationService.navigate('ListsEditor');
}}>
<Icon
name="ios-list"
style={{
fontSize: 20,
height: 22,
color: 'white',
}}
/>
</ActionButton.Item>
</ActionButton>
) : (
2019-12-04 11:29:40 +05:00
undefined
)}
2019-11-29 11:31:43 +05:00
</View>
2019-11-15 01:17:59 +05:00
);
};
export default App;
2019-11-27 21:44:52 +05:00
export const storage = new Storage(StorageInterface);