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

179 lines
4.8 KiB
JavaScript
Raw Normal View History

2020-05-06 02:26:35 +05:00
import React, {createRef} from 'react';
import {Modal, TouchableOpacity, View, StatusBar} from 'react-native';
2020-03-14 13:38:00 +05:00
import * as Animatable from 'react-native-animatable';
2020-01-24 23:13:09 +05:00
import {ACTIONS} from '../../provider/actions';
2020-03-14 13:38:00 +05:00
import {eSendEvent} from '../../services/eventManager';
import {
eMoveNoteDialogNavigateBack,
eSetModalNavigator,
} from '../../services/events';
2020-03-14 13:54:16 +05:00
import {getElevation, DDS} from '../../utils/utils';
2020-01-18 18:13:34 +05:00
import Folders from '../../views/Folders';
import Notebook from '../../views/Notebook';
import Notes from '../../views/Notes';
2020-03-14 13:37:07 +05:00
import {updateEvent} from '../DialogManager/recievers';
2020-05-06 02:26:35 +05:00
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import Container from '../Container';
2020-01-18 18:13:34 +05:00
2020-05-06 02:26:35 +05:00
const Stack = createStackNavigator();
const modalNavigatorRef = createRef();
2020-05-06 02:47:26 +05:00
const ModalNavigator = ({onStateChange}) => {
2020-05-06 02:26:35 +05:00
return (
<NavigationContainer
onStateChange={onStateChange}
independent={true}
ref={modalNavigatorRef}>
2020-05-06 02:26:35 +05:00
<Stack.Navigator
initialRouteName="Folders"
screenOptions={{
headerShown: false,
animationEnabled: false,
gestureEnabled: false,
cardOverlayEnabled: false,
cardShadowEnabled: false,
}}>
<Stack.Screen
name="Folders"
component={Folders}
initialParams={{
title: 'Select a notebook',
2020-05-06 02:26:35 +05:00
isMove: true,
hideMore: true,
canGoBack: true,
root: false,
2020-05-06 02:26:35 +05:00
}}
/>
<Stack.Screen
initialParams={{
root: false,
}}
name="Notebook"
component={Notebook}
/>
<Stack.Screen
initialParams={{
root: false,
}}
name="Notes"
component={Notes}
/>
2020-05-06 02:26:35 +05:00
</Stack.Navigator>
</NavigationContainer>
);
2020-01-18 18:13:34 +05:00
};
class MoveNoteDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
2020-05-06 02:43:04 +05:00
visible: false,
2020-01-18 18:13:34 +05:00
animated: false,
};
2020-01-23 23:19:06 +05:00
this.routeIndex = 0;
2020-01-18 18:13:34 +05:00
this.count = 0;
}
open() {
this.setState({
visible: true,
});
}
close() {
updateEvent({type: ACTIONS.CLEAR_SELECTION});
updateEvent({type: ACTIONS.MODAL_NAVIGATOR, enabled: false});
this.setState({
visible: false,
animated: false,
});
}
render() {
const {visible, animated} = this.state;
2020-01-23 23:19:06 +05:00
const {colors} = this.props;
2020-01-18 18:13:34 +05:00
return (
<Modal
animated={true}
animationType="fade"
onShow={() => {
updateEvent({type: ACTIONS.MODAL_NAVIGATOR, enabled: true});
StatusBar.setBackgroundColor('white');
eSendEvent(eSetModalNavigator, true);
2020-01-18 18:13:34 +05:00
this.setState({
animated: true,
});
}}
onRequestClose={() => {
StatusBar.setBackgroundColor('transparent');
2020-01-23 23:19:06 +05:00
if (!this.routeIndex || this.routeIndex === 0) {
eSendEvent(eSetModalNavigator, false);
2020-01-18 18:13:34 +05:00
this.close();
} else {
2020-01-25 23:24:01 +05:00
eSendEvent(eMoveNoteDialogNavigateBack);
2020-01-18 18:13:34 +05:00
}
}}
visible={visible}
transparent={true}>
<Animatable.View
transition={['opacity', 'scaleX', 'scaleY']}
useNativeDriver={true}
duration={300}
iterationCount={1}
style={{
opacity: animated ? 1 : 0,
flex: 1,
2020-01-23 23:19:06 +05:00
backgroundColor: DDS.isTab ? 'rgba(0,0,0,0.3)' : colors.bg,
width: '100%',
height: '100%',
alignSelf: 'center',
justifyContent: 'center',
alignItems: 'center',
2020-01-18 18:13:34 +05:00
transform: [
{
scaleX: animated ? 1 : 0.95,
},
{
scaleY: animated ? 1 : 0.95,
},
],
}}>
2020-01-23 23:19:06 +05:00
<TouchableOpacity
onPress={() => this.close()}
style={{
width: '100%',
height: '100%',
position: 'absolute',
zIndex: 1,
2020-01-18 18:13:34 +05:00
}}
/>
2020-01-23 23:19:06 +05:00
<View
style={{
...getElevation(DDS.isTab ? 10 : 0),
width: DDS.isTab ? '65%' : '100%',
height: DDS.isTab ? '90%' : '100%',
2020-02-22 20:00:57 +05:00
flex: 1,
2020-01-23 23:19:06 +05:00
borderRadius: DDS.isTab ? 5 : 0,
backgroundColor: colors.bg,
2020-02-02 16:18:52 +05:00
padding: DDS.isTab ? 8 : 0,
2020-01-23 23:19:06 +05:00
zIndex: 10,
}}>
<Container
root={false}
>
<ModalNavigator
2020-05-06 02:47:26 +05:00
onStateChange={event => {
this.routeIndex = event.index;
}}
/>
</Container>
2020-01-23 23:19:06 +05:00
</View>
2020-01-18 18:13:34 +05:00
</Animatable.View>
</Modal>
);
}
}
export default MoveNoteDialog;