[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.
This commit is contained in:
parent
083f6b400b
commit
b4d44f367d
|
@ -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.
|
||||
|
@ -15,8 +17,20 @@ import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
|
|||
* }}
|
||||
*/
|
||||
export function setAspectRatio(width: number, height: number): Object {
|
||||
return {
|
||||
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: width < height ? ASPECT_RATIO_NARROW : ASPECT_RATIO_WIDE
|
||||
aspectRatio
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue