You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. // @flow
  2. import { BackHandler } from 'react-native';
  3. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../base/app';
  4. import { MiddlewareRegistry } from '../../base/redux';
  5. import BackButtonRegistry from './BackButtonRegistry';
  6. // Binding function to the proper instance, so then the event emitter won't replace the
  7. // underlying instance.
  8. BackButtonRegistry.onHardwareBackPress = BackButtonRegistry.onHardwareBackPress.bind(BackButtonRegistry);
  9. /**
  10. * Middleware that captures App lifetime actions and subscribes to application
  11. * state changes. When the application state changes it will fire the action
  12. * required to mute or unmute the local video in case the application goes to
  13. * the background or comes back from it.
  14. *
  15. * @param {Store} store - The redux store.
  16. * @returns {Function}
  17. * @see {@link https://facebook.github.io/react-native/docs/appstate.html}
  18. */
  19. MiddlewareRegistry.register(() => next => action => {
  20. switch (action.type) {
  21. case APP_WILL_MOUNT:
  22. BackHandler.addEventListener('hardwareBackPress', BackButtonRegistry.onHardwareBackPress);
  23. break;
  24. case APP_WILL_UNMOUNT:
  25. BackHandler.removeEventListener('hardwareBackPress', BackButtonRegistry.onHardwareBackPress);
  26. break;
  27. }
  28. return next(action);
  29. });