From a450c865df0ff2f4a3ed0f87da7553927444132c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0ev=C4=8D=C3=ADk?= Date: Wed, 12 Dec 2018 14:29:10 +0100 Subject: [PATCH] Created App container with Navigator ref and proper Linking --- App.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ index.js | 4 ++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 App.js diff --git a/App.js b/App.js new file mode 100644 index 000000000..b94ef1bc0 --- /dev/null +++ b/App.js @@ -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 ( + { + this.navigator = nav; + }} + /> + ); + } +} diff --git a/index.js b/index.js index f37414a25..fbefbcb45 100644 --- a/index.js +++ b/index.js @@ -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 ? this.setIsMigratingData()} /> : ; + return this.state.isMigratingData ? this.setIsMigratingData()} /> : ; } }