@enact/ui 5.4.2 → 5.4.3
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/CHANGELOG.md +8 -0
- package/VirtualList/VirtualListBasic.js +8 -54
- package/package.json +6 -6
- package/useScroll/tests/useScroll-specs.js +25 -261
- package/useScroll/useScroll.js +16 -27
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
The following is a curated list of changes in the Enact ui module, newest changes on the top.
|
|
4
4
|
|
|
5
|
+
## [5.4.3] - 2026-02-26
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `ui/VirtualList` to revert 5.4.2 cix that not to jump to the top when item size was changed
|
|
10
|
+
- `ui/VirtulList` to revert 5.4.2 fix that not to cut off focused item when scroll by pressing key
|
|
11
|
+
- `ui/VirtualList.VirtualGridList` to revert 5.4.2 fix to adjust itemSize properly when resizing window
|
|
12
|
+
|
|
5
13
|
## [5.4.2] - 2026-01-28
|
|
6
14
|
|
|
7
15
|
### Changed
|
|
@@ -104,22 +104,16 @@ 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;
|
|
111
107
|
_this.threshold = 0;
|
|
112
108
|
_this.maxFirstIndex = 0;
|
|
113
109
|
_this.curDataSize = 0;
|
|
114
110
|
_this.hasDataSizeChanged = false;
|
|
115
111
|
_this.cc = [];
|
|
116
112
|
_this.scrollPosition = 0;
|
|
117
|
-
_this.prevScrollPosition = 0;
|
|
118
113
|
_this.scrollPositionTarget = 0;
|
|
119
114
|
_this.scrollToPositionTarget = -1;
|
|
120
115
|
// For individually sized item
|
|
121
116
|
_this.itemPositions = [];
|
|
122
|
-
_this.prevItemPositions = [];
|
|
123
117
|
_this.indexToScrollIntoView = -1;
|
|
124
118
|
_this.updateScrollPosition = function (_ref, behavior) {
|
|
125
119
|
var x = _ref.x,
|
|
@@ -171,19 +165,18 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
171
165
|
var maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft;
|
|
172
166
|
var position = _this.getGridPosition(index);
|
|
173
167
|
var offset = 0;
|
|
174
|
-
var marginOffset = isPrimaryDirectionVertical ? _this.itemMarginTop + _this.itemMarginBottom : _this.itemMarginLeft + _this.itemMarginRight;
|
|
175
168
|
if (stickTo === 'start') {
|
|
176
169
|
// 'start'
|
|
177
170
|
offset = optionalOffset;
|
|
178
171
|
} else if (_this.props.itemSizes) {
|
|
179
172
|
// 'end' for different item sizes
|
|
180
|
-
offset = primary.clientSize - _this.props.itemSizes[index] -
|
|
173
|
+
offset = primary.clientSize - _this.props.itemSizes[index] - optionalOffset;
|
|
181
174
|
} else if (stickTo === 'center') {
|
|
182
175
|
// 'center'
|
|
183
176
|
offset = primary.clientSize / 2 - primary.gridSize / 2 - optionalOffset;
|
|
184
177
|
} else {
|
|
185
178
|
// 'end' for same item sizes
|
|
186
|
-
offset = primary.clientSize - primary.itemSize -
|
|
179
|
+
offset = primary.clientSize - primary.itemSize - optionalOffset;
|
|
187
180
|
}
|
|
188
181
|
|
|
189
182
|
/* istanbul ignore next */
|
|
@@ -394,16 +387,6 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
394
387
|
}, {
|
|
395
388
|
key: "componentDidUpdate",
|
|
396
389
|
value: function componentDidUpdate(prevProps, prevState) {
|
|
397
|
-
var items = document.getElementsByClassName(_VirtualListModule["default"].listItem);
|
|
398
|
-
if (!this.itemMarginTop && this.itemMarginTop !== 0 && items.length > 0) {
|
|
399
|
-
var firstItemStyle = window.getComputedStyle(items[0].children[0]);
|
|
400
|
-
this.itemMarginTop = Number(firstItemStyle.getPropertyValue('margin-top').slice(0, -2));
|
|
401
|
-
this.itemMarginBottom = Number(firstItemStyle.getPropertyValue('margin-bottom').slice(0, -2));
|
|
402
|
-
this.itemMarginLeft = Number(firstItemStyle.getPropertyValue('margin-left').slice(0, -2));
|
|
403
|
-
this.itemMarginRight = Number(firstItemStyle.getPropertyValue('margin-right').slice(0, -2));
|
|
404
|
-
}
|
|
405
|
-
this.scrollBounds.maxTop += this.itemMarginTop + this.itemMarginBottom;
|
|
406
|
-
this.scrollBounds.maxLeft += this.itemMarginLeft + this.itemMarginRight;
|
|
407
390
|
var deferScrollTo = false;
|
|
408
391
|
var _this$state = this.state,
|
|
409
392
|
firstIndex = _this$state.firstIndex,
|
|
@@ -459,42 +442,17 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
459
442
|
}
|
|
460
443
|
}
|
|
461
444
|
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)) {
|
|
462
|
-
var _this$scrollBounds = this.scrollBounds,
|
|
463
|
-
clientHeight = _this$scrollBounds.clientHeight,
|
|
464
|
-
clientWidth = _this$scrollBounds.clientWidth,
|
|
465
|
-
scrollHeight = _this$scrollBounds.scrollHeight,
|
|
466
|
-
scrollWidth = _this$scrollBounds.scrollWidth;
|
|
467
|
-
|
|
468
|
-
/* istanbul ignore next */
|
|
469
|
-
if (this.scrollPosition === 0 && this.moreInfo.firstVisibleIndex !== 0) {
|
|
470
|
-
this.scrollPosition = this.prevScrollPosition;
|
|
471
|
-
this.setState({
|
|
472
|
-
firstIndex: prevState.firstIndex
|
|
473
|
-
});
|
|
474
|
-
this.updateMoreInfo(this.props.dataSize, this.scrollPosition);
|
|
475
|
-
for (var i = prevState.firstIndex; i < prevState.firstIndex + this.state.numOfItems; i++) {
|
|
476
|
-
var _this$itemPositions, _this$prevItemPositio, _this$itemPositions2, _this$prevItemPositio2;
|
|
477
|
-
var size = this.isPrimaryDirectionVertical ? clientHeight : clientWidth;
|
|
478
|
-
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)) {
|
|
479
|
-
if (i === this.moreInfo.lastVisibleIndex && this.getItemBottomPosition(i) > this.scrollPosition + size) {
|
|
480
|
-
this.scrollPosition = this.getItemBottomPosition(i) - size;
|
|
481
|
-
}
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
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)) {
|
|
485
|
-
if (this.itemPositions[i].position < this.scrollPosition) {
|
|
486
|
-
this.scrollPosition = this.itemPositions[i].position;
|
|
487
|
-
}
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
445
|
var _this$getXY = this.getXY(this.scrollPosition, 0),
|
|
493
446
|
x = _this$getXY.x,
|
|
494
447
|
y = _this$getXY.y;
|
|
495
448
|
this.calculateMetrics(this.props);
|
|
496
|
-
this.setState(this.getStatesAndUpdateBounds(this.props
|
|
449
|
+
this.setState(this.getStatesAndUpdateBounds(this.props));
|
|
497
450
|
this.setContainerSize();
|
|
451
|
+
var _this$scrollBounds = this.scrollBounds,
|
|
452
|
+
clientHeight = _this$scrollBounds.clientHeight,
|
|
453
|
+
clientWidth = _this$scrollBounds.clientWidth,
|
|
454
|
+
scrollHeight = _this$scrollBounds.scrollHeight,
|
|
455
|
+
scrollWidth = _this$scrollBounds.scrollWidth;
|
|
498
456
|
var xMax = scrollWidth - clientWidth;
|
|
499
457
|
var yMax = scrollHeight - clientHeight;
|
|
500
458
|
this.updateScrollPosition({
|
|
@@ -633,10 +591,6 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
633
591
|
this.secondary = secondary;
|
|
634
592
|
|
|
635
593
|
// reset
|
|
636
|
-
this.prevScrollPosition = this.scrollPosition;
|
|
637
|
-
for (var i = 0; i < this.itemPositions.length; i++) {
|
|
638
|
-
this.prevItemPositions[i] = this.itemPositions[i];
|
|
639
|
-
}
|
|
640
594
|
this.scrollPosition = 0;
|
|
641
595
|
this.scrollToPositionTarget = -1;
|
|
642
596
|
if (scrollMode === 'translate' && this.contentRef.current) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/ui",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.3",
|
|
4
4
|
"description": "A collection of simplified unstyled cross-platform UI components for Enact",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@enact/core": "^5.4.
|
|
36
|
-
"@enact/i18n": "^5.4.
|
|
35
|
+
"@enact/core": "^5.4.3",
|
|
36
|
+
"@enact/i18n": "^5.4.3",
|
|
37
37
|
"classnames": "^2.5.1",
|
|
38
38
|
"ilib": "^14.21.2",
|
|
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.4",
|
|
43
|
+
"react-dom": "^19.2.4",
|
|
44
|
+
"react-is": "^19.2.4",
|
|
45
45
|
"warning": "^4.0.3"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1,266 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
|
-
var _react = require("@testing-library/react");
|
|
5
|
-
var _useScroll = require("../useScroll");
|
|
6
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
9
|
-
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
10
|
-
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
11
|
-
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
12
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
13
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
|
-
// Mock all dependencies at the top level BEFORE importing useScroll
|
|
15
|
-
var mockRiScale;
|
|
16
|
-
var mockPlatform;
|
|
17
|
-
jest.mock('../../resolution', function () {
|
|
18
|
-
return {
|
|
19
|
-
__esModule: true,
|
|
20
|
-
"default": {
|
|
21
|
-
get scale() {
|
|
22
|
-
return mockRiScale || function (val) {
|
|
23
|
-
return val;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
jest.mock('@enact/core/platform', function () {
|
|
30
|
-
return {
|
|
31
|
-
__esModule: true,
|
|
32
|
-
get platform() {
|
|
33
|
-
return mockPlatform || {
|
|
34
|
-
chrome: 120
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
global.ResizeObserver = /*#__PURE__*/function () {
|
|
40
|
-
function ResizeObserver() {
|
|
41
|
-
_classCallCheck(this, ResizeObserver);
|
|
42
|
-
}
|
|
43
|
-
return _createClass(ResizeObserver, [{
|
|
44
|
-
key: "observe",
|
|
45
|
-
value: function observe() {}
|
|
46
|
-
}, {
|
|
47
|
-
key: "unobserve",
|
|
48
|
-
value: function unobserve() {}
|
|
49
|
-
}, {
|
|
50
|
-
key: "disconnect",
|
|
51
|
-
value: function disconnect() {}
|
|
52
|
-
}]);
|
|
53
|
-
}();
|
|
54
|
-
|
|
55
|
-
// Import AFTER all mocks
|
|
56
|
-
|
|
57
|
-
// Helper function to create complete mock refs
|
|
58
|
-
function createMockRefs() {
|
|
59
|
-
return {
|
|
60
|
-
scrollContentHandle: {
|
|
61
|
-
current: {
|
|
62
|
-
getScrollBounds: jest.fn(function () {
|
|
63
|
-
return {
|
|
64
|
-
clientWidth: 1920,
|
|
65
|
-
clientHeight: 1080,
|
|
66
|
-
scrollWidth: 1000,
|
|
67
|
-
scrollHeight: 800,
|
|
68
|
-
maxTop: 200,
|
|
69
|
-
maxLeft: 200
|
|
70
|
-
};
|
|
71
|
-
}),
|
|
72
|
-
getMoreInfo: jest.fn(function () {
|
|
73
|
-
return {};
|
|
74
|
-
}),
|
|
75
|
-
hasDataSizeChanged: false,
|
|
76
|
-
syncClientSize: jest.fn(function () {
|
|
77
|
-
return false;
|
|
78
|
-
}),
|
|
79
|
-
getRtlPositionX: jest.fn(function (x) {
|
|
80
|
-
return x;
|
|
81
|
-
}),
|
|
82
|
-
calculateMetrics: jest.fn(),
|
|
83
|
-
props: {}
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
scrollContainerRef: {
|
|
87
|
-
current: document.createElement('div')
|
|
88
|
-
},
|
|
89
|
-
scrollContentRef: {
|
|
90
|
-
current: document.createElement('div')
|
|
91
|
-
},
|
|
92
|
-
horizontalScrollbarHandle: {
|
|
93
|
-
current: {
|
|
94
|
-
update: jest.fn(),
|
|
95
|
-
getContainerRef: jest.fn(function () {
|
|
96
|
-
return document.createElement('div');
|
|
97
|
-
}),
|
|
98
|
-
startHidingScrollbarTrack: jest.fn()
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
verticalScrollbarHandle: {
|
|
102
|
-
current: {
|
|
103
|
-
update: jest.fn(),
|
|
104
|
-
getContainerRef: jest.fn(function () {
|
|
105
|
-
return document.createElement('div');
|
|
106
|
-
}),
|
|
107
|
-
startHidingScrollbarTrack: jest.fn()
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
4
|
describe('useScroll', function () {
|
|
113
|
-
describe('riRatio itemSize scaling on window resize', function () {
|
|
114
|
-
beforeEach(function () {
|
|
115
|
-
jest.useFakeTimers();
|
|
116
|
-
mockPlatform = {
|
|
117
|
-
chrome: 132
|
|
118
|
-
};
|
|
119
|
-
});
|
|
120
|
-
afterEach(function () {
|
|
121
|
-
jest.runOnlyPendingTimers();
|
|
122
|
-
jest.useRealTimers();
|
|
123
|
-
});
|
|
124
|
-
test('should scale itemSize when ri.scale(1) changes from 1 to 2', function () {
|
|
125
|
-
mockRiScale = jest.fn(function (val) {
|
|
126
|
-
return val;
|
|
127
|
-
});
|
|
128
|
-
var itemSize = {
|
|
129
|
-
minWidth: 100,
|
|
130
|
-
minHeight: 50
|
|
131
|
-
};
|
|
132
|
-
var mocks = createMockRefs();
|
|
133
|
-
var props = _objectSpread(_objectSpread({
|
|
134
|
-
itemRenderer: jest.fn(),
|
|
135
|
-
itemSize: itemSize,
|
|
136
|
-
direction: 'vertical',
|
|
137
|
-
scrollMode: 'translate'
|
|
138
|
-
}, mocks), {}, {
|
|
139
|
-
assignProperties: jest.fn(),
|
|
140
|
-
horizontalScrollbar: 'auto',
|
|
141
|
-
verticalScrollbar: 'auto'
|
|
142
|
-
});
|
|
143
|
-
(0, _react.renderHook)(function () {
|
|
144
|
-
return (0, _useScroll.useScrollBase)(props);
|
|
145
|
-
});
|
|
146
|
-
mockRiScale = jest.fn(function () {
|
|
147
|
-
return 2;
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
151
|
-
(0, _react.act)(function () {
|
|
152
|
-
(0, _react.fireEvent)(window, new Event('resize'));
|
|
153
|
-
jest.runAllTimers();
|
|
154
|
-
});
|
|
155
|
-
expect(itemSize.minWidth).toBe(200);
|
|
156
|
-
expect(itemSize.minHeight).toBe(100);
|
|
157
|
-
});
|
|
158
|
-
test('should NOT scale when ri.scale(1) remains unchanged', function () {
|
|
159
|
-
mockRiScale = jest.fn(function (val) {
|
|
160
|
-
return val;
|
|
161
|
-
});
|
|
162
|
-
var itemSize = {
|
|
163
|
-
minWidth: 100,
|
|
164
|
-
minHeight: 50
|
|
165
|
-
};
|
|
166
|
-
var mocks = createMockRefs();
|
|
167
|
-
var props = _objectSpread(_objectSpread({
|
|
168
|
-
itemRenderer: jest.fn(),
|
|
169
|
-
itemSize: itemSize,
|
|
170
|
-
direction: 'vertical',
|
|
171
|
-
scrollMode: 'translate'
|
|
172
|
-
}, mocks), {}, {
|
|
173
|
-
assignProperties: jest.fn(),
|
|
174
|
-
horizontalScrollbar: 'auto',
|
|
175
|
-
verticalScrollbar: 'auto'
|
|
176
|
-
});
|
|
177
|
-
(0, _react.renderHook)(function () {
|
|
178
|
-
return (0, _useScroll.useScrollBase)(props);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
182
|
-
(0, _react.act)(function () {
|
|
183
|
-
(0, _react.fireEvent)(window, new Event('resize'));
|
|
184
|
-
jest.runAllTimers();
|
|
185
|
-
});
|
|
186
|
-
expect(itemSize.minWidth).toBe(100);
|
|
187
|
-
expect(itemSize.minHeight).toBe(50);
|
|
188
|
-
});
|
|
189
|
-
test('should NOT scale when minWidth is missing', function () {
|
|
190
|
-
mockRiScale = jest.fn(function (val) {
|
|
191
|
-
return val;
|
|
192
|
-
});
|
|
193
|
-
var itemSize = {
|
|
194
|
-
minHeight: 50
|
|
195
|
-
};
|
|
196
|
-
var mocks = createMockRefs();
|
|
197
|
-
var props = _objectSpread(_objectSpread({
|
|
198
|
-
itemRenderer: jest.fn(),
|
|
199
|
-
itemSize: itemSize,
|
|
200
|
-
direction: 'vertical',
|
|
201
|
-
scrollMode: 'translate'
|
|
202
|
-
}, mocks), {}, {
|
|
203
|
-
assignProperties: jest.fn(),
|
|
204
|
-
horizontalScrollbar: 'auto',
|
|
205
|
-
verticalScrollbar: 'auto'
|
|
206
|
-
});
|
|
207
|
-
(0, _react.renderHook)(function () {
|
|
208
|
-
return (0, _useScroll.useScrollBase)(props);
|
|
209
|
-
});
|
|
210
|
-
mockRiScale = jest.fn(function () {
|
|
211
|
-
return 2;
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
215
|
-
(0, _react.act)(function () {
|
|
216
|
-
(0, _react.fireEvent)(window, new Event('resize'));
|
|
217
|
-
jest.runAllTimers();
|
|
218
|
-
});
|
|
219
|
-
expect(itemSize.minHeight).toBe(50);
|
|
220
|
-
expect(itemSize.minWidth).toBeUndefined();
|
|
221
|
-
});
|
|
222
|
-
test('should NOT scale when minHeight is missing', function () {
|
|
223
|
-
mockRiScale = jest.fn(function (val) {
|
|
224
|
-
return val;
|
|
225
|
-
});
|
|
226
|
-
var itemSize = {
|
|
227
|
-
minWidth: 100
|
|
228
|
-
};
|
|
229
|
-
var mocks = createMockRefs();
|
|
230
|
-
var props = _objectSpread(_objectSpread({
|
|
231
|
-
itemRenderer: jest.fn(),
|
|
232
|
-
itemSize: itemSize,
|
|
233
|
-
direction: 'vertical',
|
|
234
|
-
scrollMode: 'translate'
|
|
235
|
-
}, mocks), {}, {
|
|
236
|
-
assignProperties: jest.fn(),
|
|
237
|
-
horizontalScrollbar: 'auto',
|
|
238
|
-
verticalScrollbar: 'auto'
|
|
239
|
-
});
|
|
240
|
-
(0, _react.renderHook)(function () {
|
|
241
|
-
return (0, _useScroll.useScrollBase)(props);
|
|
242
|
-
});
|
|
243
|
-
mockRiScale = jest.fn(function () {
|
|
244
|
-
return 2;
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
248
|
-
(0, _react.act)(function () {
|
|
249
|
-
(0, _react.fireEvent)(window, new Event('resize'));
|
|
250
|
-
jest.runAllTimers();
|
|
251
|
-
});
|
|
252
|
-
expect(itemSize.minWidth).toBe(100);
|
|
253
|
-
expect(itemSize.minHeight).toBeUndefined();
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
5
|
describe('Rounding target scroll position', function () {
|
|
257
6
|
beforeEach(function () {
|
|
258
7
|
jest.resetModules(); // important! clears cached modules
|
|
259
8
|
});
|
|
260
9
|
test('should round target position upwards when target is bigger than current position', function () {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
10
|
+
jest.doMock('@enact/core/platform', function () {
|
|
11
|
+
return {
|
|
12
|
+
__esModule: true,
|
|
13
|
+
platform: {
|
|
14
|
+
chrome: 132
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
});
|
|
264
18
|
var _require = require('../useScroll'),
|
|
265
19
|
roundTarget = _require.roundTarget;
|
|
266
20
|
var currentPosition = {
|
|
@@ -275,10 +29,15 @@ describe('useScroll', function () {
|
|
|
275
29
|
expect(roundedTargetX).toEqual(121);
|
|
276
30
|
expect(roundedTargetY).toEqual(121);
|
|
277
31
|
});
|
|
278
|
-
test('should round target position downwards when target is
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
32
|
+
test('should round target position downwards when target is bigger than current position', function () {
|
|
33
|
+
jest.doMock('@enact/core/platform', function () {
|
|
34
|
+
return {
|
|
35
|
+
__esModule: true,
|
|
36
|
+
platform: {
|
|
37
|
+
chrome: 132
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
});
|
|
282
41
|
var _require2 = require('../useScroll'),
|
|
283
42
|
roundTarget = _require2.roundTarget;
|
|
284
43
|
var currentPosition = {
|
|
@@ -294,9 +53,14 @@ describe('useScroll', function () {
|
|
|
294
53
|
expect(roundedTargetY).toEqual(80);
|
|
295
54
|
});
|
|
296
55
|
test('should not round target position when chrome <= 120', function () {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
56
|
+
jest.doMock('@enact/core/platform', function () {
|
|
57
|
+
return {
|
|
58
|
+
__esModule: true,
|
|
59
|
+
platform: {
|
|
60
|
+
chrome: 119
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
});
|
|
300
64
|
var _require3 = require('../useScroll'),
|
|
301
65
|
roundTarget = _require3.roundTarget;
|
|
302
66
|
var currentPosition = {
|
package/useScroll/useScroll.js
CHANGED
|
@@ -207,10 +207,6 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
|
|
|
207
207
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
208
208
|
isVerticalScrollbarVisible = _useState4[0],
|
|
209
209
|
setIsVerticalScrollbarVisible = _useState4[1];
|
|
210
|
-
var _useState5 = (0, _react.useState)(_resolution["default"].scale(1)),
|
|
211
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
212
|
-
riRatio = _useState6[0],
|
|
213
|
-
setRiRatio = _useState6[1];
|
|
214
210
|
var mutableRef = (0, _react.useRef)({
|
|
215
211
|
overscrollEnabled: !!props.applyOverscrollEffect,
|
|
216
212
|
// Enable the early bail out of repeated scrolling to the same position
|
|
@@ -437,31 +433,8 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
|
|
|
437
433
|
}, [forceUpdate, scrollContentHandle]);
|
|
438
434
|
// scrollMode 'translate' ]]
|
|
439
435
|
|
|
440
|
-
var scrollContentProps = props.itemRenderer ?
|
|
441
|
-
// If the child component is a VirtualList
|
|
442
|
-
{
|
|
443
|
-
childProps: childProps,
|
|
444
|
-
clientSize: clientSize,
|
|
445
|
-
dataSize: dataSize,
|
|
446
|
-
itemRenderer: itemRenderer,
|
|
447
|
-
itemSize: itemSize,
|
|
448
|
-
itemSizes: itemSizes,
|
|
449
|
-
overhang: overhang,
|
|
450
|
-
pageScroll: pageScroll,
|
|
451
|
-
spacing: spacing,
|
|
452
|
-
wrap: wrap
|
|
453
|
-
} : {
|
|
454
|
-
children: children
|
|
455
|
-
};
|
|
456
436
|
function handleResizeWindow() {
|
|
457
437
|
var propsHandleResizeWindow = props.handleResizeWindow;
|
|
458
|
-
if (_resolution["default"].scale(1) !== riRatio) {
|
|
459
|
-
if (scrollContentProps.itemSize.minWidth && scrollContentProps.itemSize.minHeight) {
|
|
460
|
-
scrollContentProps.itemSize.minWidth *= _resolution["default"].scale(1) / riRatio;
|
|
461
|
-
scrollContentProps.itemSize.minHeight *= _resolution["default"].scale(1) / riRatio;
|
|
462
|
-
setRiRatio(_resolution["default"].scale(1));
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
438
|
|
|
466
439
|
// `handleSize` in `ui/resolution.ResolutionDecorator` should be executed first.
|
|
467
440
|
setTimeout(function () {
|
|
@@ -1539,6 +1512,22 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
|
|
|
1539
1512
|
onFlick: onFlick,
|
|
1540
1513
|
onTouchStart: scrollMode === 'native' ? onTouchStart : null // scrollMode 'native'
|
|
1541
1514
|
}));
|
|
1515
|
+
var scrollContentProps = props.itemRenderer ?
|
|
1516
|
+
// If the child component is a VirtualList
|
|
1517
|
+
{
|
|
1518
|
+
childProps: childProps,
|
|
1519
|
+
clientSize: clientSize,
|
|
1520
|
+
dataSize: dataSize,
|
|
1521
|
+
itemRenderer: itemRenderer,
|
|
1522
|
+
itemSize: itemSize,
|
|
1523
|
+
itemSizes: itemSizes,
|
|
1524
|
+
overhang: overhang,
|
|
1525
|
+
pageScroll: pageScroll,
|
|
1526
|
+
spacing: spacing,
|
|
1527
|
+
wrap: wrap
|
|
1528
|
+
} : {
|
|
1529
|
+
children: children
|
|
1530
|
+
};
|
|
1542
1531
|
assignProperties('scrollContentProps', _objectSpread(_objectSpread({}, scrollContentProps), {}, {
|
|
1543
1532
|
cbScrollTo: scrollTo,
|
|
1544
1533
|
className: [_useScrollModule["default"].scrollFill],
|