[FIX][ANDROID] Fix return from background (#115)

* fix frozen screen when app return from background (Android)

* Update state.js

* Update state.js

* Update RoomsListView.js
This commit is contained in:
Guilherme Gazzo 2017-11-28 09:01:18 -02:00 committed by Diego Mello
parent 69a0746850
commit 43f1892570
7 changed files with 47 additions and 8 deletions

View File

@ -2,6 +2,7 @@ import { createStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga'; import createSagaMiddleware from 'redux-saga';
import logger from 'redux-logger'; import logger from 'redux-logger';
import { composeWithDevTools } from 'remote-redux-devtools'; import { composeWithDevTools } from 'remote-redux-devtools';
import applyAppStateListener from 'redux-enhancer-react-native-appstate';
import reducers from '../reducers'; import reducers from '../reducers';
import sagas from '../sagas'; import sagas from '../sagas';
@ -13,12 +14,16 @@ if (__DEV__) {
const reduxImmutableStateInvariant = require('redux-immutable-state-invariant').default(); const reduxImmutableStateInvariant = require('redux-immutable-state-invariant').default();
enhacers = composeWithDevTools( enhacers = composeWithDevTools(
applyAppStateListener(),
applyMiddleware(reduxImmutableStateInvariant), applyMiddleware(reduxImmutableStateInvariant),
applyMiddleware(sagaMiddleware), applyMiddleware(sagaMiddleware),
applyMiddleware(logger) applyMiddleware(logger)
); );
} else { } else {
enhacers = composeWithDevTools(applyMiddleware(sagaMiddleware)); enhacers = composeWithDevTools(
applyAppStateListener(),
applyMiddleware(sagaMiddleware)
);
} }
const store = enhacers(createStore)(reducers); const store = enhacers(createStore)(reducers);

View File

@ -7,6 +7,7 @@ import messages from './messages';
import selectServer from './selectServer'; import selectServer from './selectServer';
import createChannel from './createChannel'; import createChannel from './createChannel';
import init from './init'; import init from './init';
import state from './state';
const root = function* root() { const root = function* root() {
yield all([ yield all([
@ -17,7 +18,8 @@ const root = function* root() {
login(), login(),
connect(), connect(),
messages(), messages(),
selectServer() selectServer(),
state()
]); ]);
}; };
// Consider using takeEvery // Consider using takeEvery

View File

@ -1,5 +1,5 @@
import { AsyncStorage } from 'react-native'; import { AsyncStorage } from 'react-native';
import { call, put, take } from 'redux-saga/effects'; import { call, put, takeLatest } from 'redux-saga/effects';
import * as actions from '../actions'; import * as actions from '../actions';
import { setServer } from '../actions/server'; import { setServer } from '../actions/server';
import { restoreToken } from '../actions/login'; import { restoreToken } from '../actions/login';
@ -9,7 +9,6 @@ import RocketChat from '../lib/rocketchat';
const restore = function* restore() { const restore = function* restore() {
try { try {
yield take(APP.INIT);
const token = yield call([AsyncStorage, 'getItem'], 'reactnativemeteor_usertoken'); const token = yield call([AsyncStorage, 'getItem'], 'reactnativemeteor_usertoken');
if (token) { if (token) {
yield put(restoreToken(token)); yield put(restoreToken(token));
@ -28,4 +27,8 @@ const restore = function* restore() {
console.log(e); console.log(e);
} }
}; };
export default restore;
const root = function* root() {
yield takeLatest(APP.INIT, restore);
};
export default root;

23
app/sagas/state.js Normal file
View File

@ -0,0 +1,23 @@
import { takeLatest } from 'redux-saga/effects';
import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate';
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
yield console.log('appHasComeBackToForeground');
};
const root = function* root() {
yield takeLatest(
FOREGROUND,
appHasComeBackToForeground
);
yield takeLatest(
BACKGROUND,
appHasComeBackToForeground
);
yield takeLatest(
INACTIVE,
appHasComeBackToForeground
);
};
export default root;

View File

@ -259,7 +259,7 @@ export default class RoomsListView extends React.Component {
userMentions={item.userMentions} userMentions={item.userMentions}
favorite={item.f} favorite={item.f}
name={item.name} name={item.name}
_updatedAt={item._updatedAt} _updatedAt={item.roomUpdatedAt}
key={item._id} key={item._id}
type={item.t} type={item.t}
baseUrl={this.props.Site_Url} baseUrl={this.props.Site_Url}

5
package-lock.json generated
View File

@ -12564,6 +12564,11 @@
"symbol-observable": "1.0.4" "symbol-observable": "1.0.4"
} }
}, },
"redux-enhancer-react-native-appstate": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/redux-enhancer-react-native-appstate/-/redux-enhancer-react-native-appstate-0.3.0.tgz",
"integrity": "sha1-+5Fwk3WM4J9DLNCytWPRNh6PV28="
},
"redux-immutable-state-invariant": { "redux-immutable-state-invariant": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/redux-immutable-state-invariant/-/redux-immutable-state-invariant-2.1.0.tgz", "resolved": "https://registry.npmjs.org/redux-immutable-state-invariant/-/redux-immutable-state-invariant-2.1.0.tgz",

View File

@ -46,14 +46,15 @@
"react-redux": "^5.0.6", "react-redux": "^5.0.6",
"realm": "^2.0.7", "realm": "^2.0.7",
"redux": "^3.7.2", "redux": "^3.7.2",
"redux-enhancer-react-native-appstate": "^0.3.0",
"redux-immutable-state-invariant": "^2.1.0", "redux-immutable-state-invariant": "^2.1.0",
"redux-logger": "^3.0.6", "redux-logger": "^3.0.6",
"redux-saga": "^0.16.0", "redux-saga": "^0.16.0",
"regenerator-runtime": "^0.11.0", "regenerator-runtime": "^0.11.0",
"remote-redux-devtools": "^0.5.12", "remote-redux-devtools": "^0.5.12",
"strip-ansi": "^4.0.0",
"@storybook/react-native": "^3.2.15", "@storybook/react-native": "^3.2.15",
"snyk": "^1.41.1" "snyk": "^1.41.1",
"strip-ansi": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@storybook/addon-storyshots": "^3.2.15", "@storybook/addon-storyshots": "^3.2.15",