load room on return
This commit is contained in:
parent
4f9638b151
commit
0318366aef
|
@ -12,7 +12,8 @@ import * as NavigationService from './routes/NavigationService';
|
||||||
@connect(
|
@connect(
|
||||||
state => ({
|
state => ({
|
||||||
login: state.login,
|
login: state.login,
|
||||||
app: state.app
|
app: state.app,
|
||||||
|
background: state.app.background
|
||||||
}),
|
}),
|
||||||
dispatch => bindActionCreators({
|
dispatch => bindActionCreators({
|
||||||
appInit
|
appInit
|
||||||
|
@ -26,7 +27,7 @@ export default class Routes extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.props.appInit();
|
return !this.props.app.ready && this.props.appInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { NavigationActions } from 'react-navigation';
|
import { NavigationActions } from 'react-navigation';
|
||||||
|
import reduxStore from '../../lib/createStore';
|
||||||
|
|
||||||
const config = {};
|
const config = {};
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ export function goRoom({ rid, name }, counter = 0) {
|
||||||
if (!config.navigator) {
|
if (!config.navigator) {
|
||||||
return setTimeout(() => goRoom({ rid, name }, counter + 1), 200);
|
return setTimeout(() => goRoom({ rid, name }, counter + 1), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
const action = NavigationActions.reset({
|
const action = NavigationActions.reset({
|
||||||
index: 1,
|
index: 1,
|
||||||
actions: [
|
actions: [
|
||||||
|
@ -39,5 +41,5 @@ export function goRoom({ rid, name }, counter = 0) {
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
return config.navigator.dispatch(action);
|
requestAnimationFrame(() => config.navigator.dispatch(action), reduxStore.getState().app.starting);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,46 @@
|
||||||
|
import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate';
|
||||||
import { APP } from '../actions/actionsTypes';
|
import { APP } from '../actions/actionsTypes';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
starting: true
|
starting: true,
|
||||||
|
ready: false,
|
||||||
|
inactive: false,
|
||||||
|
background: false
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function app(state = initialState, action) {
|
export default function app(state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case FOREGROUND:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
inactive: false,
|
||||||
|
foreground: true,
|
||||||
|
background: false
|
||||||
|
};
|
||||||
|
case BACKGROUND:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
inactive: false,
|
||||||
|
foreground: false,
|
||||||
|
background: true
|
||||||
|
};
|
||||||
|
case INACTIVE:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
inactive: true,
|
||||||
|
foreground: false,
|
||||||
|
background: false
|
||||||
|
};
|
||||||
case APP.INIT:
|
case APP.INIT:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
ready: false,
|
||||||
starting: true
|
starting: true
|
||||||
};
|
};
|
||||||
case APP.READY:
|
case APP.READY:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
ready: true,
|
||||||
starting: false
|
starting: false
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -11,6 +11,8 @@ const initialState = {
|
||||||
|
|
||||||
export default function login(state = initialState, action) {
|
export default function login(state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case types.APP.INIT:
|
||||||
|
return initialState;
|
||||||
case types.LOGIN.REQUEST:
|
case types.LOGIN.REQUEST:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
|
@ -81,6 +81,9 @@ export default class RoomView extends React.Component {
|
||||||
this.rid =
|
this.rid =
|
||||||
props.rid ||
|
props.rid ||
|
||||||
props.navigation.state.params.room.rid;
|
props.navigation.state.params.room.rid;
|
||||||
|
this.name = this.props.name ||
|
||||||
|
this.props.navigation.state.params.name ||
|
||||||
|
this.props.navigation.state.params.room.name;
|
||||||
|
|
||||||
this.data = realm
|
this.data = realm
|
||||||
.objects('messages')
|
.objects('messages')
|
||||||
|
@ -96,12 +99,9 @@ export default class RoomView extends React.Component {
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.props.navigation.setParams({
|
this.props.navigation.setParams({
|
||||||
title:
|
title: this.name
|
||||||
this.props.name ||
|
|
||||||
this.props.navigation.state.params.name ||
|
|
||||||
this.props.navigation.state.params.room.name
|
|
||||||
});
|
});
|
||||||
this.props.openRoom({ rid: this.rid });
|
this.props.openRoom({ rid: this.rid, name: this.name });
|
||||||
this.data.addListener(this.updateState);
|
this.data.addListener(this.updateState);
|
||||||
}
|
}
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
|
Loading…
Reference in New Issue