From b4d44f367df69c1cae661a2c8680c8a12b0f844a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 31 Jan 2018 17:35:40 +0100 Subject: [PATCH] [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. --- react/features/base/aspect-ratio/actions.js | 24 ++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/react/features/base/aspect-ratio/actions.js b/react/features/base/aspect-ratio/actions.js index a80018abf..001f78b99 100644 --- a/react/features/base/aspect-ratio/actions.js +++ b/react/features/base/aspect-ratio/actions.js @@ -3,6 +3,8 @@ import { SET_ASPECT_RATIO } from './actionTypes'; import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants'; +import type { Dispatch } from 'redux'; + /** * Sets the aspect ratio of the app's user interface based on specific width and * height. @@ -10,13 +12,25 @@ import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants'; * @param {number} width - The width of the app's user interface. * @param {number} height - The height of the app's user interface. * @returns {{ - * type: SET_ASPECT_RATIO, - * aspectRatio: Symbol + * type: SET_ASPECT_RATIO, + * aspectRatio: Symbol * }} */ export function setAspectRatio(width: number, height: number): Object { - return { - type: SET_ASPECT_RATIO, - aspectRatio: width < height ? ASPECT_RATIO_NARROW : ASPECT_RATIO_WIDE + return (dispatch: Dispatch<*>, getState: Function) => { + // Don't change the aspect ratio if width and height are the same, that + // is, if we transition to a 1:1 aspect ratio. + if (width !== height) { + const aspectRatio + = width < height ? ASPECT_RATIO_NARROW : ASPECT_RATIO_WIDE; + + if (aspectRatio + !== getState()['features/base/aspect-ratio'].aspectRatio) { + return dispatch({ + type: SET_ASPECT_RATIO, + aspectRatio + }); + } + } }; }