2018-02-07 13:34:40 +00:00
|
|
|
// @flow
|
2017-02-06 21:32:03 +00:00
|
|
|
|
2017-01-19 22:22:30 +00:00
|
|
|
import { StatusBar } from 'react-native';
|
|
|
|
import { Immersive } from 'react-native-immersive';
|
|
|
|
|
2018-02-07 13:34:40 +00:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../app';
|
2017-01-19 22:22:30 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_FAILED,
|
2018-02-07 13:34:40 +00:00
|
|
|
CONFERENCE_JOINED,
|
2017-01-19 22:22:30 +00:00
|
|
|
CONFERENCE_LEFT,
|
2017-03-29 12:07:05 +00:00
|
|
|
CONFERENCE_WILL_JOIN,
|
|
|
|
SET_AUDIO_ONLY
|
2017-03-27 09:39:10 +00:00
|
|
|
} from '../../base/conference';
|
|
|
|
import { Platform } from '../../base/react';
|
|
|
|
import { MiddlewareRegistry } from '../../base/redux';
|
2017-01-19 22:22:30 +00:00
|
|
|
|
2018-02-07 13:34:40 +00:00
|
|
|
import { _setImmersiveListener } from './actions';
|
|
|
|
import { _SET_IMMERSIVE_LISTENER } from './actionTypes';
|
|
|
|
|
2017-01-19 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Middleware that captures conference actions and activates or deactivates the
|
2017-02-06 21:32:03 +00:00
|
|
|
* full screen mode. On iOS it hides the status bar, and on Android it uses the
|
2017-01-19 22:22:30 +00:00
|
|
|
* immersive mode:
|
|
|
|
* https://developer.android.com/training/system-ui/immersive.html
|
|
|
|
* In immersive mode the status and navigation bars are hidden and thus the
|
|
|
|
* entire screen will be covered by our application.
|
|
|
|
*
|
2017-08-04 21:06:42 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2017-01-19 22:22:30 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2018-02-07 13:34:40 +00:00
|
|
|
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
2017-08-04 21:06:42 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
2017-02-08 16:25:49 +00:00
|
|
|
let fullScreen = null;
|
2017-01-19 22:22:30 +00:00
|
|
|
|
|
|
|
switch (action.type) {
|
2018-02-07 13:34:40 +00:00
|
|
|
case _SET_IMMERSIVE_LISTENER:
|
|
|
|
// XXX The React Native module Immersive is only implemented on Android
|
|
|
|
// and throws on other platforms.
|
|
|
|
if (Platform.OS === 'android') {
|
|
|
|
// Remove the current/old Immersive listener.
|
|
|
|
const { listener } = getState()['features/full-screen'];
|
|
|
|
|
|
|
|
listener && Immersive.removeImmersiveListener(listener);
|
|
|
|
|
|
|
|
// Add the new listener.
|
|
|
|
action.listener && Immersive.addImmersiveListener(action.listener);
|
2017-02-08 16:25:49 +00:00
|
|
|
}
|
2018-02-07 13:34:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case APP_WILL_MOUNT: {
|
|
|
|
const context = {
|
|
|
|
dispatch,
|
|
|
|
getState
|
|
|
|
};
|
2017-02-08 16:25:49 +00:00
|
|
|
|
2018-02-07 13:34:40 +00:00
|
|
|
dispatch(
|
|
|
|
_setImmersiveListener(_onImmersiveChange.bind(undefined, context)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case APP_WILL_UNMOUNT:
|
|
|
|
_setImmersiveListener(undefined);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFERENCE_WILL_JOIN:
|
|
|
|
case CONFERENCE_JOINED:
|
|
|
|
case SET_AUDIO_ONLY: {
|
2017-10-09 16:13:01 +00:00
|
|
|
const { audioOnly, conference, joining }
|
2017-08-04 21:06:42 +00:00
|
|
|
= getState()['features/base/conference'];
|
2017-01-19 22:22:30 +00:00
|
|
|
|
2017-10-09 16:13:01 +00:00
|
|
|
fullScreen = conference || joining ? !audioOnly : false;
|
2017-01-19 22:22:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CONFERENCE_FAILED:
|
|
|
|
case CONFERENCE_LEFT:
|
2017-02-06 21:32:03 +00:00
|
|
|
fullScreen = false;
|
2017-01-19 22:22:30 +00:00
|
|
|
break;
|
2017-08-02 15:00:51 +00:00
|
|
|
}
|
2017-01-19 22:22:30 +00:00
|
|
|
|
2018-02-07 13:34:40 +00:00
|
|
|
fullScreen !== null && _setFullScreen(fullScreen);
|
2017-01-19 22:22:30 +00:00
|
|
|
|
2017-08-04 21:06:42 +00:00
|
|
|
return result;
|
2017-01-19 22:22:30 +00:00
|
|
|
});
|
|
|
|
|
2018-02-07 13:34:40 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* immersive mode is desired and reactivate it if needed.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The redux store.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _onImmersiveChange({ getState }) {
|
|
|
|
const state = getState();
|
|
|
|
const { appState } = state['features/background'];
|
|
|
|
|
|
|
|
if (appState === 'active') {
|
|
|
|
const { audioOnly, conference, joining }
|
|
|
|
= state['features/base/conference'];
|
|
|
|
const fullScreen = conference || joining ? !audioOnly : false;
|
|
|
|
|
|
|
|
_setFullScreen(fullScreen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Activates/deactivates the full screen mode. On iOS it will hide the status
|
2017-02-06 21:32:03 +00:00
|
|
|
* bar, and on Android it will turn immersive mode on.
|
2017-01-19 22:22:30 +00:00
|
|
|
*
|
2017-02-06 21:32:03 +00:00
|
|
|
* @param {boolean} fullScreen - True to set full screen mode, false to
|
2017-01-19 22:22:30 +00:00
|
|
|
* deactivate it.
|
2017-02-06 21:32:03 +00:00
|
|
|
* @private
|
2018-02-07 13:34:40 +00:00
|
|
|
* @returns {void}
|
2017-01-19 22:22:30 +00:00
|
|
|
*/
|
2017-02-06 21:32:03 +00:00
|
|
|
function _setFullScreen(fullScreen: boolean) {
|
|
|
|
// XXX The React Native module Immersive is only implemented on Android and
|
|
|
|
// throws on other platforms.
|
2017-01-19 22:22:30 +00:00
|
|
|
if (Platform.OS === 'android') {
|
2018-02-07 13:34:40 +00:00
|
|
|
fullScreen ? Immersive.on() : Immersive.off();
|
|
|
|
|
|
|
|
return;
|
2017-01-19 22:22:30 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 21:32:03 +00:00
|
|
|
// On platforms other than Android go with whatever React Native itself
|
|
|
|
// supports.
|
|
|
|
StatusBar.setHidden(fullScreen, 'slide');
|
2017-01-19 22:22:30 +00:00
|
|
|
}
|