1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- // @flow
-
- import React, { Component } from 'react';
- import { connect } from 'react-redux';
-
- import { setAspectRatio } from '../actions';
- import DimensionsDetector from './DimensionsDetector';
-
- /**
- * AspectRatioDetector component's property types.
- */
- type Props = {
-
- /**
- * The "onDimensionsHandler" handler.
- */
- _onDimensionsChanged: Function,
-
- /**
- * Any nested components.
- */
- children: React$Node
- };
-
- /**
- * A root {@link View} which captures the 'onLayout' event and figures out
- * the aspect ratio of the app.
- */
- class AspectRatioDetector extends Component<Props> {
- /**
- * Renders the root view and it's children.
- *
- * @returns {Component}
- */
- render() {
- return (
- <DimensionsDetector
- onDimensionsChanged = { this.props._onDimensionsChanged } >
- { this.props.children }
- </DimensionsDetector>
- );
- }
- }
-
- /**
- * Maps dispatching of the aspect ratio actions to React component props.
- *
- * @param {Function} dispatch - Redux action dispatcher.
- * @private
- * @returns {{
- * _onDimensionsChanged: Function
- * }}
- */
- function _mapDispatchToProps(dispatch) {
- return {
- /**
- * Handles the "on dimensions changed" event and dispatches aspect ratio
- * changed action.
- *
- * @param {number} width - The new width for the component.
- * @param {number} height - The new height for the component.
- * @private
- * @returns {void}
- */
- _onDimensionsChanged(width: number, height: number) {
- dispatch(setAspectRatio(width, height));
- }
- };
- }
-
- export default connect(undefined, _mapDispatchToProps)(AspectRatioDetector);
|