您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* @flow */
  2. import { StatusBar } from 'react-native';
  3. import { Immersive } from 'react-native-immersive';
  4. import { APP_STATE_CHANGED } from '../background';
  5. import {
  6. CONFERENCE_FAILED,
  7. CONFERENCE_LEFT,
  8. CONFERENCE_WILL_JOIN,
  9. SET_AUDIO_ONLY
  10. } from '../../base/conference';
  11. import { HIDE_DIALOG } from '../../base/dialog';
  12. import { Platform } from '../../base/react';
  13. import { MiddlewareRegistry } from '../../base/redux';
  14. /**
  15. * Middleware that captures conference actions and activates or deactivates the
  16. * full screen mode. On iOS it hides the status bar, and on Android it uses the
  17. * immersive mode:
  18. * https://developer.android.com/training/system-ui/immersive.html
  19. * In immersive mode the status and navigation bars are hidden and thus the
  20. * entire screen will be covered by our application.
  21. *
  22. * @param {Store} store - The redux store.
  23. * @returns {Function}
  24. */
  25. MiddlewareRegistry.register(({ getState }) => next => action => {
  26. const result = next(action);
  27. let fullScreen = null;
  28. switch (action.type) {
  29. case APP_STATE_CHANGED:
  30. case CONFERENCE_WILL_JOIN:
  31. case HIDE_DIALOG:
  32. case SET_AUDIO_ONLY: {
  33. // Check if we just came back from the background and re-enable full
  34. // screen mode if necessary.
  35. const { appState } = action;
  36. if (typeof appState !== 'undefined' && appState !== 'active') {
  37. break;
  38. }
  39. const { audioOnly, conference, joining }
  40. = getState()['features/base/conference'];
  41. fullScreen = conference || joining ? !audioOnly : false;
  42. break;
  43. }
  44. case CONFERENCE_FAILED:
  45. case CONFERENCE_LEFT:
  46. fullScreen = false;
  47. break;
  48. }
  49. if (fullScreen !== null) {
  50. _setFullScreen(fullScreen)
  51. .catch(err =>
  52. console.warn(`Failed to set full screen mode: ${err}`));
  53. }
  54. return result;
  55. });
  56. /**
  57. * Activates/deactivates the full screen mode. On iOS it will hide the status
  58. * bar, and on Android it will turn immersive mode on.
  59. *
  60. * @param {boolean} fullScreen - True to set full screen mode, false to
  61. * deactivate it.
  62. * @private
  63. * @returns {Promise}
  64. */
  65. function _setFullScreen(fullScreen: boolean) {
  66. // XXX The React Native module Immersive is only implemented on Android and
  67. // throws on other platforms.
  68. if (Platform.OS === 'android') {
  69. return fullScreen ? Immersive.on() : Immersive.off();
  70. }
  71. // On platforms other than Android go with whatever React Native itself
  72. // supports.
  73. StatusBar.setHidden(fullScreen, 'slide');
  74. return Promise.resolve();
  75. }