Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

middleware.ts 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import ImmersiveMode from 'react-native-immersive-mode';
  2. import { IStore } from '../../app/types';
  3. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../base/app/actionTypes';
  4. import MiddlewareRegistry from '../../base/redux/MiddlewareRegistry';
  5. import StateListenerRegistry from '../../base/redux/StateListenerRegistry';
  6. import { _setImmersiveSubscription } from './actions';
  7. import { shouldUseFullScreen } from './functions';
  8. import logger from './logger';
  9. type BarVisibilityType = {
  10. navigationBottomBar: boolean;
  11. statusBar: boolean;
  12. };
  13. type ImmersiveListener = (visibility: BarVisibilityType) => void;
  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(store => next => action => {
  26. switch (action.type) {
  27. case APP_WILL_MOUNT: {
  28. _setImmersiveListener(store, _onImmersiveChange.bind(undefined, store));
  29. break;
  30. }
  31. case APP_WILL_UNMOUNT:
  32. _setImmersiveListener(store, undefined);
  33. break;
  34. }
  35. return next(action);
  36. });
  37. StateListenerRegistry.register(
  38. /* selector */ shouldUseFullScreen,
  39. /* listener */ fullScreen => _setFullScreen(fullScreen)
  40. );
  41. /**
  42. * Handler for Immersive mode changes. This will be called when Android's
  43. * immersive mode changes. This can happen without us wanting, so re-evaluate if
  44. * immersive mode is desired and reactivate it if needed.
  45. *
  46. * @param {Object} store - The redux store.
  47. * @private
  48. * @returns {void}
  49. */
  50. function _onImmersiveChange({ getState }: IStore) {
  51. const state = getState();
  52. const { appState } = state['features/background'];
  53. if (appState === 'active') {
  54. _setFullScreen(shouldUseFullScreen(state));
  55. }
  56. }
  57. /**
  58. * Activates/deactivates the full screen mode. On iOS it will hide the status
  59. * bar, and on Android it will turn immersive mode on.
  60. *
  61. * @param {boolean} fullScreen - True to set full screen mode, false to
  62. * deactivate it.
  63. * @private
  64. * @returns {void}
  65. */
  66. function _setFullScreen(fullScreen: boolean) {
  67. logger.info(`Setting full-screen mode: ${fullScreen}`);
  68. ImmersiveMode.fullLayout(fullScreen);
  69. ImmersiveMode.setBarMode(fullScreen ? 'Full' : 'Normal');
  70. }
  71. /**
  72. * Notifies the feature filmstrip that the action
  73. * {@link _SET_IMMERSIVE_LISTENER} is being dispatched within a specific redux
  74. * store.
  75. *
  76. * @param {Store} store - The redux store in which the specified action is being
  77. * dispatched.
  78. * @param {Function} listener - Listener for immersive state.
  79. * @private
  80. * @returns {Object} The value returned by {@code next(action)}.
  81. */
  82. function _setImmersiveListener({ dispatch, getState }: IStore, listener?: ImmersiveListener) {
  83. const { subscription } = getState()['features/full-screen'];
  84. subscription?.remove();
  85. dispatch(_setImmersiveSubscription(listener ? ImmersiveMode.addEventListener(listener) : undefined));
  86. }