@enact/ui 5.5.0 → 5.5.2
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 +26 -0
- package/Scroller/Scroller.d.ts +2 -2
- package/Scroller/ScrollerBasic.js +33 -14
- package/Scroller/tests/ScrollerBasic-specs.js +187 -14
- package/Transition/Transition.js +207 -190
- package/Transition/Transition.module.css +0 -5
- package/Transition/tests/Transition-specs.js +220 -0
- package/VirtualList/VirtualListBasic.js +119 -26
- package/VirtualList/tests/VirtualList-native-specs.js +219 -3
- package/package.json +7 -12
- package/resolution/ResolutionDecorator.js +2 -1
- package/resolution/index.d.ts +6 -4
- package/resolution/resolution.js +63 -35
- package/resolution/tests/resolution-specs.js +35 -7
- package/useScroll/tests/useScroll-specs.js +175 -6
- package/useScroll/useScroll.js +28 -12
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
4
|
var _react = require("@testing-library/react");
|
|
5
|
+
var _Resizable = require("../../Resizable");
|
|
5
6
|
var _Transition = _interopRequireWildcard(require("../Transition"));
|
|
6
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
8
|
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); }
|
|
@@ -172,4 +173,223 @@ describe('Transition Specs', function () {
|
|
|
172
173
|
});
|
|
173
174
|
});
|
|
174
175
|
});
|
|
176
|
+
|
|
177
|
+
// type="clip"
|
|
178
|
+
test('should set inner width when type="clip" and direction="right"', function () {
|
|
179
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition.TransitionBase, {
|
|
180
|
+
clipWidth: 100,
|
|
181
|
+
"data-testid": "transition",
|
|
182
|
+
direction: "right",
|
|
183
|
+
type: "clip",
|
|
184
|
+
children: "Body"
|
|
185
|
+
}));
|
|
186
|
+
var expected = {
|
|
187
|
+
width: '100px'
|
|
188
|
+
};
|
|
189
|
+
var actual = _react.screen.getByText('Body');
|
|
190
|
+
expect(actual).toHaveStyle(expected);
|
|
191
|
+
});
|
|
192
|
+
test('should apply overflow hidden on root when type="clip"', function () {
|
|
193
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition.TransitionBase, {
|
|
194
|
+
clipWidth: 100,
|
|
195
|
+
"data-testid": "transition",
|
|
196
|
+
direction: "right",
|
|
197
|
+
type: "clip",
|
|
198
|
+
children: "Body"
|
|
199
|
+
}));
|
|
200
|
+
var expected = {
|
|
201
|
+
overflow: 'hidden'
|
|
202
|
+
};
|
|
203
|
+
var actual = _react.screen.getByTestId('transition');
|
|
204
|
+
expect(actual).toHaveStyle(expected);
|
|
205
|
+
});
|
|
206
|
+
test('should set height on root when type="clip", direction="up", and visible', function () {
|
|
207
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition.TransitionBase, {
|
|
208
|
+
clipHeight: 50,
|
|
209
|
+
"data-testid": "transition",
|
|
210
|
+
direction: "up",
|
|
211
|
+
type: "clip",
|
|
212
|
+
children: "Body"
|
|
213
|
+
}));
|
|
214
|
+
var expected = {
|
|
215
|
+
height: '50px'
|
|
216
|
+
};
|
|
217
|
+
var actual = _react.screen.getByTestId('transition');
|
|
218
|
+
expect(actual).toHaveStyle(expected);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Custom duration paths.
|
|
222
|
+
test('should set transitionDuration on inner style for a custom duration', function () {
|
|
223
|
+
var actual = _Transition.TransitionBase.computed.innerStyle({
|
|
224
|
+
css: {},
|
|
225
|
+
duration: 200,
|
|
226
|
+
type: 'slide'
|
|
227
|
+
});
|
|
228
|
+
var expected = {
|
|
229
|
+
transitionDuration: '200ms'
|
|
230
|
+
};
|
|
231
|
+
expect(actual).toEqual(expected);
|
|
232
|
+
});
|
|
233
|
+
test('should set transitionDuration on style for type="clip" with a custom duration', function () {
|
|
234
|
+
var actual = _Transition.TransitionBase.computed.style({
|
|
235
|
+
clipHeight: 10,
|
|
236
|
+
css: {},
|
|
237
|
+
direction: 'up',
|
|
238
|
+
duration: '3s',
|
|
239
|
+
type: 'clip',
|
|
240
|
+
visible: true
|
|
241
|
+
});
|
|
242
|
+
var expected = {
|
|
243
|
+
height: 10,
|
|
244
|
+
overflow: 'hidden',
|
|
245
|
+
transitionDuration: '3s'
|
|
246
|
+
};
|
|
247
|
+
expect(actual).toMatchObject(expected);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// transitionend handling
|
|
251
|
+
test('should fire \'onShow\' on transitionend when visible', function () {
|
|
252
|
+
var handleShow = jest.fn();
|
|
253
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
254
|
+
onShow: handleShow,
|
|
255
|
+
visible: true,
|
|
256
|
+
children: "Body"
|
|
257
|
+
}));
|
|
258
|
+
_react.fireEvent.transitionEnd(_react.screen.getByText('Body'));
|
|
259
|
+
var expected = 1;
|
|
260
|
+
expect(handleShow).toHaveBeenCalledTimes(expected);
|
|
261
|
+
});
|
|
262
|
+
test('should fire \'onHide\' on transitionend when not visible', function () {
|
|
263
|
+
var handleHide = jest.fn();
|
|
264
|
+
var _render3 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
265
|
+
onHide: handleHide,
|
|
266
|
+
visible: true,
|
|
267
|
+
children: "Body"
|
|
268
|
+
})),
|
|
269
|
+
rerender = _render3.rerender;
|
|
270
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
271
|
+
onHide: handleHide,
|
|
272
|
+
visible: false,
|
|
273
|
+
children: "Body"
|
|
274
|
+
}));
|
|
275
|
+
_react.fireEvent.transitionEnd(_react.screen.getByText('Body'));
|
|
276
|
+
var expected = 1;
|
|
277
|
+
expect(handleHide).toHaveBeenCalledTimes(expected);
|
|
278
|
+
});
|
|
279
|
+
test('should forward \'onTransitionEnd\'', function () {
|
|
280
|
+
var handleTransitionEnd = jest.fn();
|
|
281
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
282
|
+
onTransitionEnd: handleTransitionEnd,
|
|
283
|
+
visible: true,
|
|
284
|
+
children: "Body"
|
|
285
|
+
}));
|
|
286
|
+
_react.fireEvent.transitionEnd(_react.screen.getByText('Body'));
|
|
287
|
+
var expected = 1;
|
|
288
|
+
expect(handleTransitionEnd).toHaveBeenCalledTimes(expected);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// The main accordion/header path: animated clip transition driven by `transitionend`
|
|
292
|
+
// across a full show → hide → show cycle
|
|
293
|
+
test('should fire \'onHide\' then \'onShow\' over a visible true → false → true cycle with type="clip"', function () {
|
|
294
|
+
var handleHide = jest.fn();
|
|
295
|
+
var handleShow = jest.fn();
|
|
296
|
+
var _render4 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
297
|
+
direction: "up",
|
|
298
|
+
onHide: handleHide,
|
|
299
|
+
onShow: handleShow,
|
|
300
|
+
type: "clip",
|
|
301
|
+
visible: true,
|
|
302
|
+
children: "Body"
|
|
303
|
+
})),
|
|
304
|
+
rerender = _render4.rerender;
|
|
305
|
+
|
|
306
|
+
// true → false: the hide animation runs and completes.
|
|
307
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
308
|
+
direction: "up",
|
|
309
|
+
onHide: handleHide,
|
|
310
|
+
onShow: handleShow,
|
|
311
|
+
type: "clip",
|
|
312
|
+
visible: false,
|
|
313
|
+
children: "Body"
|
|
314
|
+
}));
|
|
315
|
+
_react.fireEvent.transitionEnd(_react.screen.getByText('Body'));
|
|
316
|
+
expect(handleHide).toHaveBeenCalledTimes(1);
|
|
317
|
+
expect(handleShow).not.toHaveBeenCalled();
|
|
318
|
+
|
|
319
|
+
// false → true: the show animation runs and completes.
|
|
320
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
321
|
+
direction: "up",
|
|
322
|
+
onHide: handleHide,
|
|
323
|
+
onShow: handleShow,
|
|
324
|
+
type: "clip",
|
|
325
|
+
visible: true,
|
|
326
|
+
children: "Body"
|
|
327
|
+
}));
|
|
328
|
+
_react.fireEvent.transitionEnd(_react.screen.getByText('Body'));
|
|
329
|
+
expect(handleShow).toHaveBeenCalledTimes(1);
|
|
330
|
+
expect(handleHide).toHaveBeenCalledTimes(1);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// ResizeContext registration
|
|
334
|
+
test('should register with ResizeContext and unregister on unmount', function () {
|
|
335
|
+
var unregister = jest.fn();
|
|
336
|
+
var register = jest.fn(function () {
|
|
337
|
+
return {
|
|
338
|
+
unregister: unregister
|
|
339
|
+
};
|
|
340
|
+
});
|
|
341
|
+
var _render5 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Resizable.ResizeContext.Provider, {
|
|
342
|
+
value: register,
|
|
343
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
344
|
+
visible: true,
|
|
345
|
+
children: "Body"
|
|
346
|
+
})
|
|
347
|
+
})),
|
|
348
|
+
unmount = _render5.unmount;
|
|
349
|
+
expect(register).toHaveBeenCalled();
|
|
350
|
+
unmount();
|
|
351
|
+
expect(unregister).toHaveBeenCalled();
|
|
352
|
+
});
|
|
353
|
+
test('should re-measure when notified through ResizeContext', function () {
|
|
354
|
+
var resizeHandler;
|
|
355
|
+
var register = jest.fn(function (handler) {
|
|
356
|
+
resizeHandler = handler;
|
|
357
|
+
return {
|
|
358
|
+
unregister: jest.fn()
|
|
359
|
+
};
|
|
360
|
+
});
|
|
361
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Resizable.ResizeContext.Provider, {
|
|
362
|
+
value: register,
|
|
363
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
364
|
+
visible: true,
|
|
365
|
+
children: "Body"
|
|
366
|
+
})
|
|
367
|
+
}));
|
|
368
|
+
|
|
369
|
+
// Invoking the registered handler nulls the cached measurement and triggers a re-measure on the next layout commit.
|
|
370
|
+
(0, _react.act)(function () {
|
|
371
|
+
resizeHandler();
|
|
372
|
+
});
|
|
373
|
+
expect(register).toHaveBeenCalled();
|
|
374
|
+
});
|
|
375
|
+
test('should defer rendering then pre-measure when mounted with visible={false}', function () {
|
|
376
|
+
jest.useFakeTimers();
|
|
377
|
+
try {
|
|
378
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
|
|
379
|
+
visible: false,
|
|
380
|
+
children: "Body"
|
|
381
|
+
}));
|
|
382
|
+
|
|
383
|
+
// INIT state — children are not rendered yet.
|
|
384
|
+
expect(_react.screen.queryByText('Body')).toBeNull();
|
|
385
|
+
|
|
386
|
+
// The idle Job moves the state to MEASURE, rendering the (hidden) children so they can be measured.
|
|
387
|
+
(0, _react.act)(function () {
|
|
388
|
+
jest.runOnlyPendingTimers();
|
|
389
|
+
});
|
|
390
|
+
expect(_react.screen.getByText('Body')).toBeInTheDocument();
|
|
391
|
+
} finally {
|
|
392
|
+
jest.useRealTimers();
|
|
393
|
+
}
|
|
394
|
+
});
|
|
175
395
|
});
|
|
@@ -18,6 +18,7 @@ var _excluded = ["className", "containerProps", "placeholderRenderer", "role", "
|
|
|
18
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
19
19
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
20
20
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
21
|
+
function _readOnlyError(r) { throw new TypeError('"' + r + '" is read-only'); }
|
|
21
22
|
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
22
23
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
23
24
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -404,10 +405,15 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
404
405
|
this.itemMarginLeft = Number(firstItemStyle.getPropertyValue('margin-left').slice(0, -2));
|
|
405
406
|
this.itemMarginRight = Number(firstItemStyle.getPropertyValue('margin-right').slice(0, -2));
|
|
406
407
|
if (this.isPrimaryDirectionVertical) {
|
|
407
|
-
|
|
408
|
+
var marginSum = this.itemMarginTop + this.itemMarginBottom;
|
|
409
|
+
this.scrollBounds.scrollHeight += marginSum;
|
|
410
|
+
this.scrollBounds.maxTop += marginSum;
|
|
408
411
|
} else {
|
|
409
|
-
|
|
412
|
+
var _marginSum = this.itemMarginLeft + this.itemMarginRight;
|
|
413
|
+
this.scrollBounds.scrollWidth += _marginSum;
|
|
414
|
+
this.scrollBounds.maxLeft += _marginSum;
|
|
410
415
|
}
|
|
416
|
+
this.setContainerSize();
|
|
411
417
|
}
|
|
412
418
|
var deferScrollTo = false;
|
|
413
419
|
var _this$state = this.state,
|
|
@@ -782,8 +788,31 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
782
788
|
value:
|
|
783
789
|
// scrollMode 'native' only
|
|
784
790
|
function scrollToPosition(left, top, behavior) {
|
|
785
|
-
|
|
786
|
-
|
|
791
|
+
var _this$props3 = this.props,
|
|
792
|
+
dataSize = _this$props3.dataSize,
|
|
793
|
+
scrollContentRef = _this$props3.scrollContentRef;
|
|
794
|
+
var node = scrollContentRef.current;
|
|
795
|
+
if (!node) return;
|
|
796
|
+
var _this$scrollBounds3 = this.scrollBounds,
|
|
797
|
+
clientWidth = _this$scrollBounds3.clientWidth,
|
|
798
|
+
clientHeight = _this$scrollBounds3.clientHeight,
|
|
799
|
+
scrollWidth = _this$scrollBounds3.scrollWidth,
|
|
800
|
+
scrollHeight = _this$scrollBounds3.scrollHeight;
|
|
801
|
+
var _this$moreInfo = this.moreInfo,
|
|
802
|
+
firstVisibleIndex = _this$moreInfo.firstVisibleIndex,
|
|
803
|
+
lastVisibleIndex = _this$moreInfo.lastVisibleIndex;
|
|
804
|
+
var scrollSize = this.isPrimaryDirectionVertical ? top >= scrollHeight - clientHeight : left >= scrollWidth - clientWidth;
|
|
805
|
+
var isTargetStart = this.isPrimaryDirectionVertical ? top === 0 : left === 0;
|
|
806
|
+
var isScrollWrap = lastVisibleIndex === dataSize - 1 && isTargetStart || firstVisibleIndex === 0 && scrollSize;
|
|
807
|
+
var isScrollByPageKey = node.lastInputType === 'pageKey';
|
|
808
|
+
var isSmoothBehavior = behavior === 'smooth';
|
|
809
|
+
if (_platform.platform.chrome && isSmoothBehavior && !isScrollByPageKey && !isScrollWrap) {
|
|
810
|
+
this.animateScroll(this.getRtlPositionX(left), top, node);
|
|
811
|
+
} else if (node.scrollTo) {
|
|
812
|
+
if (this.scrollAnimationId) {
|
|
813
|
+
this.cancelScrollAnimation();
|
|
814
|
+
}
|
|
815
|
+
node.scrollTo({
|
|
787
816
|
left: this.getRtlPositionX(left),
|
|
788
817
|
top: top,
|
|
789
818
|
behavior: behavior
|
|
@@ -791,6 +820,70 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
791
820
|
}
|
|
792
821
|
}
|
|
793
822
|
|
|
823
|
+
// scroll mode 'native' only
|
|
824
|
+
}, {
|
|
825
|
+
key: "animateScroll",
|
|
826
|
+
value: function _animateScroll(left, top, node) {
|
|
827
|
+
var _this8 = this;
|
|
828
|
+
// Determine the direction of scroll (1 for forward/down, -1 for backward/up, 0 for no movement)
|
|
829
|
+
var directionX = Math.sign(left - node.scrollLeft);
|
|
830
|
+
var directionY = Math.sign(top - node.scrollTop);
|
|
831
|
+
|
|
832
|
+
// Calculate an adaptive scroll factor (pixels per frame).
|
|
833
|
+
// It uses the average item size (gridSize) to ensure the speed feels consistent.
|
|
834
|
+
var scrollFactor = Math.max(this.primary.gridSize / 12, 2);
|
|
835
|
+
var startTime = performance.now();
|
|
836
|
+
|
|
837
|
+
// Progressively scrolls the node toward a target position using requestAnimationFrame.
|
|
838
|
+
// It applies an incremental scroll on each frame and cancels the animation once
|
|
839
|
+
// the target is reached or the duration (500ms) is exceeded, falling back to
|
|
840
|
+
// a smooth scroll if the timeout occurs first.
|
|
841
|
+
var _animateScroll = function animateScroll(currentTime) {
|
|
842
|
+
var elapsed = (currentTime - startTime) / 500;
|
|
843
|
+
|
|
844
|
+
// Clamp each step to the remaining distance so the final frame lands exactly on the target
|
|
845
|
+
// instead of overshooting by up to `scrollFactor`. Overshooting would push a focused item
|
|
846
|
+
// anchored to the start edge (e.g. `stickTo="start"`) past that edge and clip it.
|
|
847
|
+
var stepX = directionX === 0 ? 0 : directionX * Math.min(scrollFactor, Math.abs(left - node.scrollLeft));
|
|
848
|
+
var stepY = directionY === 0 ? 0 : directionY * Math.min(scrollFactor, Math.abs(top - node.scrollTop));
|
|
849
|
+
node.scrollBy({
|
|
850
|
+
top: stepY,
|
|
851
|
+
left: stepX,
|
|
852
|
+
behavior: 'instant'
|
|
853
|
+
});
|
|
854
|
+
_this8.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
|
|
855
|
+
_this8.scrolling = true;
|
|
856
|
+
var scrollHorizontally = directionX > 0 ? node.scrollLeft < left : node.scrollLeft > left;
|
|
857
|
+
var scrollVertically = directionY > 0 ? node.scrollTop < top : node.scrollTop > top;
|
|
858
|
+
var targetReached = node.scrollLeft === left && node.scrollTop === top;
|
|
859
|
+
|
|
860
|
+
// Check if we've reached the needed scroll position
|
|
861
|
+
// or the elapsed time since startTime is longer than 0.5s and cancel the animation
|
|
862
|
+
if (!scrollHorizontally && !scrollVertically || elapsed > 1) {
|
|
863
|
+
_this8.cancelScrollAnimation();
|
|
864
|
+
|
|
865
|
+
// Fallback: if time is out before reaching the target, jump there with smooth scroll
|
|
866
|
+
if (elapsed > 1 && !targetReached) {
|
|
867
|
+
node.scrollTo({
|
|
868
|
+
top: top,
|
|
869
|
+
left: left,
|
|
870
|
+
behavior: 'smooth'
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
this.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// scrollMode 'native' only
|
|
879
|
+
}, {
|
|
880
|
+
key: "cancelScrollAnimation",
|
|
881
|
+
value: function cancelScrollAnimation() {
|
|
882
|
+
window.cancelAnimationFrame(this.scrollAnimationId);
|
|
883
|
+
this.scrollAnimationId = null;
|
|
884
|
+
this.scrolling = false;
|
|
885
|
+
}
|
|
886
|
+
|
|
794
887
|
// scrollMode 'native' only
|
|
795
888
|
}, {
|
|
796
889
|
key: "setScrollToPositionTarget",
|
|
@@ -829,10 +922,10 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
829
922
|
}, {
|
|
830
923
|
key: "didScroll",
|
|
831
924
|
value: function didScroll(x, y) {
|
|
832
|
-
var _this$
|
|
833
|
-
dataSize = _this$
|
|
834
|
-
spacing = _this$
|
|
835
|
-
itemSizes = _this$
|
|
925
|
+
var _this$props4 = this.props,
|
|
926
|
+
dataSize = _this$props4.dataSize,
|
|
927
|
+
spacing = _this$props4.spacing,
|
|
928
|
+
itemSizes = _this$props4.itemSizes,
|
|
836
929
|
firstIndex = this.state.firstIndex,
|
|
837
930
|
isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
|
|
838
931
|
threshold = this.threshold,
|
|
@@ -929,9 +1022,9 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
929
1022
|
}, {
|
|
930
1023
|
key: "applyItemPositionToDOMElement",
|
|
931
1024
|
value: function applyItemPositionToDOMElement(index) {
|
|
932
|
-
var _this$
|
|
933
|
-
direction = _this$
|
|
934
|
-
rtl = _this$
|
|
1025
|
+
var _this$props5 = this.props,
|
|
1026
|
+
direction = _this$props5.direction,
|
|
1027
|
+
rtl = _this$props5.rtl,
|
|
935
1028
|
numOfItems = this.state.numOfItems,
|
|
936
1029
|
itemPositions = this.itemPositions,
|
|
937
1030
|
childNode = this.itemContainerRefs[index % numOfItems];
|
|
@@ -961,10 +1054,10 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
961
1054
|
}, {
|
|
962
1055
|
key: "updateScrollBoundsWithItemPositions",
|
|
963
1056
|
value: function updateScrollBoundsWithItemPositions() {
|
|
964
|
-
var _this$
|
|
965
|
-
dataSize = _this$
|
|
966
|
-
itemSizes = _this$
|
|
967
|
-
spacing = _this$
|
|
1057
|
+
var _this$props6 = this.props,
|
|
1058
|
+
dataSize = _this$props6.dataSize,
|
|
1059
|
+
itemSizes = _this$props6.itemSizes,
|
|
1060
|
+
spacing = _this$props6.spacing,
|
|
968
1061
|
_this$state4 = this.state,
|
|
969
1062
|
firstIndex = _this$state4.firstIndex,
|
|
970
1063
|
numOfItems = _this$state4.numOfItems,
|
|
@@ -1041,9 +1134,9 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
1041
1134
|
}, {
|
|
1042
1135
|
key: "positionItems",
|
|
1043
1136
|
value: function positionItems() {
|
|
1044
|
-
var _this$
|
|
1045
|
-
dataSize = _this$
|
|
1046
|
-
itemSizes = _this$
|
|
1137
|
+
var _this$props7 = this.props,
|
|
1138
|
+
dataSize = _this$props7.dataSize,
|
|
1139
|
+
itemSizes = _this$props7.itemSizes,
|
|
1047
1140
|
_this$state6 = this.state,
|
|
1048
1141
|
firstIndex = _this$state6.firstIndex,
|
|
1049
1142
|
numOfItems = _this$state6.numOfItems,
|
|
@@ -1101,14 +1194,14 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
|
|
|
1101
1194
|
// render
|
|
1102
1195
|
|
|
1103
1196
|
function render() {
|
|
1104
|
-
var _this$
|
|
1105
|
-
className = _this$
|
|
1106
|
-
containerProps = _this$
|
|
1107
|
-
placeholderRenderer = _this$
|
|
1108
|
-
role = _this$
|
|
1109
|
-
style = _this$
|
|
1110
|
-
scrollMode = _this$
|
|
1111
|
-
rest = _objectWithoutProperties(_this$
|
|
1197
|
+
var _this$props8 = this.props,
|
|
1198
|
+
className = _this$props8.className,
|
|
1199
|
+
containerProps = _this$props8.containerProps,
|
|
1200
|
+
placeholderRenderer = _this$props8.placeholderRenderer,
|
|
1201
|
+
role = _this$props8.role,
|
|
1202
|
+
style = _this$props8.style,
|
|
1203
|
+
scrollMode = _this$props8.scrollMode,
|
|
1204
|
+
rest = _objectWithoutProperties(_this$props8, _excluded),
|
|
1112
1205
|
cc = this.cc,
|
|
1113
1206
|
isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
|
|
1114
1207
|
primary = this.primary,
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
4
|
var _react = require("@testing-library/react");
|
|
5
|
-
var
|
|
5
|
+
var _react2 = require("react");
|
|
6
|
+
var _VirtualList = _interopRequireWildcard(require("../VirtualList"));
|
|
6
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
8
|
var _excluded = ["index"],
|
|
8
|
-
_excluded2 = ["index"]
|
|
9
|
-
|
|
9
|
+
_excluded2 = ["index"],
|
|
10
|
+
_excluded3 = ["direction"],
|
|
11
|
+
_excluded4 = ["index"];
|
|
12
|
+
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); }
|
|
10
13
|
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; }
|
|
11
14
|
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; }
|
|
12
15
|
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; }
|
|
@@ -14,6 +17,14 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
14
17
|
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); }
|
|
15
18
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
16
19
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
20
|
+
var mockPlatform = {};
|
|
21
|
+
jest.mock('@enact/core/platform', function () {
|
|
22
|
+
return {
|
|
23
|
+
get platform() {
|
|
24
|
+
return mockPlatform;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
});
|
|
17
28
|
describe('VirtualList with native scrollMode', function () {
|
|
18
29
|
var clientSize, dataSize, items, itemSize, renderItem;
|
|
19
30
|
beforeEach(function () {
|
|
@@ -165,4 +176,209 @@ describe('VirtualList with native scrollMode', function () {
|
|
|
165
176
|
jest.useRealTimers();
|
|
166
177
|
});
|
|
167
178
|
});
|
|
179
|
+
describe('Animating scroll', function () {
|
|
180
|
+
var instance, node, scrollContentRef;
|
|
181
|
+
beforeEach(function () {
|
|
182
|
+
node = {
|
|
183
|
+
scrollTo: jest.fn(),
|
|
184
|
+
scrollBy: jest.fn(),
|
|
185
|
+
scrollLeft: 0,
|
|
186
|
+
scrollTop: 0
|
|
187
|
+
};
|
|
188
|
+
scrollContentRef = {
|
|
189
|
+
current: node
|
|
190
|
+
};
|
|
191
|
+
instance = new _VirtualList.VirtualListBasic({
|
|
192
|
+
scrollContentRef: scrollContentRef,
|
|
193
|
+
clientSize: clientSize,
|
|
194
|
+
itemSize: itemSize,
|
|
195
|
+
itemRenderer: renderItem,
|
|
196
|
+
scrollMode: 'native'
|
|
197
|
+
});
|
|
198
|
+
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(function (cb) {
|
|
199
|
+
instance.rafCallback = cb;
|
|
200
|
+
return 123;
|
|
201
|
+
});
|
|
202
|
+
jest.spyOn(window, 'cancelAnimationFrame').mockImplementation(jest.fn());
|
|
203
|
+
jest.spyOn(performance, 'now').mockReturnValue(0);
|
|
204
|
+
});
|
|
205
|
+
afterEach(function () {
|
|
206
|
+
delete mockPlatform.chrome;
|
|
207
|
+
});
|
|
208
|
+
test('should call native scrollTo when behavior is instant', function () {
|
|
209
|
+
instance.scrollToPosition(0, 300, 'instant');
|
|
210
|
+
expect(node.scrollTo).toHaveBeenCalledWith({
|
|
211
|
+
left: 0,
|
|
212
|
+
top: 300,
|
|
213
|
+
behavior: 'instant'
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
test('should call native scrollTo when NOT on Chrome and behavior is smooth', function () {
|
|
217
|
+
mockPlatform.chrome = false;
|
|
218
|
+
instance.scrollToPosition(0, 300, 'smooth');
|
|
219
|
+
expect(node.scrollTo).toHaveBeenCalledWith({
|
|
220
|
+
left: 0,
|
|
221
|
+
top: 300,
|
|
222
|
+
behavior: 'smooth'
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
test('should call animateScroll when on Chrome and behavior is smooth', function () {
|
|
226
|
+
mockPlatform.chrome = 88;
|
|
227
|
+
instance.animateScroll = jest.fn();
|
|
228
|
+
instance.scrollToPosition(0, 300, 'smooth');
|
|
229
|
+
expect(instance.animateScroll).toHaveBeenCalledWith(0, 300, node);
|
|
230
|
+
});
|
|
231
|
+
test('should cancel animation when content is scrolled by pageKey', function () {
|
|
232
|
+
mockPlatform.chrome = 88;
|
|
233
|
+
instance.scrollToPosition(0, 600, 'smooth');
|
|
234
|
+
node.lastInputType = 'pageKey';
|
|
235
|
+
instance.scrollToPosition(0, 200, 'smooth');
|
|
236
|
+
expect(window.cancelAnimationFrame).toHaveBeenCalled();
|
|
237
|
+
});
|
|
238
|
+
test('should initiate animation loop using requestAnimationFrame', function () {
|
|
239
|
+
instance.animateScroll(0, 300, node);
|
|
240
|
+
expect(window.requestAnimationFrame).toHaveBeenCalled();
|
|
241
|
+
});
|
|
242
|
+
test('should scroll incrementally on each frame', function () {
|
|
243
|
+
instance.animateScroll(0, 300, node);
|
|
244
|
+
instance.rafCallback();
|
|
245
|
+
expect(node.scrollBy).toHaveBeenCalledWith(expect.objectContaining({
|
|
246
|
+
behavior: 'instant'
|
|
247
|
+
}));
|
|
248
|
+
expect(instance.scrolling).toBe(true);
|
|
249
|
+
});
|
|
250
|
+
test('should cancel animation and stop when target is reached', function () {
|
|
251
|
+
node.scrollTop = 300;
|
|
252
|
+
instance.animateScroll(0, 310, node);
|
|
253
|
+
instance.rafCallback(600);
|
|
254
|
+
expect(window.cancelAnimationFrame).toHaveBeenCalled();
|
|
255
|
+
expect(instance.scrolling).toBe(false);
|
|
256
|
+
});
|
|
257
|
+
test('should fallback to smooth scroll if animation exceeds duration (timeout)', function () {
|
|
258
|
+
instance.animateScroll(0, 300, node);
|
|
259
|
+
instance.rafCallback(600);
|
|
260
|
+
node.scrollTop = 250;
|
|
261
|
+
expect(node.scrollTo).toHaveBeenCalledWith({
|
|
262
|
+
left: 0,
|
|
263
|
+
top: 300,
|
|
264
|
+
behavior: 'smooth'
|
|
265
|
+
});
|
|
266
|
+
expect(window.cancelAnimationFrame).toHaveBeenCalled();
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
describe('VirtualListBasic scrollBounds consistency after item margin detection', function () {
|
|
271
|
+
var originalGetComputedStyle;
|
|
272
|
+
var nop = function nop() {};
|
|
273
|
+
function renderVirtualListBasic() {
|
|
274
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
275
|
+
_ref3$direction = _ref3.direction,
|
|
276
|
+
direction = _ref3$direction === void 0 ? 'vertical' : _ref3$direction,
|
|
277
|
+
rest = _objectWithoutProperties(_ref3, _excluded3);
|
|
278
|
+
var scrollContentRef = /*#__PURE__*/(0, _react2.createRef)();
|
|
279
|
+
var itemRefs = /*#__PURE__*/(0, _react2.createRef)();
|
|
280
|
+
itemRefs.current = [];
|
|
281
|
+
var ref = /*#__PURE__*/(0, _react2.createRef)();
|
|
282
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList.VirtualListBasic, _objectSpread({
|
|
283
|
+
clientSize: {
|
|
284
|
+
clientWidth: 1280,
|
|
285
|
+
clientHeight: 720
|
|
286
|
+
},
|
|
287
|
+
dataSize: 100,
|
|
288
|
+
direction: direction,
|
|
289
|
+
getAffordance: function getAffordance() {
|
|
290
|
+
return 0;
|
|
291
|
+
},
|
|
292
|
+
itemRefs: itemRefs,
|
|
293
|
+
itemRenderer: function itemRenderer(_ref4) {
|
|
294
|
+
var index = _ref4.index,
|
|
295
|
+
rest2 = _objectWithoutProperties(_ref4, _excluded4);
|
|
296
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest2), {}, {
|
|
297
|
+
"data-index": index
|
|
298
|
+
}));
|
|
299
|
+
},
|
|
300
|
+
itemSize: 30,
|
|
301
|
+
overhang: 3,
|
|
302
|
+
placeholderRenderer: nop,
|
|
303
|
+
role: "list",
|
|
304
|
+
scrollContentRef: scrollContentRef,
|
|
305
|
+
scrollMode: "native",
|
|
306
|
+
spacing: 0,
|
|
307
|
+
cbScrollTo: nop,
|
|
308
|
+
ref: ref
|
|
309
|
+
}, rest)));
|
|
310
|
+
return {
|
|
311
|
+
ref: ref
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
beforeEach(function () {
|
|
315
|
+
originalGetComputedStyle = window.getComputedStyle;
|
|
316
|
+
});
|
|
317
|
+
afterEach(function () {
|
|
318
|
+
window.getComputedStyle = originalGetComputedStyle;
|
|
319
|
+
});
|
|
320
|
+
test('should increment scrollHeight and maxTop by the same margin sum when vertical item margins are detected, and not re-apply on subsequent updates', function () {
|
|
321
|
+
var _renderVirtualListBas = renderVirtualListBasic(),
|
|
322
|
+
ref = _renderVirtualListBas.ref;
|
|
323
|
+
var instance = ref.current;
|
|
324
|
+
var marginTop = 10;
|
|
325
|
+
var marginBottom = 5;
|
|
326
|
+
window.getComputedStyle = function (el) {
|
|
327
|
+
if (el === instance.props.itemRefs.current[0]) {
|
|
328
|
+
return {
|
|
329
|
+
getPropertyValue: function getPropertyValue(prop) {
|
|
330
|
+
if (prop === 'margin-top') return "".concat(marginTop, "px");
|
|
331
|
+
if (prop === 'margin-bottom') return "".concat(marginBottom, "px");
|
|
332
|
+
if (prop === 'margin-left') return '0px';
|
|
333
|
+
if (prop === 'margin-right') return '0px';
|
|
334
|
+
return '0px';
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
return originalGetComputedStyle(el);
|
|
339
|
+
};
|
|
340
|
+
instance.itemMarginTop = null;
|
|
341
|
+
(0, _react.act)(function () {
|
|
342
|
+
instance.forceUpdate();
|
|
343
|
+
});
|
|
344
|
+
var scrollHeightAfterFirst = instance.scrollBounds.scrollHeight;
|
|
345
|
+
var maxTopAfterFirst = instance.scrollBounds.maxTop;
|
|
346
|
+
expect(scrollHeightAfterFirst - maxTopAfterFirst).toBe(instance.props.clientSize.clientHeight);
|
|
347
|
+
expect(instance.scrollBounds.maxTop).toBe(instance.scrollBounds.scrollHeight - instance.props.clientSize.clientHeight);
|
|
348
|
+
|
|
349
|
+
// guard prevents re-applying on subsequent updates
|
|
350
|
+
(0, _react.act)(function () {
|
|
351
|
+
instance.forceUpdate();
|
|
352
|
+
});
|
|
353
|
+
expect(instance.scrollBounds.scrollHeight).toBe(scrollHeightAfterFirst);
|
|
354
|
+
expect(instance.scrollBounds.maxTop).toBe(maxTopAfterFirst);
|
|
355
|
+
});
|
|
356
|
+
test('should increment scrollWidth and maxLeft by the same margin sum when horizontal item margins are detected', function () {
|
|
357
|
+
var _renderVirtualListBas2 = renderVirtualListBasic({
|
|
358
|
+
direction: 'horizontal'
|
|
359
|
+
}),
|
|
360
|
+
ref = _renderVirtualListBas2.ref;
|
|
361
|
+
var instance = ref.current;
|
|
362
|
+
var marginLeft = 8;
|
|
363
|
+
var marginRight = 8;
|
|
364
|
+
window.getComputedStyle = function (el) {
|
|
365
|
+
if (el === instance.props.itemRefs.current[0]) {
|
|
366
|
+
return {
|
|
367
|
+
getPropertyValue: function getPropertyValue(prop) {
|
|
368
|
+
if (prop === 'margin-top') return '0px';
|
|
369
|
+
if (prop === 'margin-bottom') return '0px';
|
|
370
|
+
if (prop === 'margin-left') return "".concat(marginLeft, "px");
|
|
371
|
+
if (prop === 'margin-right') return "".concat(marginRight, "px");
|
|
372
|
+
return '0px';
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
return originalGetComputedStyle(el);
|
|
377
|
+
};
|
|
378
|
+
instance.itemMarginTop = null;
|
|
379
|
+
(0, _react.act)(function () {
|
|
380
|
+
instance.forceUpdate();
|
|
381
|
+
});
|
|
382
|
+
expect(instance.scrollBounds.scrollWidth - instance.scrollBounds.maxLeft).toBe(instance.props.clientSize.clientWidth);
|
|
383
|
+
});
|
|
168
384
|
});
|