Regression: Deep linking stopped working after react-native-navigation update (#549)

This commit is contained in:
Diego Mello 2018-11-22 16:54:38 -02:00 committed by GitHub
parent b0420a4421
commit 35fac39594
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 26 deletions

View File

@ -47,7 +47,7 @@ export const ROOM = createRequestTypes('ROOM', [
'MESSAGE_RECEIVED', 'MESSAGE_RECEIVED',
'SET_LAST_OPEN' 'SET_LAST_OPEN'
]); ]);
export const APP = createRequestTypes('APP', ['START', 'READY', 'INIT']); export const APP = createRequestTypes('APP', ['START', 'READY', 'INIT', 'SET_STACK_ROOT']);
export const MESSAGES = createRequestTypes('MESSAGES', [ export const MESSAGES = createRequestTypes('MESSAGES', [
...defaultTypes, ...defaultTypes,
'ACTIONS_SHOW', 'ACTIONS_SHOW',

View File

@ -20,6 +20,13 @@ export function appInit() {
}; };
} }
export function setStackRoot(stackRoot) {
return {
type: APP.SET_STACK_ROOT,
stackRoot
};
}
export function setCurrentServer(server) { export function setCurrentServer(server) {
return { return {
type: types.SET_CURRENT_SERVER, type: types.SET_CURRENT_SERVER,

View File

@ -7,7 +7,7 @@ import { connect } from 'react-redux';
import Icon from 'react-native-vector-icons/MaterialIcons'; import Icon from 'react-native-vector-icons/MaterialIcons';
import { Navigation } from 'react-native-navigation'; import { Navigation } from 'react-native-navigation';
import { appStart as appStartAction } from '../actions'; import { appStart as appStartAction, setStackRoot as setStackRootAction } from '../actions';
import { logout as logoutAction } from '../actions/login'; import { logout as logoutAction } from '../actions/login';
import Avatar from './Avatar'; import Avatar from './Avatar';
import Status from './status'; import Status from './status';
@ -19,7 +19,6 @@ import I18n from '../i18n';
import scrollPersistTaps from '../utils/scrollPersistTaps'; import scrollPersistTaps from '../utils/scrollPersistTaps';
import DeviceInfo from '../utils/deviceInfo'; import DeviceInfo from '../utils/deviceInfo';
import Drawer from '../Drawer'; import Drawer from '../Drawer';
import EventEmitter from '../utils/events';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
@ -86,6 +85,7 @@ const keyExtractor = item => item.id;
@connect(state => ({ @connect(state => ({
Site_Name: state.settings.Site_Name, Site_Name: state.settings.Site_Name,
stackRoot: state.app.stackRoot,
user: { user: {
id: state.login.user && state.login.user.id, id: state.login.user && state.login.user.id,
language: state.login.user && state.login.user.language, language: state.login.user && state.login.user.language,
@ -95,30 +95,31 @@ const keyExtractor = item => item.id;
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
}), dispatch => ({ }), dispatch => ({
logout: () => dispatch(logoutAction()), logout: () => dispatch(logoutAction()),
appStart: () => dispatch(appStartAction('outside')) appStart: () => dispatch(appStartAction('outside')),
setStackRoot: stackRoot => dispatch(setStackRootAction(stackRoot))
})) }))
export default class Sidebar extends Component { export default class Sidebar extends Component {
static propTypes = { static propTypes = {
baseUrl: PropTypes.string, baseUrl: PropTypes.string,
componentId: PropTypes.string, componentId: PropTypes.string,
Site_Name: PropTypes.string.isRequired, Site_Name: PropTypes.string.isRequired,
stackRoot: PropTypes.string.isRequired,
user: PropTypes.object, user: PropTypes.object,
logout: PropTypes.func.isRequired, logout: PropTypes.func.isRequired,
appStart: PropTypes.func appStart: PropTypes.func,
setStackRoot: PropTypes.func
} }
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
showStatus: false, showStatus: false
currentStack: 'RoomsListView'
}; };
Navigation.events().bindComponent(this); Navigation.events().bindComponent(this);
} }
componentDidMount() { componentDidMount() {
this.setStatus(); this.setStatus();
EventEmitter.addEventListener('ChangeStack', this.handleChangeStack);
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
@ -128,10 +129,6 @@ export default class Sidebar extends Component {
} }
} }
componentWillUnmount() {
EventEmitter.removeListener('ChangeStack', this.handleChangeStack);
}
handleChangeStack = (event) => { handleChangeStack = (event) => {
const { stack } = event; const { stack } = event;
this.setStack(stack); this.setStack(stack);
@ -164,16 +161,16 @@ export default class Sidebar extends Component {
}); });
} }
setStack = (stack) => { setStack = async(stack) => {
const { currentStack } = this.state; const { stackRoot, setStackRoot } = this.props;
if (currentStack !== stack) { if (stackRoot !== stack) {
Navigation.setStackRoot('AppRoot', { await Navigation.setStackRoot('AppRoot', {
component: { component: {
id: stack, id: stack,
name: stack name: stack
} }
}); });
this.setState({ currentStack: stack }); setStackRoot(stack);
} }
} }
@ -237,7 +234,7 @@ export default class Sidebar extends Component {
} }
renderNavigation = () => { renderNavigation = () => {
const { currentStack } = this.state; const { stackRoot } = this.props;
const { logout } = this.props; const { logout } = this.props;
return ( return (
[ [
@ -246,21 +243,21 @@ export default class Sidebar extends Component {
left: <Icon name='chat-bubble' size={20} />, left: <Icon name='chat-bubble' size={20} />,
onPress: () => this.sidebarNavigate('RoomsListView'), onPress: () => this.sidebarNavigate('RoomsListView'),
testID: 'sidebar-chats', testID: 'sidebar-chats',
current: currentStack === 'RoomsListView' current: stackRoot === 'RoomsListView'
}), }),
this.renderItem({ this.renderItem({
text: I18n.t('Profile'), text: I18n.t('Profile'),
left: <Icon name='person' size={20} />, left: <Icon name='person' size={20} />,
onPress: () => this.sidebarNavigate('ProfileView'), onPress: () => this.sidebarNavigate('ProfileView'),
testID: 'sidebar-profile', testID: 'sidebar-profile',
current: currentStack === 'ProfileView' current: stackRoot === 'ProfileView'
}), }),
this.renderItem({ this.renderItem({
text: I18n.t('Settings'), text: I18n.t('Settings'),
left: <Icon name='settings' size={20} />, left: <Icon name='settings' size={20} />,
onPress: () => this.sidebarNavigate('SettingsView'), onPress: () => this.sidebarNavigate('SettingsView'),
testID: 'sidebar-settings', testID: 'sidebar-settings',
current: currentStack === 'SettingsView' current: stackRoot === 'SettingsView'
}), }),
this.renderSeparator('separator-logout'), this.renderSeparator('separator-logout'),
this.renderItem({ this.renderItem({

View File

@ -3,6 +3,7 @@ import { APP } from '../actions/actionsTypes';
const initialState = { const initialState = {
root: null, root: null,
stackRoot: 'RoomsListView',
starting: true, starting: true,
ready: false, ready: false,
inactive: false, inactive: false,
@ -37,6 +38,11 @@ export default function app(state = initialState, action) {
...state, ...state,
root: action.root root: action.root
}; };
case APP.SET_STACK_ROOT:
return {
...state,
stackRoot: action.stackRoot
};
case APP.INIT: case APP.INIT:
return { return {
...state, ...state,

View File

@ -6,23 +6,38 @@ import {
import { Navigation } from 'react-native-navigation'; import { Navigation } from 'react-native-navigation';
import * as types from '../actions/actionsTypes'; import * as types from '../actions/actionsTypes';
import { appStart } from '../actions'; import { appStart, setStackRoot } from '../actions';
import { selectServerRequest } from '../actions/server'; import { selectServerRequest } from '../actions/server';
import database from '../lib/realm'; import database from '../lib/realm';
import RocketChat from '../lib/rocketchat'; import RocketChat from '../lib/rocketchat';
import EventEmitter from '../utils/events'; import EventEmitter from '../utils/events';
const navigate = function* go({ params, sameServer = true }) { const navigate = function* navigate({ params, sameServer = true }) {
if (!sameServer) { if (!sameServer) {
yield put(appStart('inside')); yield put(appStart('inside'));
} }
if (params.rid) { if (params.rid) {
const canOpenRoom = yield RocketChat.canOpenRoom(params); const canOpenRoom = yield RocketChat.canOpenRoom(params);
if (canOpenRoom) { if (canOpenRoom) {
const stack = 'RoomsListView';
const stackRoot = yield select(state => state.app.stackRoot);
// Make sure current stack is RoomsListView before navigate to RoomView // Make sure current stack is RoomsListView before navigate to RoomView
EventEmitter.emit('ChangeStack', { stack: 'RoomsListView' }); if (stackRoot !== stack) {
yield Navigation.popToRoot('RoomsListView'); yield Navigation.setStackRoot('AppRoot', {
Navigation.push('RoomsListView', { component: {
id: stack,
name: stack
}
});
yield put(setStackRoot(stack));
}
try {
yield Navigation.popToRoot(stack);
} catch (error) {
console.log(error);
}
Navigation.push(stack, {
component: { component: {
name: 'RoomView', name: 'RoomView',
passProps: { passProps: {