Skip to content

Commit

Permalink
Use expo's AppLoader component instead of PersistGate
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-username committed Mar 26, 2018
1 parent ba228ca commit dcf5f2c
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
import React from 'react';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import { PersistGate } from 'redux-persist/integration/react';
import { AppLoading } from 'expo';

import RootStack from './config/router';
import configureStore from './redux/configureStore';

const { persistor, store } = configureStore();

class Loader extends React.Component {
constructor(props) {
super(props);
this.state = {
bootstrapped: false,
};

this._loadUserData = this._loadUserData.bind(this);
this._unsubscribe = null;
}

componentDidMount() {
this._unsubscribe = this.props.persistor.subscribe(this._loadUserData);
}

_loadUserData() {
const { persistor } = this.props;
let { bootstrapped } = persistor.getState();
if (bootstrapped) {
this._unsubscribe && this._unsubscribe();
return Promise.resolve();
}
}

render() {
if (!this.state.bootstrapped) {
return (
<AppLoading
startAsync={this._loadUserData}
onFinish={() => this.setState({ bootstrapped: true })}
onError={console.warn}
/>
);
}

return this.props.children;
}
}

export default (RootApp = () => (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Loader persistor={persistor}>
<RootStack />
</PersistGate>
</Loader>
</Provider>
));

0 comments on commit dcf5f2c

Please sign in to comment.