From 036c4d269871775d79fac141da00d1f3820ae2e6 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Fri, 15 Feb 2019 14:30:36 +0300 Subject: [PATCH] Fixed deeplink issue --- .../upvote/container/upvoteContainer.js | 1 - src/screens/root/container/rootContainer.js | 44 +++++++------------ 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/components/upvote/container/upvoteContainer.js b/src/components/upvote/container/upvoteContainer.js index ad4f29b2c..f2ff5e613 100644 --- a/src/components/upvote/container/upvoteContainer.js +++ b/src/components/upvote/container/upvoteContainer.js @@ -10,7 +10,6 @@ import { setUpvotePercent as upvoteAction } from '../../../redux/actions/applica // Utils import parseToken from '../../../utils/parseToken'; import { isEmptyContentDate, getTimeFromNow } from '../../../utils/time'; -import parseDate from '../../../utils/parseDate'; // Component import UpvoteView from '../view/upvoteView'; diff --git a/src/screens/root/container/rootContainer.js b/src/screens/root/container/rootContainer.js index 046e10c88..62fce3991 100644 --- a/src/screens/root/container/rootContainer.js +++ b/src/screens/root/container/rootContainer.js @@ -15,7 +15,6 @@ import { getPost, getUser } from '../../../providers/steem/dsteem'; import { Modal } from '../../../components'; import { PinCode } from '../../pinCode'; import PostButtonForAndroid from '../../../components/postButton/view/postButtonsForAndroid'; -import { ToastNotificaiton } from '../../../components/toastNotification'; // Constants import ROUTES from '../../../constants/routeNames'; @@ -34,7 +33,6 @@ const RootContainer = () => (WrappedComponent) => { componentDidMount() { AppState.addEventListener('change', this._handleAppStateChange); this._createPushListener(); - console.log('test ===11222211==== :'); if (Platform.OS === 'android') { Linking.getInitialURL().then((url) => { @@ -51,12 +49,10 @@ const RootContainer = () => (WrappedComponent) => { } _handleOpenURL = (event) => { - console.log('event :', event); this._handleDeepLink(event.url); } _handleDeepLink = async (url) => { - console.log('url :', url); if (!url) return; let author; @@ -65,28 +61,20 @@ const RootContainer = () => (WrappedComponent) => { let params; let content; let profile; - const postRegex = /^https?:\/\/(.*)\/(.*)\/(@[\w.\d-]+)\/(.*)/i; const { navigation, currentAccountUsername, intl } = this.props; - console.log('url.indexOf() :', url.indexOf('steemit')); - if (url.indexOf('esteem') > -1) { - console.log('test ===3 === :'); - const route = url.replace(/.*?:\/\//g, ''); - const routeParams = route.indexOf('/') > -1 ? route.split('/') : [route]; + if ( + url.indexOf('esteem') > -1 + || url.indexOf('steemit') > -1 + || url.indexOf('busy') > -1 + || url.indexOf('steempeak') > -1 + ) { + url = url.substring(url.indexOf('@'), url.length); + const routeParams = url.indexOf('/') > -1 ? url.split('/') : [url]; - if (routeParams && routeParams.length > 1) { - permlink = routeParams[2]; - author = routeParams[1].indexOf('@') > -1 ? routeParams[1].replace('@', '') : routeParams[1]; - } else if ((routeParams && routeParams.length === 1) || route.indexOf('@') > -1) { - author = route.length >= 3 && route; - } - } else if (url.indexOf('steemit') > -1) { - console.log('test ===2 === :'); - const urlMatch = url.match(postRegex); - const sss = urlMatch; + [, permlink] = routeParams; + author = routeParams[0].indexOf('@') > -1 ? routeParams[0].replace('@', '') : routeParams[0]; } - console.log('author :', author); - console.log('permlink :', permlink); if (author && permlink) { await getPost(author, permlink, currentAccountUsername) @@ -128,11 +116,13 @@ const RootContainer = () => (WrappedComponent) => { } if (profile || content) { - navigation.navigate({ - routeName, - params, - key: permlink || author, - }); + setTimeout(() => { + navigation.navigate({ + routeName, + params, + key: permlink || author, + }); + }, 2000); } };