|
@@ -3,6 +3,8 @@
|
3
|
3
|
import { SET_ASPECT_RATIO } from './actionTypes';
|
4
|
4
|
import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
|
5
|
5
|
|
|
6
|
+import type { Dispatch } from 'redux';
|
|
7
|
+
|
6
|
8
|
/**
|
7
|
9
|
* Sets the aspect ratio of the app's user interface based on specific width and
|
8
|
10
|
* height.
|
|
@@ -10,13 +12,25 @@ import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
|
10
|
12
|
* @param {number} width - The width of the app's user interface.
|
11
|
13
|
* @param {number} height - The height of the app's user interface.
|
12
|
14
|
* @returns {{
|
13
|
|
- * type: SET_ASPECT_RATIO,
|
14
|
|
- * aspectRatio: Symbol
|
|
15
|
+ * type: SET_ASPECT_RATIO,
|
|
16
|
+ * aspectRatio: Symbol
|
15
|
17
|
* }}
|
16
|
18
|
*/
|
17
|
19
|
export function setAspectRatio(width: number, height: number): Object {
|
18
|
|
- return {
|
19
|
|
- type: SET_ASPECT_RATIO,
|
20
|
|
- aspectRatio: width < height ? ASPECT_RATIO_NARROW : ASPECT_RATIO_WIDE
|
|
20
|
+ return (dispatch: Dispatch<*>, getState: Function) => {
|
|
21
|
+ // Don't change the aspect ratio if width and height are the same, that
|
|
22
|
+ // is, if we transition to a 1:1 aspect ratio.
|
|
23
|
+ if (width !== height) {
|
|
24
|
+ const aspectRatio
|
|
25
|
+ = width < height ? ASPECT_RATIO_NARROW : ASPECT_RATIO_WIDE;
|
|
26
|
+
|
|
27
|
+ if (aspectRatio
|
|
28
|
+ !== getState()['features/base/aspect-ratio'].aspectRatio) {
|
|
29
|
+ return dispatch({
|
|
30
|
+ type: SET_ASPECT_RATIO,
|
|
31
|
+ aspectRatio
|
|
32
|
+ });
|
|
33
|
+ }
|
|
34
|
+ }
|
21
|
35
|
};
|
22
|
36
|
}
|