2019-07-18 17:44:02 +00:00
|
|
|
import React from 'react';
|
2019-10-02 12:18:08 +00:00
|
|
|
import { View } from 'react-native';
|
2019-09-17 19:24:47 +00:00
|
|
|
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
|
|
|
|
import { createStackNavigator } from 'react-navigation-stack';
|
2019-07-18 17:44:02 +00:00
|
|
|
import { Provider } from 'react-redux';
|
2019-07-29 16:33:28 +00:00
|
|
|
import RNUserDefaults from 'rn-user-defaults';
|
2019-07-18 17:44:02 +00:00
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
import Navigation from './lib/ShareNavigation';
|
2019-07-18 17:44:02 +00:00
|
|
|
import store from './lib/createStore';
|
2019-10-02 12:18:08 +00:00
|
|
|
import sharedStyles from './views/Styles';
|
|
|
|
import { isNotch, isIOS } from './utils/deviceInfo';
|
2019-07-18 17:44:02 +00:00
|
|
|
import { defaultHeader, onNavigationStateChange } from './utils/navigation';
|
2019-07-29 16:33:28 +00:00
|
|
|
import RocketChat from './lib/rocketchat';
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
const InsideNavigator = createStackNavigator({
|
2019-07-29 16:33:28 +00:00
|
|
|
ShareListView: {
|
|
|
|
getScreen: () => require('./views/ShareListView').default
|
|
|
|
},
|
|
|
|
ShareView: {
|
|
|
|
getScreen: () => require('./views/ShareView').default
|
|
|
|
},
|
|
|
|
SelectServerView: {
|
|
|
|
getScreen: () => require('./views/SelectServerView').default
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
}, {
|
|
|
|
initialRouteName: 'ShareListView',
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
|
|
|
const OutsideNavigator = createStackNavigator({
|
2019-07-29 16:33:28 +00:00
|
|
|
WithoutServersView: {
|
|
|
|
getScreen: () => require('./views/WithoutServersView').default
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
}, {
|
|
|
|
initialRouteName: 'WithoutServersView',
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
|
|
|
const AppContainer = createAppContainer(createSwitchNavigator({
|
|
|
|
OutsideStack: OutsideNavigator,
|
|
|
|
InsideStack: InsideNavigator,
|
2019-07-29 16:33:28 +00:00
|
|
|
AuthLoading: {
|
|
|
|
getScreen: () => require('./views/AuthLoadingView').default
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
initialRouteName: 'AuthLoading'
|
|
|
|
}));
|
|
|
|
|
|
|
|
class Root extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2019-10-02 12:18:08 +00:00
|
|
|
this.state = {
|
|
|
|
isLandscape: false
|
|
|
|
};
|
2019-07-29 16:33:28 +00:00
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
init = async() => {
|
|
|
|
if (isIOS) {
|
|
|
|
await RNUserDefaults.setName('group.ios.chat.rocket');
|
|
|
|
}
|
|
|
|
const currentServer = await RNUserDefaults.get('currentServer');
|
|
|
|
const token = await RNUserDefaults.get(RocketChat.TOKEN_KEY);
|
|
|
|
|
|
|
|
if (currentServer && token) {
|
|
|
|
await Navigation.navigate('InsideStack');
|
|
|
|
await RocketChat.shareExtensionInit(currentServer);
|
|
|
|
} else {
|
|
|
|
await Navigation.navigate('OutsideStack');
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2019-10-02 12:18:08 +00:00
|
|
|
handleLayout = (event) => {
|
|
|
|
const { width, height } = event.nativeEvent.layout;
|
|
|
|
this.setState({ isLandscape: width > height });
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:44:02 +00:00
|
|
|
render() {
|
2019-10-02 12:18:08 +00:00
|
|
|
const { isLandscape } = this.state;
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
2019-10-02 12:18:08 +00:00
|
|
|
<View
|
|
|
|
style={[sharedStyles.container, isLandscape && isNotch ? sharedStyles.notchLandscapeContainer : {}]}
|
|
|
|
onLayout={this.handleLayout}
|
|
|
|
>
|
2019-07-18 17:44:02 +00:00
|
|
|
<Provider store={store}>
|
2019-10-30 15:43:57 +00:00
|
|
|
<AppContainer
|
|
|
|
ref={(navigatorRef) => {
|
|
|
|
Navigation.setTopLevelNavigator(navigatorRef);
|
|
|
|
}}
|
|
|
|
onNavigationStateChange={onNavigationStateChange}
|
|
|
|
/>
|
2019-07-18 17:44:02 +00:00
|
|
|
</Provider>
|
2019-10-02 12:18:08 +00:00
|
|
|
</View>
|
2019-07-18 17:44:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Root;
|