|
|
@@ -1,33 +1,33 @@
|
|
1
|
|
-import PropTypes from 'prop-types';
|
|
|
1
|
+// @flow
|
|
|
2
|
+
|
|
2
|
3
|
import React, { Component } from 'react';
|
|
3
|
|
-import { View } from 'react-native';
|
|
4
|
4
|
import { connect } from 'react-redux';
|
|
5
|
5
|
|
|
|
6
|
+import { DimensionsDetector } from '../../dimensions-detector';
|
|
|
7
|
+
|
|
6
|
8
|
import { setAspectRatio } from '../actions';
|
|
7
|
|
-import styles from './styles';
|
|
8
|
9
|
|
|
9
|
10
|
/**
|
|
10
|
|
- * A root {@link View} which captures the 'onLayout' event and figures out
|
|
11
|
|
- * the aspect ratio of the app.
|
|
|
11
|
+ * AspectRatioDetector component's property types.
|
|
12
|
12
|
*/
|
|
13
|
|
-class AspectRatioDetector extends Component {
|
|
|
13
|
+type Props = {
|
|
|
14
|
+
|
|
14
|
15
|
/**
|
|
15
|
|
- * AspectRatioDetector component's property types.
|
|
16
|
|
- *
|
|
17
|
|
- * @static
|
|
|
16
|
+ * The "onDimensionsHandler" handler.
|
|
18
|
17
|
*/
|
|
19
|
|
- static propTypes = {
|
|
20
|
|
- /**
|
|
21
|
|
- * The "onLayout" handler.
|
|
22
|
|
- */
|
|
23
|
|
- _onLayout: PropTypes.func,
|
|
|
18
|
+ _onDimensionsChanged: Function,
|
|
24
|
19
|
|
|
25
|
|
- /**
|
|
26
|
|
- * Any nested components.
|
|
27
|
|
- */
|
|
28
|
|
- children: PropTypes.node
|
|
29
|
|
- };
|
|
|
20
|
+ /**
|
|
|
21
|
+ * Any nested components.
|
|
|
22
|
+ */
|
|
|
23
|
+ children: React$Node
|
|
|
24
|
+};
|
|
30
|
25
|
|
|
|
26
|
+/**
|
|
|
27
|
+ * A root {@link View} which captures the 'onLayout' event and figures out
|
|
|
28
|
+ * the aspect ratio of the app.
|
|
|
29
|
+ */
|
|
|
30
|
+class AspectRatioDetector extends Component<Props> {
|
|
31
|
31
|
/**
|
|
32
|
32
|
* Renders the root view and it's children.
|
|
33
|
33
|
*
|
|
|
@@ -35,11 +35,10 @@ class AspectRatioDetector extends Component {
|
|
35
|
35
|
*/
|
|
36
|
36
|
render() {
|
|
37
|
37
|
return (
|
|
38
|
|
- <View
|
|
39
|
|
- onLayout = { this.props._onLayout }
|
|
40
|
|
- style = { styles.aspectRatioDetector } >
|
|
|
38
|
+ <DimensionsDetector
|
|
|
39
|
+ onDimensionsChanged = { this.props._onDimensionsChanged } >
|
|
41
|
40
|
{ this.props.children }
|
|
42
|
|
- </View>
|
|
|
41
|
+ </DimensionsDetector>
|
|
43
|
42
|
);
|
|
44
|
43
|
}
|
|
45
|
44
|
}
|
|
|
@@ -50,21 +49,21 @@ class AspectRatioDetector extends Component {
|
|
50
|
49
|
* @param {Function} dispatch - Redux action dispatcher.
|
|
51
|
50
|
* @private
|
|
52
|
51
|
* @returns {{
|
|
53
|
|
- * _onLayout: Function
|
|
|
52
|
+ * _onDimensionsChanged: Function
|
|
54
|
53
|
* }}
|
|
55
|
54
|
*/
|
|
56
|
55
|
function _mapDispatchToProps(dispatch) {
|
|
57
|
56
|
return {
|
|
58
|
57
|
/**
|
|
59
|
|
- * Handles the "on layout" View's event and dispatches aspect ratio
|
|
|
58
|
+ * Handles the "on dimensions changed" event and dispatches aspect ratio
|
|
60
|
59
|
* changed action.
|
|
61
|
60
|
*
|
|
62
|
|
- * @param {Object} event - The "on layout" event object/structure passed
|
|
63
|
|
- * by react-native.
|
|
|
61
|
+ * @param {number} width - The new width for the component.
|
|
|
62
|
+ * @param {number} height - The new height for the component.
|
|
64
|
63
|
* @private
|
|
65
|
64
|
* @returns {void}
|
|
66
|
65
|
*/
|
|
67
|
|
- _onLayout({ nativeEvent: { layout: { height, width } } }) {
|
|
|
66
|
+ _onDimensionsChanged(width: number, height: number) {
|
|
68
|
67
|
dispatch(setAspectRatio(width, height));
|
|
69
|
68
|
}
|
|
70
|
69
|
};
|