Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WRQ-11247: Added fontScale prop for large text mode scale values #3217

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
11 changes: 9 additions & 2 deletions packages/ui/resolution/ResolutionDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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 Down Expand Up @@ -97,7 +97,8 @@
static displayName = 'ResolutionDecorator';

static propTypes = /** @lends ui/resolution.ResolutionDecorator.prototype */ {
className: PropTypes.string
className: PropTypes.string,
fontScale: PropTypes.number
juwonjeong marked this conversation as resolved.
Show resolved Hide resolved
};

constructor (props) {
Expand All @@ -116,6 +117,12 @@
this.rootNode = ReactDOM.findDOMNode(this);
}

componentDidUpdate (prevProps) {

Check warning on line 120 in packages/ui/resolution/ResolutionDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/ui/resolution/ResolutionDecorator.js#L120

Added line #L120 was not covered by tests
if (prevProps.fontScale !== this.props.fontScale) {
updateBaseFontSize(calculateFontSize(null, this.props.fontScale));

Check warning on line 122 in packages/ui/resolution/ResolutionDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/ui/resolution/ResolutionDecorator.js#L122

Added line #L122 was not covered by tests
juwonjeong marked this conversation as resolved.
Show resolved Hide resolved
}
}

componentWillUnmount () {
if (config.dynamic) window.removeEventListener('resize', this.handleResize);
}
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 @@
* @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);

Check warning on line 204 in packages/ui/resolution/resolution.js

View check run for this annotation

Codecov / codecov/patch

packages/ui/resolution/resolution.js#L204

Added line #L204 was not covered by tests
} 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);

Check warning on line 208 in packages/ui/resolution/resolution.js

View check run for this annotation

Codecov / codecov/patch

packages/ui/resolution/resolution.js#L208

Added line #L208 was not covered by tests
}
}
return size + 'px';
Expand Down Expand Up @@ -494,5 +494,6 @@
scaleToRem,
selectSrc,
unit,
unitToPixelFactors
unitToPixelFactors,
updateBaseFontSize
};