mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-01 17:56:48 +03:00
Fixed push navigation issue
This commit is contained in:
parent
e79d275f2c
commit
3a5130cba8
@ -157,7 +157,6 @@ dependencies {
|
||||
compile project(':appcenter-push')
|
||||
compile project(':react-native-view-overflow')
|
||||
compile project(':react-native-vector-icons')
|
||||
compile project(':react-native-restart')
|
||||
compile project(':react-native-linear-gradient')
|
||||
compile project(':react-native-config')
|
||||
compile project(':appcenter-crashes')
|
||||
|
@ -12,7 +12,6 @@ import com.reactnative.ivpusic.imagepicker.PickerPackage;
|
||||
import com.microsoft.appcenter.reactnative.push.AppCenterReactNativePushPackage;
|
||||
import com.entria.views.RNViewOverflowPackage;
|
||||
import com.oblador.vectoricons.VectorIconsPackage;
|
||||
import com.avishayil.rnrestart.ReactNativeRestartPackage;
|
||||
import com.BV.LinearGradient.LinearGradientPackage;
|
||||
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
|
||||
import com.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesPackage;
|
||||
@ -22,7 +21,6 @@ import com.facebook.react.ReactNativeHost;
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.shell.MainReactPackage;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import com.facebook.react.BuildConfig;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -54,7 +52,6 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
new AppCenterReactNativePushPackage(MainApplication.this),
|
||||
new RNViewOverflowPackage(),
|
||||
new VectorIconsPackage(),
|
||||
new ReactNativeRestartPackage(),
|
||||
new LinearGradientPackage(),
|
||||
new ReactNativeConfigPackage(),
|
||||
new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)),
|
||||
|
@ -17,8 +17,6 @@ include ':react-native-view-overflow'
|
||||
project(':react-native-view-overflow').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-view-overflow/android')
|
||||
include ':react-native-vector-icons'
|
||||
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
|
||||
include ':react-native-restart'
|
||||
project(':react-native-restart').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-restart/android')
|
||||
include ':react-native-linear-gradient'
|
||||
project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')
|
||||
include ':react-native-config'
|
||||
|
@ -8,6 +8,7 @@ import Config from 'react-native-config';
|
||||
import { NavigationActions } from 'react-navigation';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import Push from 'appcenter-push';
|
||||
import get from 'lodash/get';
|
||||
|
||||
// Languages
|
||||
import en from 'react-intl/locale-data/en';
|
||||
@ -21,10 +22,10 @@ import ko from 'react-intl/locale-data/ko';
|
||||
import lt from 'react-intl/locale-data/lt';
|
||||
import pt from 'react-intl/locale-data/pt';
|
||||
import fa from 'react-intl/locale-data/fa';
|
||||
import he from 'react-intl/locale-data/he';
|
||||
|
||||
// Constants
|
||||
import AUTH_TYPE from '../../../constants/authType';
|
||||
import ROUTES from '../../../constants/routeNames';
|
||||
|
||||
// Services
|
||||
import {
|
||||
@ -103,6 +104,7 @@ class ApplicationContainer extends Component {
|
||||
}
|
||||
|
||||
this.globalInterval = setInterval(this._refreshGlobalProps, 180000);
|
||||
this._createPushListener();
|
||||
};
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
@ -139,6 +141,58 @@ class ApplicationContainer extends Component {
|
||||
this.setState({ isReady: true });
|
||||
};
|
||||
|
||||
_createPushListener = () => {
|
||||
const { dispatch } = this.props;
|
||||
let params = null;
|
||||
let key = null;
|
||||
let routeName = null;
|
||||
|
||||
Push.setListener({
|
||||
onPushNotificationReceived(pushNotification) {
|
||||
const push = get(pushNotification, 'customProperties');
|
||||
const permlink1 = get(push, 'permlink1');
|
||||
const permlink2 = get(push, 'permlink2');
|
||||
const permlink3 = get(push, 'permlink3');
|
||||
const parentPermlink1 = get(push, 'parent_permlink1');
|
||||
const parentPermlink2 = get(push, 'parent_permlink2');
|
||||
const parentPermlink3 = get(push, 'parent_permlink3');
|
||||
|
||||
if (parentPermlink1 || permlink1) {
|
||||
const fullParentPermlink = `${parentPermlink1}${parentPermlink2}${parentPermlink3}`;
|
||||
const fullPermlink = `${permlink1}${permlink2}${permlink3}`;
|
||||
|
||||
params = {
|
||||
author: parentPermlink1 ? get(push, 'parent_author') : get(push, 'target'),
|
||||
permlink: parentPermlink1
|
||||
? fullParentPermlink
|
||||
: fullPermlink,
|
||||
};
|
||||
key = parentPermlink1
|
||||
? fullParentPermlink
|
||||
: fullPermlink;
|
||||
routeName = ROUTES.SCREENS.POST;
|
||||
} else {
|
||||
params = {
|
||||
username: push.source,
|
||||
};
|
||||
key = push.source;
|
||||
routeName = ROUTES.SCREENS.PROFILE;
|
||||
}
|
||||
|
||||
this.pushNavigationTimeout = setTimeout(() => {
|
||||
clearTimeout(this.pushNavigationTimeout);
|
||||
const navigateAction = NavigationActions.navigate({
|
||||
routeName,
|
||||
params,
|
||||
key,
|
||||
action: NavigationActions.navigate({ routeName }),
|
||||
});
|
||||
dispatch(navigateAction);
|
||||
}, 4000);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
_handleConntectionChange = (status) => {
|
||||
const { dispatch, isConnected } = this.props;
|
||||
|
||||
|
@ -27,13 +27,11 @@ const RootContainer = () => (WrappedComponent) => {
|
||||
this.state = {
|
||||
wrappedComponentStates: null,
|
||||
appState: AppState.currentState,
|
||||
isNotificationRouted: false,
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
AppState.addEventListener('change', this._handleAppStateChange);
|
||||
this._createPushListener();
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
Linking.getInitialURL().then((url) => {
|
||||
@ -164,55 +162,6 @@ const RootContainer = () => (WrappedComponent) => {
|
||||
this.setState({ wrappedComponentStates: { ...data } });
|
||||
};
|
||||
|
||||
_createPushListener = () => {
|
||||
const { navigation } = this.props;
|
||||
let params = null;
|
||||
let key = null;
|
||||
let routeName = null;
|
||||
|
||||
Push.setListener({
|
||||
onPushNotificationReceived(pushNotification) {
|
||||
const push = get(pushNotification, 'customProperties');
|
||||
const permlink1 = get(push, 'permlink1');
|
||||
const permlink2 = get(push, 'permlink2');
|
||||
const permlink3 = get(push, 'permlink3');
|
||||
const parentPermlink1 = get(push, 'parent_permlink1');
|
||||
const parentPermlink2 = get(push, 'parent_permlink2');
|
||||
const parentPermlink3 = get(push, 'parent_permlink3');
|
||||
|
||||
if (parentPermlink1 || permlink1) {
|
||||
const fullParentPermlink = `${parentPermlink1}${parentPermlink2}${parentPermlink3}`;
|
||||
const fullPermlink = `${permlink1}${permlink2}${permlink3}`;
|
||||
|
||||
params = {
|
||||
author: parentPermlink1 ? get(push, 'parent_author') : get(push, 'target'),
|
||||
permlink: parentPermlink1
|
||||
? fullParentPermlink
|
||||
: fullPermlink,
|
||||
};
|
||||
key = parentPermlink1
|
||||
? fullParentPermlink
|
||||
: fullPermlink;
|
||||
routeName = ROUTES.SCREENS.POST;
|
||||
} else {
|
||||
params = {
|
||||
username: push.source,
|
||||
};
|
||||
key = push.source;
|
||||
routeName = ROUTES.SCREENS.PROFILE;
|
||||
}
|
||||
|
||||
this.pushNavigationTimeout = setTimeout(() => {
|
||||
const { isNotificationRouted } = this.state;
|
||||
|
||||
clearTimeout(this.pushNavigationTimeout);
|
||||
if (isNotificationRouted) navigation.navigate({ routeName, params, key });
|
||||
this.setState({ isNotificationRouted: true });
|
||||
}, 4000);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const { isPinCodeReqiure, navigation } = this.props;
|
||||
const { wrappedComponentStates } = this.state;
|
||||
|
Loading…
Reference in New Issue
Block a user