瀏覽代碼

[RN] aspect-ratio: preserve mode when width === height

If the view gets resized to a 1:1 aspect ratio, remember the previous mode to
avoid flickering when going back to a larger size or different aspect ratio.
master
Saúl Ibarra Corretgé 7 年之前
父節點
當前提交
b4d44f367d
共有 1 個檔案被更改,包括 19 行新增5 行删除
  1. 19
    5
      react/features/base/aspect-ratio/actions.js

+ 19
- 5
react/features/base/aspect-ratio/actions.js 查看文件

3
 import { SET_ASPECT_RATIO } from './actionTypes';
3
 import { SET_ASPECT_RATIO } from './actionTypes';
4
 import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
4
 import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
5
 
5
 
6
+import type { Dispatch } from 'redux';
7
+
6
 /**
8
 /**
7
  * Sets the aspect ratio of the app's user interface based on specific width and
9
  * Sets the aspect ratio of the app's user interface based on specific width and
8
  * height.
10
  * height.
10
  * @param {number} width - The width of the app's user interface.
12
  * @param {number} width - The width of the app's user interface.
11
  * @param {number} height - The height of the app's user interface.
13
  * @param {number} height - The height of the app's user interface.
12
  * @returns {{
14
  * @returns {{
13
- *      type: SET_ASPECT_RATIO,
14
- *      aspectRatio: Symbol
15
+ *     type: SET_ASPECT_RATIO,
16
+ *     aspectRatio: Symbol
15
  * }}
17
  * }}
16
  */
18
  */
17
 export function setAspectRatio(width: number, height: number): Object {
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
 }

Loading…
取消
儲存