From 072ad25146ed840084562d3ef12a06b3fa926128 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 31 Oct 2019 07:52:57 +0100 Subject: [PATCH] fix for launch urls and notification target urls --- src/component/AppNavigator.js | 10 ++++++- src/page/splash/view.js | 55 +++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/component/AppNavigator.js b/src/component/AppNavigator.js index 812f89b..e335cba 100644 --- a/src/component/AppNavigator.js +++ b/src/component/AppNavigator.js @@ -27,7 +27,15 @@ import { createNavigationReducer, } from 'react-navigation-redux-helpers'; import { connect } from 'react-redux'; -import { AppState, BackHandler, Linking, NativeModules, TextInput, ToastAndroid } from 'react-native'; +import { + AppState, + BackHandler, + DeviceEventEmitter, + Linking, + NativeModules, + TextInput, + ToastAndroid, +} from 'react-native'; import { selectDrawerStack } from 'redux/selectors/drawer'; import { SETTINGS, doDismissToast, doPopulateSharedUserState, doPreferenceGet, doToast, selectToast } from 'lbry-redux'; import { diff --git a/src/page/splash/view.js b/src/page/splash/view.js index 4e1eddb..cc5a1fb 100644 --- a/src/page/splash/view.js +++ b/src/page/splash/view.js @@ -1,7 +1,7 @@ import React from 'react'; import { Lbry, doPreferenceGet } from 'lbry-redux'; import { Lbryio } from 'lbryinc'; -import { ActivityIndicator, Linking, NativeModules, Platform, Text, View } from 'react-native'; +import { ActivityIndicator, DeviceEventEmitter, Linking, NativeModules, Platform, Text, View } from 'react-native'; import { NavigationActions, StackActions } from 'react-navigation'; import { decode as atob } from 'base-64'; import { navigateToUri, transformUrl } from 'utils/helper'; @@ -52,7 +52,10 @@ class SplashScreen extends React.PureComponent { }); navigation.dispatch(resetAction); - const launchUrl = navigation.state.params ? navigation.state.params.launchUrl : this.state.launchUrl; + const launchUrl = + navigation.state.params && navigation.state.params.launchUrl + ? navigation.state.params.launchUrl + : this.state.launchUrl; if (launchUrl) { if (launchUrl.startsWith('lbry://?verify=')) { let verification = {}; @@ -118,6 +121,12 @@ class SplashScreen extends React.PureComponent { ); }; + onNotificationTargetLaunch = evt => { + if (evt.url && evt.url.startsWith('lbry://')) { + this.setState({ launchUrl: evt.url }); + } + }; + finishSplashScreen = () => { const { authenticate, @@ -250,15 +259,44 @@ class SplashScreen extends React.PureComponent { }, 1000); } + componentWillMount() { + DeviceEventEmitter.addListener('onNotificationTargetLaunch', this.onNotificationTargetLaunch); + } + + componentWillUnmount() { + DeviceEventEmitter.removeListener('onNotificationTargetLaunch', this.onNotificationTargetLaunch); + } + componentDidMount() { NativeModules.Firebase.track('app_launch', null); NativeModules.Firebase.setCurrentScreen('Splash'); this.props.fetchRewardedContent(); Linking.getInitialURL().then(url => { + console.log('checking initial url=' + url); if (url) { this.setState({ launchUrl: url }); } + + NativeModules.UtilityModule.getNotificationLaunchTarget().then(target => { + if (target) { + this.setState({ launchUrl: target }); + } + + // Only connect after checking initial launch url / notification launch target + Lbry.connect() + .then(() => { + this.updateStatus(); + }) + .catch(e => { + this.setState({ + isLagging: true, + message: 'Connection Failure', + details: + 'We could not establish a connection to the daemon. Your data connection may be preventing LBRY from connecting. Contact hello@lbry.com if you think this is a software bug.', + }); + }); + }); }); // Start measuring the first launch time from the splash screen @@ -270,19 +308,6 @@ class SplashScreen extends React.PureComponent { AsyncStorage.setItem('firstLaunchTime', String(moment().unix())); } }); - - Lbry.connect() - .then(() => { - this.updateStatus(); - }) - .catch(e => { - this.setState({ - isLagging: true, - message: 'Connection Failure', - details: - 'We could not establish a connection to the daemon. Your data connection may be preventing LBRY from connecting. Contact hello@lbry.com if you think this is a software bug.', - }); - }); } handleContinueAnywayPressed = () => { -- 2.45.2