forked from g0v/react-native-scanbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.shared.js
104 lines (86 loc) · 2.68 KB
/
index.shared.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Scanbot Example
* @flow
*/
import React, { Component } from 'react';
import { connect, Provider } from 'react-redux';
import { persistStore } from 'redux-persist';
import { AsyncStorage, View, StatusBar } from 'react-native'
import { StackNavigator } from 'react-navigation';
import { addNavigationHelpers } from 'react-navigation';
import Scanbot from './src/Scanbot/Scanbot';
import DocumentReviewList from './src/components/DocumentReviewList';
import LoginScreen from './src/components/login/LoginScreen';
import Home from './src/components//Home/Home';
import configureStore from './src/store/configureStore';
import { createRootNavigator } from "./src/components/router";
import { isSignedIn } from "./src/components/auth";
import config from './src/config';
// Set valid license and translations here
Scanbot.setLicense(config.scanbotLicense);
Scanbot.setTranslations(config.labelTranslations);
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
signedIn: false,
checkedSignIn: false
};
}
componentWillMount() {
StatusBar.setBarStyle('light-content');
isSignedIn()
.then(res => this.setState({ signedIn: res, checkedSignIn: true }))
.catch(err => alert(err.message));
}
render() {
const { checkedSignIn, signedIn } = this.state;
// If we haven't checked AsyncStorage yet, don't render anything (better ways to do this)
if (!checkedSignIn) {
return null;
}
const Layout = createRootNavigator(signedIn);
return <Layout />;
}
}
// const AppNavigator = StackNavigator({
// // @Hsin you can add more app screens here if you need
// LoginScreen: { screen: Home },
// Home: { screen: LoginScreen },
// DocumentReviewList: { screen: DocumentReviewList },
// });
//
// const App = ({ nav, dispatch }) =>
// <AppNavigator
// navigation={addNavigationHelpers({
// dispatch: dispatch,
// state: nav
// })}
// />;
const mapStateToProps = (state, props) => ({ });
// const mapDispatchToProps = dispatch => ({ dispatch: dispatch });
const AppWithNavigationState = connect(mapStateToProps)(App);
class Root extends Component {
state = {
rehydrated: false,
store: configureStore(App)
};
componentDidMount() {
persistStore(this.state.store, { storage: AsyncStorage }, () => {
this.setState({ rehydrated: true })
});
}
render() {
// Show the logo while we wait to get the saved state from disk
// if(!this.state.rehydrated){
// // TODO show logo here
// return <View />;
// }
return (
<Provider store={this.state.store}>
<AppWithNavigationState />
</Provider>
);
}
}
export default Root;