2017-11-07 14:28:08 +00:00
|
|
|
// @flow
|
2017-10-13 16:13:46 +00:00
|
|
|
|
2018-02-02 13:39:27 +00:00
|
|
|
import { SET_ASPECT_RATIO, SET_REDUCED_UI } from './actionTypes';
|
2017-10-13 16:13:46 +00:00
|
|
|
import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
|
|
|
|
|
2018-01-31 16:35:40 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2018-02-02 13:39:27 +00:00
|
|
|
/**
|
|
|
|
* Size threshold for determining if we are in reduced UI mode or not.
|
2018-03-22 16:22:33 +00:00
|
|
|
*
|
|
|
|
* FIXME The logic to base {@code reducedUI} on a hardcoded width or height is
|
|
|
|
* very brittle because it's completely disconnected from the UI which wants to
|
|
|
|
* be rendered and, naturally, it broke on iPad where even the secondary Toolbar
|
|
|
|
* didn't fit in the height. We do need to measure the actual UI at runtime and
|
|
|
|
* determine whether and how to render it. I'm bumping from 240 to 300 because I
|
|
|
|
* don't have the time now to refactor {@code ReducedUIDetector} or rip it out
|
|
|
|
* completely.
|
2018-02-02 13:39:27 +00:00
|
|
|
*/
|
2018-03-22 16:22:33 +00:00
|
|
|
const REDUCED_UI_THRESHOLD = 300;
|
2018-02-02 13:39:27 +00:00
|
|
|
|
2017-10-13 16:13:46 +00:00
|
|
|
/**
|
2017-11-07 14:28:08 +00:00
|
|
|
* Sets the aspect ratio of the app's user interface based on specific width and
|
|
|
|
* height.
|
2017-10-13 16:13:46 +00:00
|
|
|
*
|
2017-11-07 14:28:08 +00:00
|
|
|
* @param {number} width - The width of the app's user interface.
|
|
|
|
* @param {number} height - The height of the app's user interface.
|
2017-10-13 16:13:46 +00:00
|
|
|
* @returns {{
|
2018-01-31 16:35:40 +00:00
|
|
|
* type: SET_ASPECT_RATIO,
|
|
|
|
* aspectRatio: Symbol
|
2017-10-13 16:13:46 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2018-05-22 14:23:03 +00:00
|
|
|
export function setAspectRatio(width: number, height: number): Function {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
2018-01-31 16:35:40 +00:00
|
|
|
// 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
|
2018-02-06 18:14:05 +00:00
|
|
|
!== getState()['features/base/responsive-ui'].aspectRatio) {
|
2018-01-31 16:35:40 +00:00
|
|
|
return dispatch({
|
|
|
|
type: SET_ASPECT_RATIO,
|
|
|
|
aspectRatio
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-10-13 16:13:46 +00:00
|
|
|
};
|
|
|
|
}
|
2018-02-02 13:39:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the "reduced UI" property. In reduced UI mode some components will
|
|
|
|
* be hidden if there is no space to render them.
|
|
|
|
*
|
|
|
|
* @param {number} width - Current usable width.
|
|
|
|
* @param {number} height - Current usable height.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_REDUCED_UI,
|
|
|
|
* reducedUI: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
2018-05-22 14:23:03 +00:00
|
|
|
export function setReducedUI(width: number, height: number): Function {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
2018-02-02 13:39:27 +00:00
|
|
|
const reducedUI = Math.min(width, height) < REDUCED_UI_THRESHOLD;
|
|
|
|
|
|
|
|
if (reducedUI !== getState()['features/base/responsive-ui'].reducedUI) {
|
|
|
|
return dispatch({
|
|
|
|
type: SET_REDUCED_UI,
|
|
|
|
reducedUI
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|