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

middleware.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 - Redux store.
  23. * @returns {Function}
  24. */
  25. MiddlewareRegistry.register(store => next => action => {
  26. let fullScreen = null;
  27. switch (action.type) {
  28. case APP_STATE_CHANGED: {
  29. // Check if we just came back from the background and reenable full
  30. // screen mode if necessary.
  31. if (action.appState === 'active') {
  32. const { audioOnly, conference }
  33. = store.getState()['features/base/conference'];
  34. fullScreen = conference ? !audioOnly : false;
  35. }
  36. break;
  37. }
  38. case CONFERENCE_WILL_JOIN: {
  39. const { audioOnly } = store.getState()['features/base/conference'];
  40. fullScreen = !audioOnly;
  41. break;
  42. }
  43. case CONFERENCE_FAILED:
  44. case CONFERENCE_LEFT:
  45. fullScreen = false;
  46. break;
  47. case HIDE_DIALOG: {
  48. const { audioOnly, conference }
  49. = store.getState()['features/base/conference'];
  50. fullScreen = conference ? !audioOnly : false;
  51. break;
  52. }
  53. case SET_AUDIO_ONLY:
  54. fullScreen = !action.audioOnly;
  55. break;
  56. }
  57. if (fullScreen !== null) {
  58. _setFullScreen(fullScreen)
  59. .catch(err =>
  60. console.warn(`Failed to set full screen mode: ${err}`));
  61. }
  62. return next(action);
  63. });
  64. /**
  65. * Activates/deactivates the full screen mode. On iOS it will hide the status
  66. * bar, and on Android it will turn immersive mode on.
  67. *
  68. * @param {boolean} fullScreen - True to set full screen mode, false to
  69. * deactivate it.
  70. * @private
  71. * @returns {Promise}
  72. */
  73. function _setFullScreen(fullScreen: boolean) {
  74. // XXX The React Native module Immersive is only implemented on Android and
  75. // throws on other platforms.
  76. if (Platform.OS === 'android') {
  77. return fullScreen ? Immersive.on() : Immersive.off();
  78. }
  79. // On platforms other than Android go with whatever React Native itself
  80. // supports.
  81. StatusBar.setHidden(fullScreen, 'slide');
  82. return Promise.resolve();
  83. }