fix for launch urls and notification target urls #73
2 changed files with 49 additions and 16 deletions
|
@ -27,7 +27,15 @@ import {
|
||||||
createNavigationReducer,
|
createNavigationReducer,
|
||||||
} from 'react-navigation-redux-helpers';
|
} from 'react-navigation-redux-helpers';
|
||||||
import { connect } from 'react-redux';
|
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 { selectDrawerStack } from 'redux/selectors/drawer';
|
||||||
import { SETTINGS, doDismissToast, doPopulateSharedUserState, doPreferenceGet, doToast, selectToast } from 'lbry-redux';
|
import { SETTINGS, doDismissToast, doPopulateSharedUserState, doPreferenceGet, doToast, selectToast } from 'lbry-redux';
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Lbry, doPreferenceGet } from 'lbry-redux';
|
import { Lbry, doPreferenceGet } from 'lbry-redux';
|
||||||
import { Lbryio } from 'lbryinc';
|
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 { NavigationActions, StackActions } from 'react-navigation';
|
||||||
import { decode as atob } from 'base-64';
|
import { decode as atob } from 'base-64';
|
||||||
import { navigateToUri, transformUrl } from 'utils/helper';
|
import { navigateToUri, transformUrl } from 'utils/helper';
|
||||||
|
@ -52,7 +52,10 @@ class SplashScreen extends React.PureComponent {
|
||||||
});
|
});
|
||||||
navigation.dispatch(resetAction);
|
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) {
|
||||||
if (launchUrl.startsWith('lbry://?verify=')) {
|
if (launchUrl.startsWith('lbry://?verify=')) {
|
||||||
let verification = {};
|
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 = () => {
|
finishSplashScreen = () => {
|
||||||
const {
|
const {
|
||||||
authenticate,
|
authenticate,
|
||||||
|
@ -250,27 +259,31 @@ class SplashScreen extends React.PureComponent {
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
DeviceEventEmitter.addListener('onNotificationTargetLaunch', this.onNotificationTargetLaunch);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
DeviceEventEmitter.removeListener('onNotificationTargetLaunch', this.onNotificationTargetLaunch);
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
NativeModules.Firebase.track('app_launch', null);
|
NativeModules.Firebase.track('app_launch', null);
|
||||||
NativeModules.Firebase.setCurrentScreen('Splash');
|
NativeModules.Firebase.setCurrentScreen('Splash');
|
||||||
|
|
||||||
this.props.fetchRewardedContent();
|
this.props.fetchRewardedContent();
|
||||||
Linking.getInitialURL().then(url => {
|
Linking.getInitialURL().then(url => {
|
||||||
|
console.log('checking initial url=' + url);
|
||||||
if (url) {
|
if (url) {
|
||||||
this.setState({ launchUrl: url });
|
this.setState({ launchUrl: url });
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// Start measuring the first launch time from the splash screen
|
NativeModules.UtilityModule.getNotificationLaunchTarget().then(target => {
|
||||||
// (time to first user interaction - after first run completed)
|
if (target) {
|
||||||
AsyncStorage.getItem('hasLaunched').then(value => {
|
this.setState({ launchUrl: target });
|
||||||
if (value !== 'true') {
|
|
||||||
AsyncStorage.setItem('hasLaunched', 'true');
|
|
||||||
// only set firstLaunchTime since we've determined that this is the first app launch ever
|
|
||||||
AsyncStorage.setItem('firstLaunchTime', String(moment().unix()));
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
// Only connect after checking initial launch url / notification launch target
|
||||||
Lbry.connect()
|
Lbry.connect()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.updateStatus();
|
this.updateStatus();
|
||||||
|
@ -283,6 +296,18 @@ class SplashScreen extends React.PureComponent {
|
||||||
'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.',
|
'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
|
||||||
|
// (time to first user interaction - after first run completed)
|
||||||
|
AsyncStorage.getItem('hasLaunched').then(value => {
|
||||||
|
if (value !== 'true') {
|
||||||
|
AsyncStorage.setItem('hasLaunched', 'true');
|
||||||
|
// only set firstLaunchTime since we've determined that this is the first app launch ever
|
||||||
|
AsyncStorage.setItem('firstLaunchTime', String(moment().unix()));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleContinueAnywayPressed = () => {
|
handleContinueAnywayPressed = () => {
|
||||||
|
|
Loading…
Reference in a new issue