ref(full-screen/middleware): use StateListenerRegistry

Use state listener to simplify the logic and not care about the actions
since the fullscreen flag is calculated from the current conference
state.
This commit is contained in:
paweldomas 2018-05-24 15:30:59 -05:00 committed by Saúl Ibarra Corretgé
parent dbd1091364
commit bcb955ea72
1 changed files with 12 additions and 29 deletions

View File

@ -4,16 +4,9 @@ import { StatusBar } from 'react-native';
import { Immersive } from 'react-native-immersive';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../app';
import {
CONFERENCE_FAILED,
CONFERENCE_JOINED,
CONFERENCE_LEFT,
CONFERENCE_WILL_JOIN,
SET_AUDIO_ONLY,
getCurrentConference
} from '../../base/conference';
import { getCurrentConference } from '../../base/conference';
import { Platform } from '../../base/react';
import { MiddlewareRegistry } from '../../base/redux';
import { MiddlewareRegistry, StateListenerRegistry } from '../../base/redux';
import { _setImmersiveListener as _setImmersiveListenerA } from './actions';
import { _SET_IMMERSIVE_LISTENER } from './actionTypes';
@ -47,31 +40,21 @@ MiddlewareRegistry.register(store => next => action => {
store.dispatch(_setImmersiveListenerA(undefined));
break;
case CONFERENCE_WILL_JOIN:
case CONFERENCE_JOINED:
case SET_AUDIO_ONLY: {
const result = next(action);
const { audioOnly } = store.getState()['features/base/conference'];
const conference = getCurrentConference(store);
_setFullScreen(conference ? !audioOnly : false);
return result;
}
case CONFERENCE_FAILED:
case CONFERENCE_LEFT: {
const result = next(action);
_setFullScreen(false);
return result;
}
}
return next(action);
});
StateListenerRegistry.register(
/* selector */ state => {
const { audioOnly } = state['features/base/conference'];
const conference = getCurrentConference(state);
return conference ? !audioOnly : false;
},
/* listener */ fullScreen => _setFullScreen(fullScreen)
);
/**
* Handler for Immersive mode changes. This will be called when Android's
* immersive mode changes. This can happen without us wanting, so re-evaluate if