@enact/ui 5.4.3 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AnnounceDecorator/Announce.js +9 -5
- package/AnnounceDecorator/AnnounceDecorator.js +5 -3
- package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +4 -1
- package/AnnounceDecorator/tests/useAnnounce-specs.js +4 -1
- package/CHANGELOG.md +17 -0
- package/Cancelable/Cancelable.js +7 -0
- package/Cancelable/tests/Cancelable-specs.js +26 -0
- package/Changeable/Changeable.js +6 -0
- package/Changeable/tests/Changeable-specs.js +4 -1
- package/FloatingLayer/FloatingLayer.js +3 -0
- package/FloatingLayer/FloatingLayerDecorator.js +2 -0
- package/FloatingLayer/Scrim.js +3 -0
- package/Marquee/Marquee.module.css +1 -1
- package/Marquee/MarqueeDecorator.js +19 -3
- package/Marquee/tests/Marquee-specs.js +306 -1
- package/Marquee/useMarqueeController.js +6 -4
- package/Measurable/tests/Measurable-specs.js +6 -2
- package/Media/Media.js +5 -2
- package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +4 -1
- package/Resizable/tests/Resizable-specs.js +4 -1
- package/Resizable/tests/useResize-specs.js +4 -1
- package/Routable/Route.js +5 -3
- package/Routable/Router.js +25 -16
- package/Routable/tests/Routable-specs.js +16 -0
- package/Scroller/Scroller.js +6 -5
- package/Scroller/ScrollerBasic.js +5 -5
- package/Skinnable/Skinnable.js +9 -7
- package/Skinnable/tests/Skinnable-specs.js +7 -2
- package/Skinnable/useSkins.js +6 -2
- package/Slider/PositionDecorator.js +20 -5
- package/Slider/Slider.d.ts +4 -0
- package/Slider/Slider.js +10 -0
- package/Slider/tests/Slider-specs.js +18 -0
- package/Slider/utils.js +9 -1
- package/Toggleable/Toggleable.js +4 -2
- package/Toggleable/tests/Toggleable-specs.js +4 -1
- package/Touchable/Touchable.js +6 -4
- package/Touchable/tests/Touchable-specs.js +4 -1
- package/Touchable/tests/useTouch-specs.js +4 -1
- package/Touchable/useTouch.js +7 -2
- package/Transition/Transition.js +2 -0
- package/ViewManager/TransitionGroup.js +3 -0
- package/ViewManager/View.js +2 -0
- package/ViewManager/ViewManager.js +7 -0
- package/VirtualList/VirtualList.js +7 -5
- package/VirtualList/VirtualListBasic.js +59 -8
- package/VirtualList/tests/VirtualList-native-specs.js +14 -0
- package/VirtualList/tests/VirtualList-specs.js +13 -0
- package/internal/IdProvider/IdProvider.js +2 -0
- package/internal/IdProvider/tests/IdProvider-specs.js +4 -1
- package/internal/Pure/tests/Pure-specs.js +7 -0
- package/package.json +12 -7
- package/resolution/ResolutionDecorator.js +21 -18
- package/resolution/index.d.ts +63 -4
- package/resolution/index.js +18 -2
- package/resolution/resolution.js +209 -29
- package/resolution/tests/ResolutionDecorator-specs.js +84 -4
- package/resolution/tests/resolution-specs.js +217 -599
- package/useControlledState/tests/useControlledState-specs.js +4 -1
- package/useControlledState/useControlledState.js +11 -7
- package/useScroll/Scrollbar.js +27 -24
- package/useScroll/ScrollbarTrack.js +5 -3
- package/useScroll/tests/useScroll-specs.js +402 -25
- package/useScroll/useScroll.js +117 -26
- package/useScroll/utilEvent.js +18 -0
|
@@ -104,16 +104,22 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
104
104
|
_this.isItemSized = false;
|
|
105
105
|
_this.shouldUpdateBounds = false;
|
|
106
106
|
_this.dimensionToExtent = 0;
|
|
107
|
+
_this.itemMarginLeft = null;
|
|
108
|
+
_this.itemMarginRight = null;
|
|
109
|
+
_this.itemMarginTop = null;
|
|
110
|
+
_this.itemMarginBottom = null;
|
|
107
111
|
_this.threshold = 0;
|
|
108
112
|
_this.maxFirstIndex = 0;
|
|
109
113
|
_this.curDataSize = 0;
|
|
110
114
|
_this.hasDataSizeChanged = false;
|
|
111
115
|
_this.cc = [];
|
|
112
116
|
_this.scrollPosition = 0;
|
|
117
|
+
_this.prevScrollPosition = 0;
|
|
113
118
|
_this.scrollPositionTarget = 0;
|
|
114
119
|
_this.scrollToPositionTarget = -1;
|
|
115
120
|
// For individually sized item
|
|
116
121
|
_this.itemPositions = [];
|
|
122
|
+
_this.prevItemPositions = [];
|
|
117
123
|
_this.indexToScrollIntoView = -1;
|
|
118
124
|
_this.updateScrollPosition = function (_ref, behavior) {
|
|
119
125
|
var x = _ref.x,
|
|
@@ -165,18 +171,19 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
165
171
|
var maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft;
|
|
166
172
|
var position = _this.getGridPosition(index);
|
|
167
173
|
var offset = 0;
|
|
174
|
+
var marginOffset = isPrimaryDirectionVertical ? _this.itemMarginTop + _this.itemMarginBottom : _this.itemMarginLeft + _this.itemMarginRight;
|
|
168
175
|
if (stickTo === 'start') {
|
|
169
176
|
// 'start'
|
|
170
177
|
offset = optionalOffset;
|
|
171
178
|
} else if (_this.props.itemSizes) {
|
|
172
179
|
// 'end' for different item sizes
|
|
173
|
-
offset = primary.clientSize - _this.props.itemSizes[index] - optionalOffset;
|
|
180
|
+
offset = primary.clientSize - _this.props.itemSizes[index] - (optionalOffset || marginOffset);
|
|
174
181
|
} else if (stickTo === 'center') {
|
|
175
182
|
// 'center'
|
|
176
183
|
offset = primary.clientSize / 2 - primary.gridSize / 2 - optionalOffset;
|
|
177
184
|
} else {
|
|
178
185
|
// 'end' for same item sizes
|
|
179
|
-
offset = primary.clientSize - primary.itemSize - optionalOffset;
|
|
186
|
+
offset = primary.clientSize - primary.itemSize - (optionalOffset || marginOffset);
|
|
180
187
|
}
|
|
181
188
|
|
|
182
189
|
/* istanbul ignore next */
|
|
@@ -350,6 +357,7 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
350
357
|
}
|
|
351
358
|
return false;
|
|
352
359
|
};
|
|
360
|
+
(0, _util.checkPropTypes)(_this, _props);
|
|
353
361
|
_this.contentRef = /*#__PURE__*/(0, _react.createRef)();
|
|
354
362
|
_this.itemContainerRefs = [];
|
|
355
363
|
_this.state = {
|
|
@@ -387,6 +395,20 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
387
395
|
}, {
|
|
388
396
|
key: "componentDidUpdate",
|
|
389
397
|
value: function componentDidUpdate(prevProps, prevState) {
|
|
398
|
+
var items = this.props.itemRefs.current;
|
|
399
|
+
(0, _util.checkPropTypes)(this, this.props, prevProps);
|
|
400
|
+
if (!this.itemMarginTop && this.itemMarginTop !== 0 && items[0]) {
|
|
401
|
+
var firstItemStyle = window.getComputedStyle(items[0]);
|
|
402
|
+
this.itemMarginTop = Number(firstItemStyle.getPropertyValue('margin-top').slice(0, -2));
|
|
403
|
+
this.itemMarginBottom = Number(firstItemStyle.getPropertyValue('margin-bottom').slice(0, -2));
|
|
404
|
+
this.itemMarginLeft = Number(firstItemStyle.getPropertyValue('margin-left').slice(0, -2));
|
|
405
|
+
this.itemMarginRight = Number(firstItemStyle.getPropertyValue('margin-right').slice(0, -2));
|
|
406
|
+
if (this.isPrimaryDirectionVertical) {
|
|
407
|
+
this.scrollBounds.maxTop += this.itemMarginTop + this.itemMarginBottom;
|
|
408
|
+
} else {
|
|
409
|
+
this.scrollBounds.maxLeft += this.itemMarginLeft + this.itemMarginRight;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
390
412
|
var deferScrollTo = false;
|
|
391
413
|
var _this$state = this.state,
|
|
392
414
|
firstIndex = _this$state.firstIndex,
|
|
@@ -442,17 +464,42 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
442
464
|
}
|
|
443
465
|
}
|
|
444
466
|
if (prevProps.direction !== this.props.direction || prevProps.overhang !== this.props.overhang || prevProps.spacing !== this.props.spacing || !(0, _equals["default"])(prevProps.itemSize, this.props.itemSize) || !this.hasDataSizeChanged && !(0, _util.shallowEqual)(prevProps.itemSizes, this.props.itemSizes)) {
|
|
445
|
-
var _this$getXY = this.getXY(this.scrollPosition, 0),
|
|
446
|
-
x = _this$getXY.x,
|
|
447
|
-
y = _this$getXY.y;
|
|
448
|
-
this.calculateMetrics(this.props);
|
|
449
|
-
this.setState(this.getStatesAndUpdateBounds(this.props));
|
|
450
|
-
this.setContainerSize();
|
|
451
467
|
var _this$scrollBounds = this.scrollBounds,
|
|
452
468
|
clientHeight = _this$scrollBounds.clientHeight,
|
|
453
469
|
clientWidth = _this$scrollBounds.clientWidth,
|
|
454
470
|
scrollHeight = _this$scrollBounds.scrollHeight,
|
|
455
471
|
scrollWidth = _this$scrollBounds.scrollWidth;
|
|
472
|
+
|
|
473
|
+
/* istanbul ignore next */
|
|
474
|
+
if (this.scrollPosition === 0 && this.moreInfo.firstVisibleIndex !== 0) {
|
|
475
|
+
this.scrollPosition = this.prevScrollPosition;
|
|
476
|
+
this.setState({
|
|
477
|
+
firstIndex: prevState.firstIndex
|
|
478
|
+
});
|
|
479
|
+
this.updateMoreInfo(this.props.dataSize, this.scrollPosition);
|
|
480
|
+
for (var i = prevState.firstIndex; i < prevState.firstIndex + this.state.numOfItems; i++) {
|
|
481
|
+
var _this$itemPositions, _this$prevItemPositio, _this$itemPositions2, _this$prevItemPositio2;
|
|
482
|
+
var size = this.isPrimaryDirectionVertical ? clientHeight : clientWidth;
|
|
483
|
+
if (((_this$itemPositions = this.itemPositions[i + 1]) === null || _this$itemPositions === void 0 ? void 0 : _this$itemPositions.position) > ((_this$prevItemPositio = this.prevItemPositions[i + 1]) === null || _this$prevItemPositio === void 0 ? void 0 : _this$prevItemPositio.position)) {
|
|
484
|
+
if (i === this.moreInfo.lastVisibleIndex && this.getItemBottomPosition(i) > this.scrollPosition + size) {
|
|
485
|
+
this.scrollPosition = this.getItemBottomPosition(i) - size;
|
|
486
|
+
}
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
if (((_this$itemPositions2 = this.itemPositions[i + 1]) === null || _this$itemPositions2 === void 0 ? void 0 : _this$itemPositions2.position) < ((_this$prevItemPositio2 = this.prevItemPositions[i + 1]) === null || _this$prevItemPositio2 === void 0 ? void 0 : _this$prevItemPositio2.position)) {
|
|
490
|
+
if (this.itemPositions[i].position < this.scrollPosition) {
|
|
491
|
+
this.scrollPosition = this.itemPositions[i].position;
|
|
492
|
+
}
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
var _this$getXY = this.getXY(this.scrollPosition, 0),
|
|
498
|
+
x = _this$getXY.x,
|
|
499
|
+
y = _this$getXY.y;
|
|
500
|
+
this.calculateMetrics(this.props);
|
|
501
|
+
this.setState(this.getStatesAndUpdateBounds(this.props, prevState.firstIndex ? prevState.firstIndex : 0));
|
|
502
|
+
this.setContainerSize();
|
|
456
503
|
var xMax = scrollWidth - clientWidth;
|
|
457
504
|
var yMax = scrollHeight - clientHeight;
|
|
458
505
|
this.updateScrollPosition({
|
|
@@ -591,6 +638,10 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
591
638
|
this.secondary = secondary;
|
|
592
639
|
|
|
593
640
|
// reset
|
|
641
|
+
this.prevScrollPosition = this.scrollPosition;
|
|
642
|
+
for (var i = 0; i < this.itemPositions.length; i++) {
|
|
643
|
+
this.prevItemPositions[i] = this.itemPositions[i];
|
|
644
|
+
}
|
|
594
645
|
this.scrollPosition = 0;
|
|
595
646
|
this.scrollToPositionTarget = -1;
|
|
596
647
|
if (scrollMode === 'translate' && this.contentRef.current) {
|
|
@@ -29,6 +29,7 @@ describe('VirtualList with native scrollMode', function () {
|
|
|
29
29
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
30
30
|
// eslint-disable-line enact/display-name
|
|
31
31
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
|
|
32
|
+
"data-index": index,
|
|
32
33
|
id: 'item' + index,
|
|
33
34
|
children: items[index].name
|
|
34
35
|
}));
|
|
@@ -58,6 +59,19 @@ describe('VirtualList with native scrollMode', function () {
|
|
|
58
59
|
var actual = _react.screen.getByRole('list').children.item(0).textContent;
|
|
59
60
|
expect(actual).toBe(expected);
|
|
60
61
|
});
|
|
62
|
+
test('should render a list of \'items\' with horizontal direction', function () {
|
|
63
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList["default"], {
|
|
64
|
+
clientSize: clientSize,
|
|
65
|
+
dataSize: dataSize,
|
|
66
|
+
direction: "horizontal",
|
|
67
|
+
itemRenderer: renderItem,
|
|
68
|
+
itemSize: itemSize,
|
|
69
|
+
scrollMode: "native"
|
|
70
|
+
}));
|
|
71
|
+
var expected = 'Account 0';
|
|
72
|
+
var actual = _react.screen.getByRole('list').children.item(0).textContent;
|
|
73
|
+
expect(actual).toBe(expected);
|
|
74
|
+
});
|
|
61
75
|
test('should render overhang items when clientSize is not given', function () {
|
|
62
76
|
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList["default"], {
|
|
63
77
|
dataSize: dataSize,
|
|
@@ -114,6 +114,7 @@ describe('VirtualList', function () {
|
|
|
114
114
|
rest = _objectWithoutProperties(_ref3, _excluded);
|
|
115
115
|
// eslint-disable-line enact/display-name
|
|
116
116
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
|
|
117
|
+
"data-index": index,
|
|
117
118
|
id: 'item' + index,
|
|
118
119
|
children: items[index].name
|
|
119
120
|
}));
|
|
@@ -152,6 +153,18 @@ describe('VirtualList', function () {
|
|
|
152
153
|
var actual = _react.screen.getByRole('list').children.item(0).textContent;
|
|
153
154
|
expect(actual).toBe(expected);
|
|
154
155
|
});
|
|
156
|
+
test('should render a list of \'items\' with horizontal direction', function () {
|
|
157
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList["default"], {
|
|
158
|
+
clientSize: clientSize,
|
|
159
|
+
dataSize: dataSize,
|
|
160
|
+
direction: "horizontal",
|
|
161
|
+
itemRenderer: renderItem,
|
|
162
|
+
itemSize: itemSize
|
|
163
|
+
}));
|
|
164
|
+
var expected = 'Account 0';
|
|
165
|
+
var actual = _react.screen.getByRole('list').children.item(0).textContent;
|
|
166
|
+
expect(actual).toBe(expected);
|
|
167
|
+
});
|
|
155
168
|
test('should render overhang items when clientSize is not given', function () {
|
|
156
169
|
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList["default"], {
|
|
157
170
|
dataSize: dataSize,
|
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "useId", {
|
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
|
|
14
|
+
var _util = require("@enact/core/util");
|
|
14
15
|
var _useId2 = _interopRequireDefault(require("./useId"));
|
|
15
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
@@ -66,6 +67,7 @@ var IdProvider = exports.IdProvider = (0, _hoc["default"])(defaultConfig, functi
|
|
|
66
67
|
|
|
67
68
|
// eslint-disable-next-line no-shadow
|
|
68
69
|
function IdProvider(props) {
|
|
70
|
+
(0, _util.checkPropTypes)(IdProvider, props);
|
|
69
71
|
var updated = _objectSpread({}, props);
|
|
70
72
|
var _useId = (0, _useId2["default"])({
|
|
71
73
|
prefix: prefix
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
4
|
var _react = require("@testing-library/react");
|
|
5
|
+
var _react2 = require("react");
|
|
5
6
|
var _IdProvider = _interopRequireDefault(require("../IdProvider"));
|
|
6
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
@@ -30,7 +31,9 @@ describe('IdProvider', function () {
|
|
|
30
31
|
var expected = 'customProp';
|
|
31
32
|
var actual;
|
|
32
33
|
var Base = function Base(props) {
|
|
33
|
-
|
|
34
|
+
(0, _react2.useEffect)(function () {
|
|
35
|
+
actual = props;
|
|
36
|
+
}, [props]);
|
|
34
37
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
35
38
|
};
|
|
36
39
|
var Component = (0, _IdProvider["default"])({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _util = require("@enact/core/util");
|
|
3
4
|
require("@testing-library/jest-dom");
|
|
4
5
|
var _react = require("@testing-library/react");
|
|
5
6
|
var _react2 = require("react");
|
|
@@ -35,11 +36,17 @@ var Base = /*#__PURE__*/function (_Component) {
|
|
|
35
36
|
var _this;
|
|
36
37
|
_classCallCheck(this, Base);
|
|
37
38
|
_this = _callSuper(this, Base, [props]);
|
|
39
|
+
(0, _util.checkPropTypes)(_this, props);
|
|
38
40
|
_this.countRenders = 0;
|
|
39
41
|
return _this;
|
|
40
42
|
}
|
|
41
43
|
_inherits(Base, _Component);
|
|
42
44
|
return _createClass(Base, [{
|
|
45
|
+
key: "componentDidUpdate",
|
|
46
|
+
value: function componentDidUpdate(prevProps) {
|
|
47
|
+
(0, _util.checkPropTypes)(this, this.props, prevProps);
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
43
50
|
key: "render",
|
|
44
51
|
value: function render() {
|
|
45
52
|
data = this.props;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/ui",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "A collection of simplified unstyled cross-platform UI components for Enact",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,16 +32,21 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@enact/core": "^5.
|
|
36
|
-
"@enact/i18n": "^5.
|
|
35
|
+
"@enact/core": "^5.5.0",
|
|
36
|
+
"@enact/i18n": "^5.5.0",
|
|
37
37
|
"classnames": "^2.5.1",
|
|
38
|
-
"ilib": "^14.21.
|
|
38
|
+
"ilib": "^14.21.3",
|
|
39
39
|
"invariant": "^2.2.4",
|
|
40
40
|
"prop-types": "^15.8.1",
|
|
41
41
|
"ramda": "^0.32.0",
|
|
42
|
-
"react": "^19.2.
|
|
43
|
-
"react-dom": "^19.2.
|
|
44
|
-
"react-is": "^19.2.
|
|
42
|
+
"react": "^19.2.6",
|
|
43
|
+
"react-dom": "^19.2.6",
|
|
44
|
+
"react-is": "^19.2.6",
|
|
45
45
|
"warning": "^4.0.3"
|
|
46
|
+
},
|
|
47
|
+
"overrides": {
|
|
48
|
+
"prop-types": {
|
|
49
|
+
"react-is": "^19.2.6"
|
|
50
|
+
}
|
|
46
51
|
}
|
|
47
52
|
}
|
|
@@ -7,6 +7,7 @@ exports["default"] = exports.ResolutionDecorator = void 0;
|
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
|
|
10
|
+
var _util = require("@enact/core/util");
|
|
10
11
|
var _resolution = require("./resolution");
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
@@ -38,6 +39,10 @@ var defaultConfig = {
|
|
|
38
39
|
/**
|
|
39
40
|
* Attaches an event listener to the window to listen for resize events.
|
|
40
41
|
*
|
|
42
|
+
* When enabled, the resolution classes will be automatically updated when the window
|
|
43
|
+
* is resized or when screen rotation occurs (such as when a device changes from
|
|
44
|
+
* landscape to portrait orientation).
|
|
45
|
+
*
|
|
41
46
|
* @type {Boolean}
|
|
42
47
|
* @default true
|
|
43
48
|
* @public
|
|
@@ -51,23 +56,11 @@ var defaultConfig = {
|
|
|
51
56
|
* When set to `normal`, the font-size will be the pxPerRem value of the best match screen type.
|
|
52
57
|
*
|
|
53
58
|
* @type {('normal'|'scale')}
|
|
54
|
-
* @default '
|
|
55
|
-
* @private
|
|
56
|
-
* @memberof ui/resolution.ResolutionDecorator.defaultConfig
|
|
57
|
-
*/
|
|
58
|
-
intermediateScreenHandling: 'normal',
|
|
59
|
-
/**
|
|
60
|
-
* Determines how to get the best match screen type of current resolution.
|
|
61
|
-
* When set to `true`, the matched screen type will be the one that is smaller and
|
|
62
|
-
* the closest to the screen resolution.
|
|
63
|
-
* When set to `false`, the matched screen type will be the one that is greater and
|
|
64
|
-
* the closest to the screen resolution.
|
|
65
|
-
*
|
|
66
|
-
* @type {Boolean}
|
|
59
|
+
* @default 'scale'
|
|
67
60
|
* @private
|
|
68
61
|
* @memberof ui/resolution.ResolutionDecorator.defaultConfig
|
|
69
62
|
*/
|
|
70
|
-
|
|
63
|
+
fontSizeHandling: 'scale',
|
|
71
64
|
/**
|
|
72
65
|
* An array of objects containing declarations for screen types to add to the list of known
|
|
73
66
|
* screen types.
|
|
@@ -83,13 +76,17 @@ var defaultConfig = {
|
|
|
83
76
|
/**
|
|
84
77
|
* A higher-order component that configures resolution support for its wrapped component tree.
|
|
85
78
|
*
|
|
79
|
+
* This decorator automatically applies resolution-specific CSS classes to the wrapped component,
|
|
80
|
+
* enabling responsive layouts that adapt to different screen sizes, orientations, and aspect ratios.
|
|
81
|
+
* It also supports dynamic updates when the window is resized or when the screen rotates.
|
|
82
|
+
*
|
|
86
83
|
* Configuration options:
|
|
87
|
-
* * `dynamic: true` - when `true`, updates the resolution classes when the window resizes
|
|
84
|
+
* * `dynamic: true` - when `true`, updates the resolution classes when the window resizes or the screen rotates
|
|
88
85
|
* * `screenTypes: null` - defines a set of screen types to support
|
|
89
86
|
*
|
|
90
87
|
* Example:
|
|
91
88
|
* ```
|
|
92
|
-
* // Will have the resolution classes and will be updated when the window resizes
|
|
89
|
+
* // Will have the resolution classes and will be updated when the window resizes or the screen rotates
|
|
93
90
|
* const AppWithResolution = ResolutionDecorator(App);
|
|
94
91
|
* // Will have the resolution classes for the screen at the time of render only
|
|
95
92
|
* const AppWithStaticResolution = ResolutionDecorator({dynamic: false}, App);
|
|
@@ -120,8 +117,9 @@ var ResolutionDecorator = exports.ResolutionDecorator = (0, _hoc["default"])(def
|
|
|
120
117
|
});
|
|
121
118
|
}
|
|
122
119
|
};
|
|
123
|
-
|
|
124
|
-
_resolution.config.
|
|
120
|
+
(0, _util.checkPropTypes)(_this, props);
|
|
121
|
+
_resolution.config.fontSizeHandling = config.fontSizeHandling;
|
|
122
|
+
if (config.linearScaling) _resolution.config.linearScaling = config.linearScaling;
|
|
125
123
|
(0, _resolution.init)({
|
|
126
124
|
measurementNode: typeof window !== 'undefined' && window
|
|
127
125
|
});
|
|
@@ -138,6 +136,11 @@ var ResolutionDecorator = exports.ResolutionDecorator = (0, _hoc["default"])(def
|
|
|
138
136
|
if (config.dynamic) window.addEventListener('resize', this.handleResize);
|
|
139
137
|
this.rootNode = ((_document$getElements = document.getElementsByClassName((0, _resolution.getResolutionClasses)())) === null || _document$getElements === void 0 ? void 0 : _document$getElements[0]) || null;
|
|
140
138
|
}
|
|
139
|
+
}, {
|
|
140
|
+
key: "componentDidUpdate",
|
|
141
|
+
value: function componentDidUpdate(prevProps) {
|
|
142
|
+
(0, _util.checkPropTypes)(this, this.props, prevProps);
|
|
143
|
+
}
|
|
141
144
|
}, {
|
|
142
145
|
key: "componentWillUnmount",
|
|
143
146
|
value: function componentWillUnmount() {
|
package/resolution/index.d.ts
CHANGED
|
@@ -5,8 +5,12 @@ type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
|
5
5
|
|
|
6
6
|
export interface ResolutionDecoratorConfig extends Object {
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
* Attaches an event listener to the window to listen for resize events.
|
|
9
|
+
*
|
|
10
|
+
* When enabled, the resolution classes will be automatically updated when the window
|
|
11
|
+
is resized or when screen rotation occurs (such as when a device changes from
|
|
12
|
+
landscape to portrait orientation).
|
|
13
|
+
*/
|
|
10
14
|
dynamic?: boolean;
|
|
11
15
|
/**
|
|
12
16
|
* An array of objects containing declarations for screen types to add to the list of known
|
|
@@ -72,7 +76,7 @@ export function getScreenType(rez: object): string;
|
|
|
72
76
|
*
|
|
73
77
|
* This is how the magic happens. This accepts an optional `screenType` name. If one isn't provided,
|
|
74
78
|
the currently detected screen type is used. This uses the config option `orientationHandling` ,
|
|
75
|
-
which when set to "scale" and the screen is in portrait orientation, will dynamically calculate
|
|
79
|
+
which when set to "scale" and the screen is in portrait orientation (such as after screen rotation), will dynamically calculate
|
|
76
80
|
what the base font size should be, if the width were proportionally scaled down to fit in the portrait space.
|
|
77
81
|
*
|
|
78
82
|
* To use, put the following in your application code:
|
|
@@ -83,11 +87,30 @@ ri.config.orientationHandling = 'scale';
|
|
|
83
87
|
ri.init();
|
|
84
88
|
```
|
|
85
89
|
|
|
86
|
-
* This
|
|
90
|
+
* This configuration is particularly useful for applications that support screen rotation and need
|
|
91
|
+
to maintain consistent scaling when the device orientation changes from landscape to portrait or vice versa.
|
|
92
|
+
This has no effect if the screen is in landscape, or if `orientationHandling` is unset.
|
|
87
93
|
*/
|
|
88
94
|
export function calculateFontSize(type: string): string;
|
|
89
95
|
/**
|
|
90
96
|
* Returns the CSS classes for the given `type` .
|
|
97
|
+
*
|
|
98
|
+
* This function generates CSS class names that can be used to style components based on
|
|
99
|
+
the current screen resolution, orientation, and aspect ratio. The returned classes are
|
|
100
|
+
particularly useful for responsive layouts and handling screen rotation scenarios.
|
|
101
|
+
*
|
|
102
|
+
* The following CSS classes are returned:
|
|
103
|
+
* * Orientation class : `enact-orientation-landscape` or `enact-orientation-portrait`
|
|
104
|
+
* * Applied based on the current screen orientation
|
|
105
|
+
* * Updates automatically when device rotation occurs (if dynamic mode is enabled)
|
|
106
|
+
* * Resolution class : `enact-res-{screentype}`
|
|
107
|
+
* * Examples: `enact-res-fhd` , `enact-res-uhd` , `enact-res-hd` , `enact-res-qhd`
|
|
108
|
+
* * Applied based on the matched screen type
|
|
109
|
+
* * Aspect ratio class : `enact-aspect-ratio-{aspectRatioName}`
|
|
110
|
+
* * Examples: `enact-aspect-ratio-hdtv` , `enact-aspect-ratio-cinema` , `enact-aspect-ratio-standard`
|
|
111
|
+
* * Applied based on the screen type's aspect ratio name
|
|
112
|
+
*
|
|
113
|
+
* Example return value: `'enact-orientation-landscape enact-res-fhd enact-aspect-ratio-hdtv'`
|
|
91
114
|
*/
|
|
92
115
|
export function getResolutionClasses(type: string): string;
|
|
93
116
|
/**
|
|
@@ -187,3 +210,39 @@ export function selectSrc(
|
|
|
187
210
|
* This will need to be re-run any time the screen size changes, so all the values can be re-cached.
|
|
188
211
|
*/
|
|
189
212
|
export function init(args: object): void;
|
|
213
|
+
export interface LinearScalingConfig {
|
|
214
|
+
/**
|
|
215
|
+
* Enables linear scaling calculation for
|
|
216
|
+
font sizes and unit conversions. Default: `true` .
|
|
217
|
+
*/
|
|
218
|
+
active: boolean; /**
|
|
219
|
+
* Determines the
|
|
220
|
+
reference screen used for linear scaling calculation.
|
|
221
|
+
Default: `linearScalingType.currentScreen` .
|
|
222
|
+
*/
|
|
223
|
+
type: ui_resolution_linearScalingType;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Configuration options for resolution independence behavior.
|
|
227
|
+
*/
|
|
228
|
+
export interface ResolutionConfig {
|
|
229
|
+
/**
|
|
230
|
+
* Determines how to calculate
|
|
231
|
+
font-size. When set to `'scale'` and the screen is in landscape orientation,
|
|
232
|
+
calculates font-size linearly based on screen resolution. When set to `'normal'` ,
|
|
233
|
+
the font-size will be the pxPerRem value of the best match screen type.
|
|
234
|
+
Default: `'scale'`
|
|
235
|
+
*/
|
|
236
|
+
fontSizeHandling: "normal" | "scale"; /**
|
|
237
|
+
* Determines how to handle screen
|
|
238
|
+
orientation and rotation. When set to `'scale'` and the screen is in portrait
|
|
239
|
+
orientation (due to screen rotation), dynamically calculates the base font size
|
|
240
|
+
based on proportional scaling. When set to `'normal'` , uses the standard pxPerRem
|
|
241
|
+
value. This is particularly useful for supporting device rotation scenarios.
|
|
242
|
+
Default: `'normal'`
|
|
243
|
+
*/
|
|
244
|
+
orientationHandling: "normal" | "scale"; /**
|
|
245
|
+
* Configuration for linear scaling mode.
|
|
246
|
+
*/
|
|
247
|
+
linearScaling: LinearScalingConfig;
|
|
248
|
+
}
|
package/resolution/index.js
CHANGED
|
@@ -29,9 +29,25 @@ var _ResolutionDecorator = _interopRequireDefault(require("./ResolutionDecorator
|
|
|
29
29
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
30
30
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Provides resolution independence utilities for responsive applications.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
34
|
+
* This module enables applications to adapt to different screen resolutions, orientations, and aspect ratios.
|
|
35
|
+
* It includes support for screen rotation scenarios, allowing applications
|
|
36
|
+
* to dynamically adjust their layout and scaling when device orientation changes.
|
|
37
|
+
*
|
|
38
|
+
* Key features:
|
|
39
|
+
* - Automatic detection of a screen type based on resolution
|
|
40
|
+
* - Dynamic font-size calculation for different resolutions
|
|
41
|
+
* - Support for screen rotation and orientation changes
|
|
42
|
+
* - Configurable behavior via {@link ui/resolution.config}
|
|
43
|
+
* - CSS class generation for resolution-specific styling via {@link ui/resolution.getResolutionClasses}
|
|
44
|
+
* - The default export is an object containing the resolution independence methods.
|
|
45
|
+
*
|
|
46
|
+
* Key exports include:
|
|
47
|
+
* - {@link ui/resolution.config} - Configuration object for controlling resolution behavior, screen rotation handling, and more
|
|
48
|
+
* - {@link ui/resolution.getResolutionClasses} - Returns CSS classes for resolution, orientation, and aspect ratio
|
|
49
|
+
* - {@link ui/resolution.ResolutionDecorator} - HOC for wrapping components with resolution support
|
|
50
|
+
* - Other utility functions for scaling, unit conversion, and screen type detection
|
|
35
51
|
*
|
|
36
52
|
* @module ui/resolution
|
|
37
53
|
* @exports ResolutionDecorator
|