Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions packages/ui/resolution/ResolutionDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import hoc from '@enact/core/hoc';

import {init, config as riConfig, defineScreenTypes, getResolutionClasses} from './resolution';
import {init, config as riConfig, defineScreenTypes, getResolutionClasses, updateBaseFontSize, calculateFontSize} from './resolution';

/**
* Default config for `ResolutionDecorator`.
Expand All @@ -28,6 +28,18 @@ const defaultConfig = {
*/
dynamic: true,

/**
* Font Scale for large text mode.
* Use this value to set the scale of the font.
* This is the value that will be multiplied by pxPerRem, which is determined by resolution.

* @type {Number}
* @default 1
* @public
* @memberof ui/resolution.ResolutionDecorator.defaultConfig
*/
fontScale: 1,

/**
* Determines how to calculate font-size.
* When set to `scale` and the screen is in `landscape` orientation,
Expand Down Expand Up @@ -97,7 +109,8 @@ const ResolutionDecorator = hoc(defaultConfig, (config, Wrapped) => {
static displayName = 'ResolutionDecorator';

static propTypes = /** @lends ui/resolution.ResolutionDecorator.prototype */ {
className: PropTypes.string
className: PropTypes.string,
fontScale: PropTypes.number
};

constructor (props) {
Expand All @@ -116,6 +129,12 @@ const ResolutionDecorator = hoc(defaultConfig, (config, Wrapped) => {
this.rootNode = ReactDOM.findDOMNode(this);
}

componentDidUpdate (prevProps) {
if (prevProps.fontScale !== this.props.fontScale) {
updateBaseFontSize(calculateFontSize(null, this.props.fontScale));
}
}

componentWillUnmount () {
if (config.dynamic) window.removeEventListener('resize', this.handleResize);
}
Expand Down Expand Up @@ -145,11 +164,15 @@ const ResolutionDecorator = hoc(defaultConfig, (config, Wrapped) => {
}

render () {
const {...rest} = this.props;

delete rest.fontScale;

// Check if the classes are different from our previous classes
let classes = getResolutionClasses();

if (this.props.className) classes += (classes ? ' ' : '') + this.props.className;
return <Wrapped {...this.props} className={classes} />;
return <Wrapped {...rest} className={classes} />;
}
};
});
Expand Down
11 changes: 6 additions & 5 deletions packages/ui/resolution/resolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,18 @@ function getScreenType (rez) {
* @returns {String} The calculated pixel size (with unit suffix. Ex: "24px").
* @public
*/
function calculateFontSize (type) {
function calculateFontSize (type, fontScale = 1) {
const scrObj = getScreenTypeObject(type);
const shouldScaleFontSize = (config.intermediateScreenHandling === 'scale') && (config.matchSmallerScreenType ? workspaceBounds.width > scrObj.width && workspaceBounds.height > scrObj.height :
workspaceBounds.width < scrObj.width && workspaceBounds.height < scrObj.height);
let size;

if (orientation === 'portrait' && config.orientationHandling === 'scale') {
size = scrObj.height / scrObj.width * scrObj.pxPerRem;
size = scrObj.height / scrObj.width * (scrObj.pxPerRem * fontScale);
} else {
size = scrObj.pxPerRem;
size = (scrObj.pxPerRem * fontScale);
if (orientation === 'landscape' && shouldScaleFontSize) {
size = parseInt(workspaceBounds.height * scrObj.pxPerRem / scrObj.height);
size = parseInt(workspaceBounds.height * (scrObj.pxPerRem * fontScale) / scrObj.height);
}
}
return size + 'px';
Expand Down Expand Up @@ -494,5 +494,6 @@ export {
scaleToRem,
selectSrc,
unit,
unitToPixelFactors
unitToPixelFactors,
updateBaseFontSize
};