Created App container with Navigator ref and proper Linking

This commit is contained in:
Pavel Ševčík 2018-12-12 14:29:10 +01:00
parent 811ea39bf7
commit a450c865df
2 changed files with 47 additions and 2 deletions

45
App.js Normal file
View file

@ -0,0 +1,45 @@
import React from 'react';
import { Linking } from 'react-native';
import { NavigationActions } from 'react-navigation';
import MainBottomTabs from './MainBottomTabs';
export default class App extends React.Component {
navigator = null;
componentDidMount() {
Linking.getInitialURL()
.then(url => this.handleOpenURL({ url }))
.catch(console.error);
Linking.addEventListener('url', this.handleOpenURL);
}
componentWillUnmount() {
Linking.removeEventListener('url', this.handleOpenURL);
}
handleOpenURL = event => {
if (event.url && event.url.indexOf('bitcoin:') === 0) {
this.navigator &&
this.navigator.dispatch(
NavigationActions.navigate({
routeName: 'SendDetails',
params: {
uri: event.url,
},
}),
);
}
};
render() {
return (
<MainBottomTabs
ref={nav => {
this.navigator = nav;
}}
/>
);
}
}

View file

@ -1,6 +1,6 @@
import React from 'react';
import './shim.js';
import MainBottomTabs from './MainBottomTabs';
import App from './App';
import { Sentry } from 'react-native-sentry';
import { AppRegistry } from 'react-native';
import WalletMigrate from './screen/wallets/walletMigrate';
@ -28,7 +28,7 @@ class BlueAppComponent extends React.Component {
}
render() {
return this.state.isMigratingData ? <WalletMigrate onComplete={() => this.setIsMigratingData()} /> : <MainBottomTabs />;
return this.state.isMigratingData ? <WalletMigrate onComplete={() => this.setIsMigratingData()} /> : <App />;
}
}