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.

ReducedUIDetector.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // @flow
  2. import React, { Component, type Node } from 'react';
  3. import { type Dispatch } from 'redux';
  4. import { connect } from '../../redux';
  5. import { setReducedUI } from '../actions';
  6. import DimensionsDetector from './DimensionsDetector';
  7. /**
  8. * ReducedUIDetector component's property types.
  9. */
  10. type Props = {
  11. /**
  12. * The "onDimensionsHandler" handler.
  13. */
  14. _onDimensionsChanged: Function,
  15. /**
  16. * Any nested components.
  17. */
  18. children: Node
  19. };
  20. /**
  21. * A root {@link View} which captures the 'onLayout' event and figures out
  22. * if the UI is reduced.
  23. */
  24. class ReducedUIDetector extends Component<Props> {
  25. /**
  26. * Renders the root view and it's children.
  27. *
  28. * @returns {Component}
  29. */
  30. render() {
  31. return (
  32. <DimensionsDetector
  33. onDimensionsChanged = { this.props._onDimensionsChanged } >
  34. { this.props.children }
  35. </DimensionsDetector>
  36. );
  37. }
  38. }
  39. /**
  40. * Maps dispatching of the reduced UI actions to React component props.
  41. *
  42. * @param {Function} dispatch - Redux action dispatcher.
  43. * @private
  44. * @returns {{
  45. * _onDimensionsChanged: Function
  46. * }}
  47. */
  48. function _mapDispatchToProps(dispatch: Dispatch<any>) {
  49. return {
  50. /**
  51. * Handles the "on dimensions changed" event and dispatches the
  52. * reduced UI action.
  53. *
  54. * @param {number} width - The new width for the component.
  55. * @param {number} height - The new height for the component.
  56. * @private
  57. * @returns {void}
  58. */
  59. _onDimensionsChanged(width: number, height: number) {
  60. dispatch(setReducedUI(width, height));
  61. }
  62. };
  63. }
  64. export default connect(undefined, _mapDispatchToProps)(ReducedUIDetector);