Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

middleware.js 2.7KB

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