@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 CHANGED
@@ -2,6 +2,32 @@
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.5.2] - 2026-07-08
6
+
7
+ ### Changed
8
+
9
+ - `ui/Transition` to remove static `will-change` declarations, reducing persistent GPU layer promotion and memory usage on TV targets
10
+ - `ui/resolution` to not resize too often for some intermediate resolutions
11
+
12
+ ## [5.5.1] - 2026-06-01
13
+
14
+ ### Changed
15
+
16
+ - `ui/VirtualList.VirtualListBasic` scroll animation method for `scrollMode: native`
17
+
18
+ ### Fixed
19
+
20
+ - `ui/Scroller` jumping back when scrolled by long press
21
+ - `ui/VirtualList` overscroll effect at the bottom of the list
22
+ - `ui/VirtualList.VirtualList` overscroll effect at the bottom of the list
23
+ - `ui/VirtualList.VirtualGridList` overscroll effect at the bottom of the list
24
+
25
+ ## [5.4.4] - 2026-05-22
26
+
27
+ ### Fixed
28
+
29
+ - `ui/Scroller` jumping back when scrolled by long press
30
+
5
31
  ## [5.5.0] - 2026-05-08
6
32
 
7
33
  ### Added
@@ -26,8 +26,8 @@ export class ScrollerBasic extends React.Component<
26
26
  /**
27
27
  * Programmatically animates the native scroll position of `node` toward the target `left` / `top`
28
28
  offsets using `requestAnimationFrame` . It computes the scroll direction on each axis, then repeatedly
29
- calls `scrollBy` in small 18px steps (instant behavior) until the target is reached or a scroll bound
30
- is hit. Used as a Chrome fallback when repeating a smooth scroll.
29
+ calls `scrollBy` with a dynamic step (10% of remaining distance, minimum 8px) until the target is reached
30
+ or 1s has elapsed. Used as a Chrome fallback when repeating a smooth scroll.
31
31
  */
32
32
  animateScroll(any, any, any): void;
33
33
  }
@@ -151,6 +151,10 @@ var ScrollerBasic = exports.ScrollerBasic = /*#__PURE__*/function (_Component) {
151
151
  if (_platform.platform.chrome && smoothBehavior && repeat) {
152
152
  this.animateScroll(this.getRtlPositionX(left), top, node);
153
153
  } else {
154
+ if (this.scrollAnimationId) {
155
+ window.cancelAnimationFrame(this.scrollAnimationId);
156
+ this.scrollAnimationId = null;
157
+ }
154
158
  node.scrollTo({
155
159
  left: this.getRtlPositionX(left),
156
160
  top: top,
@@ -162,8 +166,8 @@ var ScrollerBasic = exports.ScrollerBasic = /*#__PURE__*/function (_Component) {
162
166
  /**
163
167
  * Programmatically animates the native scroll position of `node` toward the target `left`/`top`
164
168
  * offsets using `requestAnimationFrame`. It computes the scroll direction on each axis, then repeatedly
165
- * calls `scrollBy` in small 18px steps (instant behavior) until the target is reached or a scroll bound
166
- * is hit. Used as a Chrome fallback when repeating a smooth scroll.
169
+ * calls `scrollBy` with a dynamic step (10% of remaining distance, minimum 8px) until the target is reached
170
+ * or 1s has elapsed. Used as a Chrome fallback when repeating a smooth scroll.
167
171
  */
168
172
  }, {
169
173
  key: "animateScroll",
@@ -171,23 +175,38 @@ var ScrollerBasic = exports.ScrollerBasic = /*#__PURE__*/function (_Component) {
171
175
  var _this3 = this;
172
176
  var directionX = Math.sign(left - node.scrollLeft);
173
177
  var directionY = Math.sign(top - node.scrollTop);
174
- var _animateScroll = function animateScroll() {
178
+ var startTime = performance.now();
179
+ var _animateScroll = function animateScroll(currentTime) {
180
+ var elapsed = (currentTime - startTime) / 1000;
175
181
  var scrollLeft = directionX > 0 ? node.scrollLeft < left : node.scrollLeft > left;
176
182
  var scrollTop = directionY > 0 ? node.scrollTop < top : node.scrollTop > top;
177
183
 
178
- // Check if we reached the scroll bounds and cancel the animation
179
- if (top > _this3.scrollBounds.maxTop && node.scrollTop === _this3.scrollBounds.maxTop || left > _this3.scrollBounds.maxLeft && node.scrollLeft === _this3.scrollBounds.maxLeft || top < 0 && node.scrollTop === 0 || left < 0 && node.scrollLeft === 0) {
180
- window.cancelAnimationFrame(_this3.scrollAnimationId);
184
+ // Stop animating if the target is reached or 1s has elapsed since animation started
185
+ if (!scrollTop && !scrollLeft || elapsed > 1) {
186
+ // Fallback: if timed out before reaching target, jump there with smooth scroll
187
+ if (elapsed > 1 && (node.scrollLeft !== left || node.scrollTop !== top)) {
188
+ node.scrollTo({
189
+ top: top,
190
+ left: left,
191
+ behavior: 'smooth'
192
+ });
193
+ }
181
194
  return;
182
195
  }
183
- if (scrollTop || scrollLeft) {
184
- node.scrollBy({
185
- top: directionY * 8,
186
- left: directionX * 8,
187
- behavior: 'instant'
188
- });
189
- _this3.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
190
- }
196
+
197
+ // Clamp the step to the remaining distance so the final frame lands exactly on the target
198
+ // instead of overshooting by up to the minimum step (8px), which would push a focused item
199
+ // anchored to the start edge (e.g. `stickTo="start"`) past that edge and clip it.
200
+ var remainingX = Math.abs(left - node.scrollLeft);
201
+ var remainingY = Math.abs(top - node.scrollTop);
202
+ var horizontalScrollFactor = Math.min(Math.max(remainingX * 0.1, 8), remainingX);
203
+ var verticalScrollFactor = Math.min(Math.max(remainingY * 0.1, 8), remainingY);
204
+ node.scrollBy({
205
+ top: directionY * verticalScrollFactor,
206
+ left: directionX * horizontalScrollFactor,
207
+ behavior: 'instant'
208
+ });
209
+ _this3.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
191
210
  };
192
211
  this.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
193
212
  }
@@ -2,6 +2,14 @@
2
2
 
3
3
  require("@testing-library/jest-dom");
4
4
  var _Scroller = require("../Scroller");
5
+ var mockPlatform = {};
6
+ jest.mock('@enact/core/platform', function () {
7
+ return {
8
+ get platform() {
9
+ return mockPlatform;
10
+ }
11
+ };
12
+ });
5
13
  describe('ScrollBasic', function () {
6
14
  var scrollContentRef;
7
15
  beforeEach(function () {
@@ -18,7 +26,7 @@ describe('ScrollBasic', function () {
18
26
  afterEach(function () {
19
27
  jest.clearAllMocks();
20
28
  });
21
- test('should call scrollBy on scrollToPosition', function () {
29
+ test('should call scrollTo on scrollToPosition', function () {
22
30
  var instance = new _Scroller.ScrollerBasic({
23
31
  scrollContentRef: scrollContentRef,
24
32
  direction: 'both'
@@ -36,24 +44,189 @@ describe('ScrollBasic', function () {
36
44
  behavior: 'instant'
37
45
  });
38
46
  });
39
- test('should call scrollBy with animated values during animateScroll', function () {
40
- var rafCallback;
47
+ test('should cancel pending animation before calling scrollTo on scrollToPosition', function () {
41
48
  var instance = new _Scroller.ScrollerBasic({
42
49
  scrollContentRef: scrollContentRef,
43
50
  direction: 'both'
44
51
  });
45
- instance.scrollBounds.maxTop = 500;
46
- instance.scrollBounds.maxLeft = 500;
47
- window.requestAnimationFrame = jest.fn(function (cb) {
48
- rafCallback = cb;
52
+ var mockAnimationId = 42;
53
+ instance.scrollAnimationId = mockAnimationId;
54
+ window.cancelAnimationFrame = jest.fn();
55
+ instance.scrollToPosition(100, 200, 'instant');
56
+ expect(window.cancelAnimationFrame).toHaveBeenCalledWith(mockAnimationId);
57
+ expect(instance.scrollAnimationId).toBeNull();
58
+ expect(scrollContentRef.current.scrollTo).toHaveBeenCalledWith({
59
+ left: 100,
60
+ top: 200,
61
+ behavior: 'instant'
49
62
  });
63
+ });
64
+ test('should not call cancelAnimationFrame when scrollAnimationId is null on scrollToPosition', function () {
65
+ var instance = new _Scroller.ScrollerBasic({
66
+ scrollContentRef: scrollContentRef,
67
+ direction: 'both'
68
+ });
69
+ instance.scrollAnimationId = null;
50
70
  window.cancelAnimationFrame = jest.fn();
51
- instance.animateScroll(100, 200, scrollContentRef.current);
52
- rafCallback();
53
- expect(scrollContentRef.current.scrollBy).toHaveBeenCalled();
54
- scrollContentRef.current.scrollTop = 500;
55
- instance.animateScroll(550, 550, scrollContentRef.current);
56
- rafCallback();
57
- expect(window.cancelAnimationFrame).toHaveBeenCalled();
71
+ instance.scrollToPosition(100, 200, 'instant');
72
+ expect(window.cancelAnimationFrame).not.toHaveBeenCalled();
73
+ });
74
+ test('should call animateScroll instead of scrollTo when platform is Chrome, behavior is smooth, and repeat is true', function () {
75
+ mockPlatform.chrome = 132;
76
+ var instance = new _Scroller.ScrollerBasic({
77
+ scrollContentRef: scrollContentRef,
78
+ direction: 'both'
79
+ });
80
+ instance.animateScroll = jest.fn();
81
+ instance.scrollToPosition(100, 200, 'smooth', true);
82
+ expect(instance.animateScroll).toHaveBeenCalledWith(100, 200, scrollContentRef.current);
83
+ expect(scrollContentRef.current.scrollTo).not.toHaveBeenCalled();
84
+ delete mockPlatform.chrome;
85
+ });
86
+ describe('animateScroll', function () {
87
+ var rafCallbacks;
88
+ var rafIdCounter;
89
+ var nowValue;
90
+ beforeEach(function () {
91
+ rafCallbacks = [];
92
+ rafIdCounter = 1;
93
+ nowValue = 0;
94
+ window.requestAnimationFrame = jest.fn(function (cb) {
95
+ var id = rafIdCounter++;
96
+ rafCallbacks.push({
97
+ id: id,
98
+ cb: cb
99
+ });
100
+ return id;
101
+ });
102
+ window.cancelAnimationFrame = jest.fn(function (id) {
103
+ rafCallbacks = rafCallbacks.filter(function (entry) {
104
+ return entry.id !== id;
105
+ });
106
+ });
107
+ jest.spyOn(performance, 'now').mockImplementation(function () {
108
+ return nowValue;
109
+ });
110
+ });
111
+ afterEach(function () {
112
+ jest.restoreAllMocks();
113
+ });
114
+ function flushRaf(time) {
115
+ nowValue = time;
116
+ var callbacks = rafCallbacks.splice(0);
117
+ callbacks.forEach(function (_ref) {
118
+ var cb = _ref.cb;
119
+ return cb(time);
120
+ });
121
+ }
122
+ test('should call scrollBy with a dynamic step (10% of remaining distance) during animateScroll', function () {
123
+ scrollContentRef.current.scrollLeft = 0;
124
+ scrollContentRef.current.scrollTop = 0;
125
+ var instance = new _Scroller.ScrollerBasic({
126
+ scrollContentRef: scrollContentRef,
127
+ direction: 'both'
128
+ });
129
+ var node = scrollContentRef.current;
130
+ instance.animateScroll(200, 100, node);
131
+
132
+ // First frame at t=0
133
+ flushRaf(0);
134
+ expect(node.scrollBy).toHaveBeenCalledWith(expect.objectContaining({
135
+ left: expect.closeTo(20, 1),
136
+ // 10% of 200
137
+ top: expect.closeTo(10, 1),
138
+ // 10% of 100
139
+ behavior: 'instant'
140
+ }));
141
+ });
142
+ test('should use minimum step of 8px when remaining distance is less than 80px', function () {
143
+ scrollContentRef.current.scrollLeft = 0;
144
+ scrollContentRef.current.scrollTop = 0;
145
+ var instance = new _Scroller.ScrollerBasic({
146
+ scrollContentRef: scrollContentRef,
147
+ direction: 'both'
148
+ });
149
+ var node = scrollContentRef.current;
150
+
151
+ // 50px remaining → 10% = 5px < 8px minimum
152
+ instance.animateScroll(50, 50, node);
153
+ flushRaf(0);
154
+ expect(node.scrollBy).toHaveBeenCalledWith(expect.objectContaining({
155
+ left: 8,
156
+ top: 8,
157
+ behavior: 'instant'
158
+ }));
159
+ });
160
+ test('should stop animating and not call scrollBy when target is already reached', function () {
161
+ scrollContentRef.current.scrollLeft = 100;
162
+ scrollContentRef.current.scrollTop = 200;
163
+ var instance = new _Scroller.ScrollerBasic({
164
+ scrollContentRef: scrollContentRef,
165
+ direction: 'both'
166
+ });
167
+ var node = scrollContentRef.current;
168
+
169
+ // Target equals current position → already reached
170
+ instance.animateScroll(100, 200, node);
171
+ flushRaf(0);
172
+ expect(node.scrollBy).not.toHaveBeenCalled();
173
+ expect(node.scrollTo).not.toHaveBeenCalled();
174
+ });
175
+ test('should stop animation and call scrollTo with smooth behavior when 1s timeout elapses before reaching target', function () {
176
+ scrollContentRef.current.scrollLeft = 0;
177
+ scrollContentRef.current.scrollTop = 0;
178
+ var instance = new _Scroller.ScrollerBasic({
179
+ scrollContentRef: scrollContentRef,
180
+ direction: 'both'
181
+ });
182
+ var node = scrollContentRef.current;
183
+ instance.animateScroll(500, 500, node);
184
+
185
+ // Advance past 1s timeout without updating scroll position
186
+ flushRaf(1100);
187
+ expect(node.scrollTo).toHaveBeenCalledWith({
188
+ top: 500,
189
+ left: 500,
190
+ behavior: 'smooth'
191
+ });
192
+ });
193
+ test('should not call scrollTo fallback when target is reached exactly at timeout boundary', function () {
194
+ scrollContentRef.current.scrollLeft = 500;
195
+ scrollContentRef.current.scrollTop = 500;
196
+ var instance = new _Scroller.ScrollerBasic({
197
+ scrollContentRef: scrollContentRef,
198
+ direction: 'both'
199
+ });
200
+ var node = scrollContentRef.current;
201
+
202
+ // Target already reached
203
+ instance.animateScroll(500, 500, node);
204
+ flushRaf(1100);
205
+ expect(node.scrollTo).not.toHaveBeenCalled();
206
+ });
207
+ test('should continue requesting animation frames until target is reached', function () {
208
+ scrollContentRef.current.scrollLeft = 0;
209
+ scrollContentRef.current.scrollTop = 0;
210
+ var instance = new _Scroller.ScrollerBasic({
211
+ scrollContentRef: scrollContentRef,
212
+ direction: 'both'
213
+ });
214
+ var node = scrollContentRef.current;
215
+ instance.animateScroll(100, 0, node);
216
+
217
+ // First frame: scrollBy called, new rAF registered
218
+ flushRaf(0);
219
+ expect(node.scrollBy).toHaveBeenCalledTimes(1);
220
+
221
+ // Simulate scroll progress
222
+ node.scrollLeft = 50;
223
+ flushRaf(100);
224
+ expect(node.scrollBy).toHaveBeenCalledTimes(2);
225
+
226
+ // Simulate reaching target
227
+ node.scrollLeft = 100;
228
+ flushRaf(200);
229
+ expect(node.scrollBy).toHaveBeenCalledTimes(2);
230
+ });
58
231
  });
59
232
  });