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

149 lines
4.1 KiB
JavaScript
Raw Normal View History

2020-05-10 22:21:31 +05:00
import React, {createRef} from 'react';
2020-03-14 13:38:00 +05:00
import {Modal, TouchableOpacity, View} from 'react-native';
import * as Animatable from 'react-native-animatable';
import {normalize} from '../../common/common';
import {ACTIONS} from '../../provider/actions';
2020-01-25 20:12:47 +05:00
import {eSendEvent} from '../../services/eventManager';
import {eLoginDialogNavigateBack} from '../../services/events';
2020-03-14 13:54:16 +05:00
import {getElevation, DDS} from '../../utils/utils';
2020-03-14 13:38:00 +05:00
import ForgotPassword from '../../views/ForgotPassword';
import Login from '../../views/Login';
import Signup from '../../views/Signup';
2020-03-14 13:37:07 +05:00
import {updateEvent} from '../DialogManager/recievers';
2020-05-06 02:43:04 +05:00
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
2020-05-10 22:21:31 +05:00
import Container from '../Container';
2020-01-23 23:18:15 +05:00
2020-05-06 02:43:04 +05:00
const Stack = createStackNavigator();
const modalNavigatorRef2 = createRef();
2020-05-10 22:21:31 +05:00
2020-05-06 02:47:26 +05:00
const ModalNavigator = ({onStateChange}) => {
2020-05-06 02:43:04 +05:00
return (
2020-05-10 22:21:31 +05:00
<NavigationContainer
onStateChange={onStateChange}
independent={true}
ref={modalNavigatorRef2}>
2020-05-06 02:43:04 +05:00
<Stack.Navigator
initialRouteName="Login"
screenOptions={{
headerShown: false,
animationEnabled: false,
gestureEnabled: false,
cardOverlayEnabled: false,
cardShadowEnabled: false,
}}>
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="Signup" component={Signup} />
<Stack.Screen name="ForgotPassword" component={ForgotPassword} />
</Stack.Navigator>
</NavigationContainer>
);
2020-01-23 23:18:15 +05:00
};
class LoginDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
visible: false,
animated: false,
};
this.routeIndex = 0;
this.count = 0;
}
open() {
2020-01-25 19:41:56 +05:00
updateEvent({type: ACTIONS.LOGIN_NAVIGATOR, enabled: true});
2020-01-23 23:18:15 +05:00
this.setState({
visible: true,
});
}
close() {
this.setState({
visible: false,
animated: false,
});
}
render() {
const {visible, animated} = this.state;
const {colors} = this.props;
return (
<Modal
animated={true}
animationType="fade"
onShow={() => {
this.setState({
animated: true,
});
}}
onRequestClose={() => {
if (!this.routeIndex || this.routeIndex === 0) {
2020-01-25 19:41:56 +05:00
updateEvent({type: ACTIONS.LOGIN_NAVIGATOR, enabled: false});
2020-01-23 23:18:15 +05:00
this.close();
} else {
2020-01-25 20:12:47 +05:00
eSendEvent(eLoginDialogNavigateBack);
2020-01-23 23:18:15 +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,
backgroundColor: DDS.isTab ? 'rgba(0,0,0,0.3)' : colors.bg,
width: '100%',
height: '100%',
alignSelf: 'center',
justifyContent: 'center',
alignItems: 'center',
transform: [
{
scaleX: animated ? 1 : 0.95,
},
{
scaleY: animated ? 1 : 0.95,
},
],
}}>
<TouchableOpacity
onPress={() => this.close()}
style={{
width: '100%',
height: '100%',
position: 'absolute',
zIndex: 1,
}}
/>
<View
style={{
...getElevation(DDS.isTab ? 10 : 0),
2020-01-27 18:50:17 +05:00
width: DDS.isTab ? normalize(600) : '100%',
height: DDS.isTab ? normalize(500) : '100%',
2020-01-23 23:18:15 +05:00
borderRadius: DDS.isTab ? 5 : 0,
backgroundColor: colors.bg,
padding: 8,
paddingVertical: 16,
zIndex: 10,
}}>
2020-05-10 22:21:31 +05:00
<Container>
<ModalNavigator
onStateChange={event => {
2020-05-06 02:47:26 +05:00
this.routeIndex = event.index;
2020-05-10 22:21:31 +05:00
}}
/>
</Container>
2020-01-23 23:18:15 +05:00
</View>
</Animatable.View>
</Modal>
);
}
}
export default LoginDialog;