2017-02-06 21:32:03 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-01-19 22:22:30 +00:00
|
|
|
import { StatusBar } from 'react-native';
|
|
|
|
import { Immersive } from 'react-native-immersive';
|
|
|
|
|
2017-02-08 16:25:49 +00:00
|
|
|
import { APP_STATE_CHANGED } from '../background';
|
2017-01-19 22:22:30 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_FAILED,
|
|
|
|
CONFERENCE_LEFT,
|
|
|
|
CONFERENCE_WILL_JOIN
|
|
|
|
} from '../base/conference';
|
|
|
|
import { Platform } from '../base/react';
|
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param {Store} store - Redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2017-02-08 16:25:49 +00:00
|
|
|
let fullScreen = null;
|
2017-01-19 22:22:30 +00:00
|
|
|
|
|
|
|
switch (action.type) {
|
2017-02-08 16:25:49 +00:00
|
|
|
case APP_STATE_CHANGED: {
|
|
|
|
// Check if we just came back from the background and reenable full
|
|
|
|
// screen mode if necessary.
|
|
|
|
if (action.appState === 'active') {
|
|
|
|
const conference = store.getState()['features/base/conference'];
|
|
|
|
|
|
|
|
fullScreen = conference ? !conference.audioOnly : false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-19 22:22:30 +00:00
|
|
|
case CONFERENCE_WILL_JOIN: {
|
2017-02-06 21:32:03 +00:00
|
|
|
const conference = store.getState()['features/base/conference'];
|
2017-01-19 22:22:30 +00:00
|
|
|
|
2017-02-06 21:32:03 +00:00
|
|
|
fullScreen = !conference.audioOnly;
|
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-02-06 21:32:03 +00:00
|
|
|
if (fullScreen !== null) {
|
|
|
|
_setFullScreen(fullScreen)
|
|
|
|
.catch(err =>
|
|
|
|
console.warn(`Failed to set full screen mode: ${err}`));
|
2017-01-19 22:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2017-01-19 22:22:30 +00:00
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
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') {
|
2017-02-06 21:32:03 +00:00
|
|
|
return fullScreen ? Immersive.on() : Immersive.off();
|
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
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|