import { AppState, AppStateStatus } from 'react-native'; import { eventChannel } from 'redux-saga'; import { take, call, cancelled, delay } from 'redux-saga/effects'; import _ from 'lodash'; // import { StaticNavigator } from '../../services/navigator'; function createAppStateChannel() { return eventChannel((emit: (nextState: AppStateStatus) => void) => { AppState.addEventListener('change', emit); return () => { AppState.removeEventListener('change', emit); }; }); } export function* appStateListenerSaga(): Generator { // const PIN_ROUTE_NAME = 'Pincode'; // const MODAL_SCREENS = ['RestoreModal', 'NotifyModal']; let prevAppState = ''; const appStateChannel = yield call(createAppStateChannel); try { while (true) { const nextAppState: AppStateStatus = yield take(appStateChannel); if (prevAppState.match(/background/) && nextAppState === 'active') { // const currentRoute = StaticNavigator.getCurretRoute(); // if (currentRoute?.name !== PIN_ROUTE_NAME) { // if (_.includes(MODAL_SCREENS, currentRoute?.name)) { // yield call(StaticNavigator.goBack); // yield delay(500); // } // yield call(StaticNavigator.jumpTo, PIN_ROUTE_NAME); // } } prevAppState = nextAppState; } } finally { if (yield cancelled()) { appStateChannel.close(); } } }