@enact/ui 5.6.0 → 5.7.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 +8 -8
- package/AnnounceDecorator/AnnounceDecorator.js +5 -5
- package/BodyText/BodyText.js +5 -5
- package/BodyText/tests/BodyText-specs.js +2 -1
- package/Button/Button.js +5 -5
- package/CHANGELOG.md +18 -0
- package/Cancelable/Cancelable.js +9 -9
- package/Cancelable/tests/Cancelable-specs.js +5 -5
- package/Card/Card.js +5 -5
- package/Card/tests/Card-specs.js +2 -1
- package/Changeable/Changeable.js +9 -9
- package/ComponentOverride/ComponentOverride.js +15 -11
- package/FloatingLayer/FloatingLayer.js +10 -10
- package/FloatingLayer/FloatingLayerContainer.js +3 -3
- package/FloatingLayer/FloatingLayerDecorator.js +5 -5
- package/FloatingLayer/Scrim.js +9 -9
- package/FloatingLayer/tests/useFloatingLayerDecorator-specs.js +4 -4
- package/FloatingLayer/useFloatingLayer.js +3 -4
- package/ForwardRef/ForwardRef.js +5 -5
- package/Group/Group.js +5 -5
- package/Group/GroupItem.js +5 -5
- package/Group/tests/Group-specs.js +2 -1
- package/Heading/Heading.js +5 -5
- package/Icon/Icon.js +5 -5
- package/Icon/tests/Icon-specs.js +2 -1
- package/Image/Image.js +5 -5
- package/Image/tests/Image-specs.js +2 -1
- package/ImageItem/ImageItem.js +5 -5
- package/ImageItem/tests/ImageItem-specs.js +6 -5
- package/Item/Item.js +5 -5
- package/LabeledIcon/LabeledIcon.js +5 -5
- package/Layout/Cell.js +5 -5
- package/Layout/Layout.js +5 -5
- package/Layout/tests/Layout-specs.js +9 -9
- package/Marquee/Marquee.module.css +44 -0
- package/Marquee/MarqueeBase.js +134 -21
- package/Marquee/MarqueeController.js +4 -4
- package/Marquee/MarqueeDecorator.js +219 -27
- package/Marquee/index.d.ts +60 -12
- package/Marquee/tests/Marquee-specs.js +3 -3
- package/Marquee/tests/Marquee-vertical-specs.js +1358 -0
- package/Marquee/useMarqueeController.js +4 -4
- package/Marquee/utils.js +22 -0
- package/Marquee/verticalMeasure.js +118 -0
- package/Measurable/Measurable.js +8 -9
- package/Measurable/tests/Measurable-specs.js +7 -6
- package/Media/Media.js +10 -10
- package/Placeholder/PlaceholderControllerDecorator.js +9 -9
- package/Placeholder/PlaceholderDecorator.js +9 -9
- package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +4 -4
- package/ProgressBar/ProgressBar.js +5 -5
- package/Repeater/Repeater.js +5 -5
- package/Repeater/tests/Repeater-specs.js +6 -5
- package/Resizable/Resizable.js +4 -4
- package/Resizable/tests/Resizable-specs.js +2 -1
- package/Resizable/tests/useResize-specs.js +4 -4
- package/Resizable/useResize.js +3 -3
- package/Routable/Link.js +9 -9
- package/Routable/Routable.js +5 -5
- package/Routable/Router.js +9 -9
- package/Routable/tests/Routable-specs.js +7 -8
- package/Routable/tests/Router-specs.js +1 -1
- package/Scroller/Scroller.js +4 -4
- package/Scroller/ScrollerBasic.js +10 -10
- package/Skinnable/Skinnable.js +5 -5
- package/Skinnable/tests/Skinnable-specs.js +4 -4
- package/Skinnable/tests/useSkins-specs.js +4 -4
- package/Slider/Knob.js +5 -5
- package/Slider/PositionDecorator.js +8 -8
- package/Slider/Slider.js +5 -5
- package/Slottable/Slottable.js +4 -4
- package/Slottable/useSlots.js +5 -5
- package/Spinner/Spinner.js +5 -5
- package/ToggleIcon/ToggleIcon.js +5 -5
- package/Toggleable/Toggle.js +5 -5
- package/Toggleable/Toggleable.js +9 -9
- package/Toggleable/useToggle.js +5 -5
- package/Touchable/ClickAllow.js +3 -3
- package/Touchable/Drag.js +6 -6
- package/Touchable/Flick.js +5 -5
- package/Touchable/Hold.js +5 -5
- package/Touchable/Pinch.js +6 -6
- package/Touchable/Touch.js +3 -3
- package/Touchable/Touchable.js +5 -5
- package/Touchable/config.js +4 -4
- package/Touchable/tests/Touchable-specs.js +1 -1
- package/Touchable/tests/useTouch-specs.js +5 -5
- package/Touchable/useTouch.js +7 -8
- package/Transition/Transition.js +14 -13
- package/Transition/tests/Transition-specs.js +9 -9
- package/ViewManager/Arranger.js +4 -4
- package/ViewManager/TransitionGroup.js +7 -7
- package/ViewManager/View.js +9 -9
- package/ViewManager/ViewManager.js +11 -10
- package/ViewManager/tests/ViewManager-specs.js +6 -6
- package/VirtualList/VirtualList.js +4 -4
- package/VirtualList/VirtualListBasic.js +67 -47
- package/VirtualList/tests/VirtualGridList-native-specs.js +5 -5
- package/VirtualList/tests/VirtualGridList-specs.js +16 -15
- package/VirtualList/tests/VirtualList-native-specs.js +164 -16
- package/VirtualList/tests/VirtualList-specs.js +16 -15
- package/internal/IdProvider/IdProvider.js +4 -4
- package/internal/IdProvider/Provider.js +3 -3
- package/internal/IdProvider/tests/IdProvider-specs.js +4 -4
- package/internal/IdProvider/tests/useId-specs.js +16 -8
- package/internal/Pure/Pure.js +9 -9
- package/internal/Pure/tests/Pure-specs.js +8 -8
- package/internal/localized-fonts/localized-fonts.js +3 -4
- package/package.json +6 -6
- package/resolution/ResolutionDecorator.js +71 -87
- package/resolution/index.js +2 -1
- package/resolution/tests/resolution-specs.js +7 -8
- package/useControlledState/tests/useControlledState-specs.js +3 -4
- package/useControlledState/useControlledState.js +3 -4
- package/useScroll/ScrollAnimator.js +3 -3
- package/useScroll/Scrollbar.js +5 -5
- package/useScroll/ScrollbarTrack.js +5 -5
- package/useScroll/scrollMotion.js +126 -0
- package/useScroll/tests/scrollMotion-specs.js +215 -0
- package/useScroll/tests/useScroll-specs.js +430 -9
- package/useScroll/useScroll.js +156 -92
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _scrollMotion = require("../scrollMotion");
|
|
4
|
+
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; }
|
|
5
|
+
function _objectSpread(r) { for (var t = 1; t < arguments.length; t++) { var o = null != arguments[t] ? arguments[t] : {}; t % 2 ? ownKeys(Object(o), !0).forEach(function (t) { _defineProperty(r, t, o[t]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(o)) : ownKeys(Object(o)).forEach(function (e) { Object.defineProperty(r, e, Object.getOwnPropertyDescriptor(o, e)); }); } return r; }
|
|
6
|
+
function _defineProperty(r, t, o) { return (t = _toPropertyKey(t)) in r ? Object.defineProperty(r, t, { value: o, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = o, r; }
|
|
7
|
+
function _toPropertyKey(r) { var o = _toPrimitive(r, "string"); return "symbol" == typeof o ? o : o + ""; }
|
|
8
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
9
|
+
var motion = function motion(overrides) {
|
|
10
|
+
return _objectSpread({
|
|
11
|
+
delay: 0,
|
|
12
|
+
duration: 600,
|
|
13
|
+
ease: function ease(progress) {
|
|
14
|
+
return progress;
|
|
15
|
+
}
|
|
16
|
+
}, overrides);
|
|
17
|
+
};
|
|
18
|
+
describe('scrollMotion', function () {
|
|
19
|
+
describe('resolveScrollMotion', function () {
|
|
20
|
+
test('should use the token when the scroll has no duration of its own', function () {
|
|
21
|
+
var resolved = (0, _scrollMotion.resolveScrollMotion)({
|
|
22
|
+
getScrollMotion: function getScrollMotion() {
|
|
23
|
+
return motion();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
expect(resolved.duration).toBe(600);
|
|
27
|
+
expect(resolved.delay).toBe(0);
|
|
28
|
+
expect(resolved.timingFunction(0, 100, 600, 300, false)).toBe(50);
|
|
29
|
+
});
|
|
30
|
+
test('should keep a held key linear', function () {
|
|
31
|
+
var _resolveScrollMotion = (0, _scrollMotion.resolveScrollMotion)({
|
|
32
|
+
getScrollMotion: function getScrollMotion() {
|
|
33
|
+
return motion({
|
|
34
|
+
ease: function ease() {
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}),
|
|
40
|
+
timingFunction = _resolveScrollMotion.timingFunction;
|
|
41
|
+
expect(timingFunction(0, 100, 100, 50, true)).toBe(50);
|
|
42
|
+
});
|
|
43
|
+
test('should keep an explicit duration, a held key, and a repeat on the existing timing', function () {
|
|
44
|
+
var getScrollMotion = function getScrollMotion() {
|
|
45
|
+
return motion();
|
|
46
|
+
};
|
|
47
|
+
expect((0, _scrollMotion.resolveScrollMotion)({
|
|
48
|
+
duration: 320,
|
|
49
|
+
getScrollMotion: getScrollMotion
|
|
50
|
+
})).toBeNull();
|
|
51
|
+
expect((0, _scrollMotion.resolveScrollMotion)({
|
|
52
|
+
keyPressed: true,
|
|
53
|
+
getScrollMotion: getScrollMotion
|
|
54
|
+
})).toBeNull();
|
|
55
|
+
expect((0, _scrollMotion.resolveScrollMotion)({
|
|
56
|
+
repeat: true,
|
|
57
|
+
getScrollMotion: getScrollMotion
|
|
58
|
+
})).toBeNull();
|
|
59
|
+
expect((0, _scrollMotion.resolveScrollMotion)({})).toBeNull();
|
|
60
|
+
expect((0, _scrollMotion.resolveScrollMotion)({
|
|
61
|
+
getScrollMotion: function getScrollMotion() {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
})).toBeNull();
|
|
65
|
+
expect((0, _scrollMotion.resolveScrollMotion)({
|
|
66
|
+
getScrollMotion: function getScrollMotion() {
|
|
67
|
+
return {
|
|
68
|
+
duration: 600
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
})).toBeNull();
|
|
72
|
+
});
|
|
73
|
+
test('should keep a positive delay and drop a non-positive one', function () {
|
|
74
|
+
expect((0, _scrollMotion.resolveScrollMotion)({
|
|
75
|
+
getScrollMotion: function getScrollMotion() {
|
|
76
|
+
return motion({
|
|
77
|
+
delay: 30
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}).delay).toBe(30);
|
|
81
|
+
expect((0, _scrollMotion.resolveScrollMotion)({
|
|
82
|
+
getScrollMotion: function getScrollMotion() {
|
|
83
|
+
return motion({
|
|
84
|
+
delay: 0
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}).delay).toBe(0);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe('startNativeScroll', function () {
|
|
91
|
+
var realNow = performance.now;
|
|
92
|
+
var realRaf = window.requestAnimationFrame;
|
|
93
|
+
var realCancel = window.cancelAnimationFrame;
|
|
94
|
+
var now;
|
|
95
|
+
var next;
|
|
96
|
+
beforeEach(function () {
|
|
97
|
+
now = 1000;
|
|
98
|
+
next = null;
|
|
99
|
+
performance.now = function () {
|
|
100
|
+
return now;
|
|
101
|
+
};
|
|
102
|
+
window.requestAnimationFrame = function (callback) {
|
|
103
|
+
next = callback;
|
|
104
|
+
return 1;
|
|
105
|
+
};
|
|
106
|
+
window.cancelAnimationFrame = function () {
|
|
107
|
+
next = null;
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
afterEach(function () {
|
|
111
|
+
performance.now = realNow;
|
|
112
|
+
window.requestAnimationFrame = realRaf;
|
|
113
|
+
window.cancelAnimationFrame = realCancel;
|
|
114
|
+
});
|
|
115
|
+
var frame = function frame(at) {
|
|
116
|
+
var callback = next;
|
|
117
|
+
next = null;
|
|
118
|
+
now = at;
|
|
119
|
+
callback(at);
|
|
120
|
+
};
|
|
121
|
+
test('should interpolate in logical coordinates and release the animation before the final position', function () {
|
|
122
|
+
var state = {};
|
|
123
|
+
var positions = [];
|
|
124
|
+
(0, _scrollMotion.startNativeScroll)(state, {
|
|
125
|
+
fromX: 0,
|
|
126
|
+
fromY: 0,
|
|
127
|
+
toX: 100,
|
|
128
|
+
toY: 40,
|
|
129
|
+
duration: 600,
|
|
130
|
+
ease: function ease(progress) {
|
|
131
|
+
return progress;
|
|
132
|
+
},
|
|
133
|
+
scrollTo: function scrollTo(x, y) {
|
|
134
|
+
return positions.push({
|
|
135
|
+
x: x,
|
|
136
|
+
y: y,
|
|
137
|
+
animating: state.motionAnimating
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
expect(state.motionAnimating).toBe(true);
|
|
142
|
+
frame(1300);
|
|
143
|
+
expect(positions).toEqual([{
|
|
144
|
+
x: 50,
|
|
145
|
+
y: 20,
|
|
146
|
+
animating: true
|
|
147
|
+
}]);
|
|
148
|
+
frame(1600);
|
|
149
|
+
expect(positions[1]).toEqual({
|
|
150
|
+
x: 100,
|
|
151
|
+
y: 40,
|
|
152
|
+
animating: false
|
|
153
|
+
});
|
|
154
|
+
expect(state.motionAnimating).toBe(false);
|
|
155
|
+
expect(state.motionFrame).toBeNull();
|
|
156
|
+
});
|
|
157
|
+
test('should not move when the scroll is already at its target', function () {
|
|
158
|
+
var state = {
|
|
159
|
+
motionAnimating: true
|
|
160
|
+
};
|
|
161
|
+
var scrollTo = jest.fn();
|
|
162
|
+
(0, _scrollMotion.startNativeScroll)(state, {
|
|
163
|
+
fromX: 10,
|
|
164
|
+
fromY: 10,
|
|
165
|
+
toX: 10,
|
|
166
|
+
toY: 10,
|
|
167
|
+
duration: 600,
|
|
168
|
+
ease: function ease(progress) {
|
|
169
|
+
return progress;
|
|
170
|
+
},
|
|
171
|
+
scrollTo: scrollTo
|
|
172
|
+
});
|
|
173
|
+
expect(scrollTo).not.toHaveBeenCalled();
|
|
174
|
+
expect(state.motionAnimating).toBe(false);
|
|
175
|
+
expect(next).toBeNull();
|
|
176
|
+
});
|
|
177
|
+
test('should drop a frame scheduled before it was cancelled', function () {
|
|
178
|
+
var state = {};
|
|
179
|
+
var scrollTo = jest.fn();
|
|
180
|
+
(0, _scrollMotion.startNativeScroll)(state, {
|
|
181
|
+
fromX: 0,
|
|
182
|
+
fromY: 0,
|
|
183
|
+
toX: 100,
|
|
184
|
+
toY: 0,
|
|
185
|
+
duration: 600,
|
|
186
|
+
ease: function ease(progress) {
|
|
187
|
+
return progress;
|
|
188
|
+
},
|
|
189
|
+
scrollTo: scrollTo
|
|
190
|
+
});
|
|
191
|
+
var scheduled = next;
|
|
192
|
+
(0, _scrollMotion.cancelScrollMotion)(state);
|
|
193
|
+
scheduled(1600);
|
|
194
|
+
expect(scrollTo).not.toHaveBeenCalled();
|
|
195
|
+
expect(state.motionAnimating).toBe(false);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
describe('cancelScrollMotion', function () {
|
|
199
|
+
test('should cancel a delayed start', function () {
|
|
200
|
+
jest.useFakeTimers();
|
|
201
|
+
try {
|
|
202
|
+
var started = jest.fn();
|
|
203
|
+
var state = {};
|
|
204
|
+
state.motionDelay = setTimeout(started, 30);
|
|
205
|
+
(0, _scrollMotion.cancelScrollMotion)(state);
|
|
206
|
+
jest.advanceTimersByTime(30);
|
|
207
|
+
expect(started).not.toHaveBeenCalled();
|
|
208
|
+
expect(state.motionDelay).toBeNull();
|
|
209
|
+
expect(state.motionAnimating).toBe(false);
|
|
210
|
+
} finally {
|
|
211
|
+
jest.useRealTimers();
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
});
|
|
@@ -3,20 +3,19 @@
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
4
|
var _react = require("@testing-library/react");
|
|
5
5
|
var _useScroll = require("../useScroll");
|
|
6
|
-
function _slicedToArray(
|
|
6
|
+
function _slicedToArray(e, i) { return _iterableToArrayLimit(e, i) || _unsupportedIterableToArray(e, i) || _nonIterableRest(); }
|
|
7
7
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
-
function _unsupportedIterableToArray(
|
|
8
|
+
function _unsupportedIterableToArray(t, e) { if (t) { if ("string" == typeof t) return _arrayLikeToArray(t, e); var o = {}.toString.call(t).slice(8, -1); return "Object" === o && t.constructor && (o = t.constructor.name), "Map" === o || "Set" === o ? Array.from(t) : "Arguments" === o || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o) ? _arrayLikeToArray(t, e) : void 0; } }
|
|
9
9
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
10
|
-
function _iterableToArrayLimit(r,
|
|
11
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
10
|
+
function _iterableToArrayLimit(r, t) { var e = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (Array.isArray(r) && (null == e || e === ("undefined" != typeof Symbol && [][Symbol.iterator]) || e === []["@@iterator"])) return r; if (null != e) { var l, n, i, a, u = [], o = !0, f = !1; try { if (i = (e = e.call(r)).next, 0 === t) { if (Object(e) !== e) return; o = !1; } else for (; !(o = (l = i.call(e)).done) && (u.push(l.value), u.length !== t); o = !0); } catch (r) { f = !0, n = r; } finally { try { if (!o && null != e["return"] && (a = e["return"](), Object(a) !== a)) return; } finally { if (f) throw n; } } return u; } }
|
|
12
11
|
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; }
|
|
13
|
-
function _objectSpread(
|
|
14
|
-
function _defineProperty(
|
|
12
|
+
function _objectSpread(r) { for (var t = 1; t < arguments.length; t++) { var o = null != arguments[t] ? arguments[t] : {}; t % 2 ? ownKeys(Object(o), !0).forEach(function (t) { _defineProperty(r, t, o[t]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(o)) : ownKeys(Object(o)).forEach(function (e) { Object.defineProperty(r, e, Object.getOwnPropertyDescriptor(o, e)); }); } return r; }
|
|
13
|
+
function _defineProperty(r, t, o) { return (t = _toPropertyKey(t)) in r ? Object.defineProperty(r, t, { value: o, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = o, r; }
|
|
15
14
|
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
16
|
-
function _defineProperties(
|
|
15
|
+
function _defineProperties(r, t) { for (var o = 0; o < t.length; o++) { var i = t[o]; i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(r, _toPropertyKey(i.key), i); } }
|
|
17
16
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
18
|
-
function _toPropertyKey(
|
|
19
|
-
function _toPrimitive(t,
|
|
17
|
+
function _toPropertyKey(r) { var o = _toPrimitive(r, "string"); return "symbol" == typeof o ? o : o + ""; }
|
|
18
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
20
19
|
// Mock all dependencies at the top level BEFORE importing useScroll
|
|
21
20
|
var mockRiScale;
|
|
22
21
|
var mockPlatform;
|
|
@@ -622,4 +621,426 @@ describe('useScroll', function () {
|
|
|
622
621
|
expect(onKeyDown).toHaveBeenCalledTimes(1);
|
|
623
622
|
});
|
|
624
623
|
});
|
|
624
|
+
describe('scroll motion', function () {
|
|
625
|
+
var realRaf = window.requestAnimationFrame;
|
|
626
|
+
var realCancel = window.cancelAnimationFrame;
|
|
627
|
+
var realNow = performance.now;
|
|
628
|
+
var now;
|
|
629
|
+
var next;
|
|
630
|
+
beforeEach(function () {
|
|
631
|
+
mockPlatform = {
|
|
632
|
+
chrome: 120
|
|
633
|
+
};
|
|
634
|
+
mockRiScale = function mockRiScale(val) {
|
|
635
|
+
return val;
|
|
636
|
+
};
|
|
637
|
+
now = 1000;
|
|
638
|
+
next = null;
|
|
639
|
+
performance.now = function () {
|
|
640
|
+
return now;
|
|
641
|
+
};
|
|
642
|
+
window.requestAnimationFrame = function (callback) {
|
|
643
|
+
next = callback;
|
|
644
|
+
return 1;
|
|
645
|
+
};
|
|
646
|
+
window.cancelAnimationFrame = function () {
|
|
647
|
+
next = null;
|
|
648
|
+
};
|
|
649
|
+
if (!('onscrollend' in window)) {
|
|
650
|
+
window.onscrollend = null;
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
afterEach(function () {
|
|
654
|
+
performance.now = realNow;
|
|
655
|
+
window.requestAnimationFrame = realRaf;
|
|
656
|
+
window.cancelAnimationFrame = realCancel;
|
|
657
|
+
jest.useRealTimers();
|
|
658
|
+
});
|
|
659
|
+
var bounds = {
|
|
660
|
+
clientWidth: 1920,
|
|
661
|
+
clientHeight: 1080,
|
|
662
|
+
scrollWidth: 2000,
|
|
663
|
+
scrollHeight: 2000,
|
|
664
|
+
maxTop: 920,
|
|
665
|
+
maxLeft: 80
|
|
666
|
+
};
|
|
667
|
+
var token = function token(overrides) {
|
|
668
|
+
return _objectSpread({
|
|
669
|
+
delay: 0,
|
|
670
|
+
duration: 600,
|
|
671
|
+
ease: function ease(progress) {
|
|
672
|
+
return progress;
|
|
673
|
+
}
|
|
674
|
+
}, overrides);
|
|
675
|
+
};
|
|
676
|
+
function renderScroll() {
|
|
677
|
+
var extra = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
678
|
+
var mocks = createMockRefs();
|
|
679
|
+
mocks.scrollContentHandle.current.getScrollBounds = function () {
|
|
680
|
+
return bounds;
|
|
681
|
+
};
|
|
682
|
+
mocks.scrollContentHandle.current.scrollToPosition = jest.fn();
|
|
683
|
+
mocks.scrollContentHandle.current.setScrollPosition = jest.fn();
|
|
684
|
+
var handle = null;
|
|
685
|
+
(0, _react.renderHook)(function () {
|
|
686
|
+
return (0, _useScroll.useScrollBase)(_objectSpread(_objectSpread({
|
|
687
|
+
direction: 'vertical',
|
|
688
|
+
scrollMode: 'native'
|
|
689
|
+
}, mocks), {}, {
|
|
690
|
+
assignProperties: jest.fn(),
|
|
691
|
+
horizontalScrollbar: 'auto',
|
|
692
|
+
verticalScrollbar: 'auto',
|
|
693
|
+
onKeyDown: jest.fn(),
|
|
694
|
+
setScrollContainerHandle: function setScrollContainerHandle(value) {
|
|
695
|
+
handle = value;
|
|
696
|
+
}
|
|
697
|
+
}, extra));
|
|
698
|
+
});
|
|
699
|
+
return {
|
|
700
|
+
mocks: mocks,
|
|
701
|
+
get handle() {
|
|
702
|
+
return handle;
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
function emitScroll(node) {
|
|
707
|
+
var top = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
708
|
+
var left = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
709
|
+
var event = new Event('scroll');
|
|
710
|
+
Object.defineProperty(event, 'target', {
|
|
711
|
+
value: {
|
|
712
|
+
scrollLeft: left,
|
|
713
|
+
scrollTop: top
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
(0, _react.fireEvent)(node, event);
|
|
717
|
+
}
|
|
718
|
+
function emitScrollEnd(node) {
|
|
719
|
+
(0, _react.fireEvent)(node, new Event('scrollend'));
|
|
720
|
+
}
|
|
721
|
+
test('should interpolate a native scroll with the motion token', function () {
|
|
722
|
+
var themeStart = jest.fn();
|
|
723
|
+
var _renderScroll = renderScroll({
|
|
724
|
+
getScrollMotion: function getScrollMotion() {
|
|
725
|
+
return token();
|
|
726
|
+
},
|
|
727
|
+
start: themeStart
|
|
728
|
+
}),
|
|
729
|
+
mocks = _renderScroll.mocks,
|
|
730
|
+
handle = _renderScroll.handle;
|
|
731
|
+
(0, _react.act)(function () {
|
|
732
|
+
handle.start({
|
|
733
|
+
targetX: 0,
|
|
734
|
+
targetY: 100
|
|
735
|
+
});
|
|
736
|
+
});
|
|
737
|
+
expect(themeStart).toHaveBeenCalledWith(true);
|
|
738
|
+
(0, _react.act)(function () {
|
|
739
|
+
next(1300);
|
|
740
|
+
});
|
|
741
|
+
expect(mocks.scrollContentHandle.current.scrollToPosition).toHaveBeenCalledWith(0, 50, 'instant');
|
|
742
|
+
(0, _react.act)(function () {
|
|
743
|
+
next(1600);
|
|
744
|
+
});
|
|
745
|
+
expect(mocks.scrollContentHandle.current.scrollToPosition).toHaveBeenLastCalledWith(0, 100, 'instant');
|
|
746
|
+
});
|
|
747
|
+
test('should keep the browser smooth scroll when no motion token is set', function () {
|
|
748
|
+
var _renderScroll2 = renderScroll(),
|
|
749
|
+
mocks = _renderScroll2.mocks,
|
|
750
|
+
handle = _renderScroll2.handle;
|
|
751
|
+
(0, _react.act)(function () {
|
|
752
|
+
handle.start({
|
|
753
|
+
targetX: 0,
|
|
754
|
+
targetY: 100
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
var call = mocks.scrollContentHandle.current.scrollToPosition.mock.calls[0];
|
|
758
|
+
expect(call.slice(0, 3)).toEqual([0, 100, 'smooth']);
|
|
759
|
+
expect(call[3]).toBeFalsy();
|
|
760
|
+
});
|
|
761
|
+
test('should scroll instantly when animation is disabled', function () {
|
|
762
|
+
var themeStart = jest.fn();
|
|
763
|
+
var _renderScroll3 = renderScroll({
|
|
764
|
+
start: themeStart
|
|
765
|
+
}),
|
|
766
|
+
mocks = _renderScroll3.mocks,
|
|
767
|
+
handle = _renderScroll3.handle;
|
|
768
|
+
(0, _react.act)(function () {
|
|
769
|
+
handle.start({
|
|
770
|
+
targetX: 0,
|
|
771
|
+
targetY: 40,
|
|
772
|
+
animate: false
|
|
773
|
+
});
|
|
774
|
+
});
|
|
775
|
+
expect(mocks.scrollContentHandle.current.scrollToPosition).toHaveBeenCalledWith(0, 40, 'instant');
|
|
776
|
+
expect(themeStart).toHaveBeenCalledWith(false);
|
|
777
|
+
});
|
|
778
|
+
test('should wait for the token delay before starting', function () {
|
|
779
|
+
jest.useFakeTimers({
|
|
780
|
+
doNotFake: ['cancelAnimationFrame', 'performance', 'requestAnimationFrame']
|
|
781
|
+
});
|
|
782
|
+
now = 1000;
|
|
783
|
+
performance.now = function () {
|
|
784
|
+
return now;
|
|
785
|
+
};
|
|
786
|
+
window.requestAnimationFrame = function (callback) {
|
|
787
|
+
next = callback;
|
|
788
|
+
return 1;
|
|
789
|
+
};
|
|
790
|
+
window.cancelAnimationFrame = function () {
|
|
791
|
+
next = null;
|
|
792
|
+
};
|
|
793
|
+
var _renderScroll4 = renderScroll({
|
|
794
|
+
getScrollMotion: function getScrollMotion() {
|
|
795
|
+
return token({
|
|
796
|
+
delay: 30
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
}),
|
|
800
|
+
mocks = _renderScroll4.mocks,
|
|
801
|
+
handle = _renderScroll4.handle;
|
|
802
|
+
(0, _react.act)(function () {
|
|
803
|
+
handle.start({
|
|
804
|
+
targetX: 0,
|
|
805
|
+
targetY: 100
|
|
806
|
+
});
|
|
807
|
+
});
|
|
808
|
+
expect(next).toBeNull();
|
|
809
|
+
(0, _react.act)(function () {
|
|
810
|
+
jest.advanceTimersByTime(30);
|
|
811
|
+
});
|
|
812
|
+
expect(next).toEqual(expect.any(Function));
|
|
813
|
+
expect(mocks.scrollContentHandle.current.scrollToPosition).not.toHaveBeenCalled();
|
|
814
|
+
});
|
|
815
|
+
test('should ignore a native scroll that repeats the current target', function () {
|
|
816
|
+
var _renderScroll5 = renderScroll({
|
|
817
|
+
getScrollMotion: function getScrollMotion() {
|
|
818
|
+
return token();
|
|
819
|
+
}
|
|
820
|
+
}),
|
|
821
|
+
mocks = _renderScroll5.mocks,
|
|
822
|
+
handle = _renderScroll5.handle;
|
|
823
|
+
(0, _react.act)(function () {
|
|
824
|
+
handle.start({
|
|
825
|
+
targetX: 0,
|
|
826
|
+
targetY: 100
|
|
827
|
+
});
|
|
828
|
+
emitScroll(mocks.scrollContentRef.current);
|
|
829
|
+
});
|
|
830
|
+
var scheduled = next;
|
|
831
|
+
(0, _react.act)(function () {
|
|
832
|
+
handle.start({
|
|
833
|
+
targetX: 0,
|
|
834
|
+
targetY: 100
|
|
835
|
+
});
|
|
836
|
+
});
|
|
837
|
+
expect(next).toBe(scheduled);
|
|
838
|
+
expect(mocks.scrollContentHandle.current.scrollToPosition).not.toHaveBeenCalled();
|
|
839
|
+
});
|
|
840
|
+
test('should aim a motion scroll at the end of the range', function () {
|
|
841
|
+
var applyOverscrollEffect = jest.fn();
|
|
842
|
+
var _renderScroll6 = renderScroll({
|
|
843
|
+
applyOverscrollEffect: applyOverscrollEffect,
|
|
844
|
+
getScrollMotion: function getScrollMotion() {
|
|
845
|
+
return token();
|
|
846
|
+
}
|
|
847
|
+
}),
|
|
848
|
+
mocks = _renderScroll6.mocks,
|
|
849
|
+
handle = _renderScroll6.handle;
|
|
850
|
+
(0, _react.act)(function () {
|
|
851
|
+
handle.start({
|
|
852
|
+
targetX: 0,
|
|
853
|
+
targetY: 2000,
|
|
854
|
+
overscrollEffect: true
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
(0, _react.act)(function () {
|
|
858
|
+
now = 1600;
|
|
859
|
+
next(1600);
|
|
860
|
+
});
|
|
861
|
+
expect(mocks.scrollContentHandle.current.scrollToPosition).toHaveBeenLastCalledWith(0, bounds.maxTop, 'instant');
|
|
862
|
+
expect(applyOverscrollEffect).not.toHaveBeenCalled();
|
|
863
|
+
|
|
864
|
+
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
865
|
+
(0, _react.act)(function () {
|
|
866
|
+
emitScroll(mocks.scrollContentRef.current, bounds.maxTop, 0);
|
|
867
|
+
var scrollEnd = new Event('scrollend');
|
|
868
|
+
Object.defineProperty(scrollEnd, 'target', {
|
|
869
|
+
value: {
|
|
870
|
+
scrollLeft: 0,
|
|
871
|
+
scrollTop: bounds.maxTop
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
(0, _react.fireEvent)(mocks.scrollContentRef.current, scrollEnd);
|
|
875
|
+
});
|
|
876
|
+
(0, _react.act)(function () {
|
|
877
|
+
handle.start({
|
|
878
|
+
targetX: 0,
|
|
879
|
+
targetY: bounds.maxTop + 400,
|
|
880
|
+
overscrollEffect: true
|
|
881
|
+
});
|
|
882
|
+
});
|
|
883
|
+
expect(applyOverscrollEffect).toHaveBeenCalledWith('vertical', 'after', 2, 0.5);
|
|
884
|
+
});
|
|
885
|
+
test('should retarget a native scroll when the target changes while scrolling', function () {
|
|
886
|
+
var _renderScroll7 = renderScroll({
|
|
887
|
+
getScrollMotion: function getScrollMotion() {
|
|
888
|
+
return token();
|
|
889
|
+
}
|
|
890
|
+
}),
|
|
891
|
+
mocks = _renderScroll7.mocks,
|
|
892
|
+
handle = _renderScroll7.handle;
|
|
893
|
+
(0, _react.act)(function () {
|
|
894
|
+
handle.start({
|
|
895
|
+
targetX: 0,
|
|
896
|
+
targetY: 100
|
|
897
|
+
});
|
|
898
|
+
emitScroll(mocks.scrollContentRef.current, 20, 0);
|
|
899
|
+
});
|
|
900
|
+
(0, _react.act)(function () {
|
|
901
|
+
handle.start({
|
|
902
|
+
targetX: 0,
|
|
903
|
+
targetY: 180
|
|
904
|
+
});
|
|
905
|
+
});
|
|
906
|
+
(0, _react.act)(function () {
|
|
907
|
+
now = 1600;
|
|
908
|
+
next(1600);
|
|
909
|
+
});
|
|
910
|
+
expect(mocks.scrollContentHandle.current.scrollToPosition).toHaveBeenLastCalledWith(0, 180, 'instant');
|
|
911
|
+
});
|
|
912
|
+
test('should apply overscroll on both axes when a scroll starts', function () {
|
|
913
|
+
var _renderScroll8 = renderScroll({
|
|
914
|
+
direction: 'both',
|
|
915
|
+
applyOverscrollEffect: jest.fn()
|
|
916
|
+
}),
|
|
917
|
+
mocks = _renderScroll8.mocks,
|
|
918
|
+
handle = _renderScroll8.handle;
|
|
919
|
+
(0, _react.act)(function () {
|
|
920
|
+
handle.start({
|
|
921
|
+
targetX: 80,
|
|
922
|
+
targetY: 920,
|
|
923
|
+
overscrollEffect: true
|
|
924
|
+
});
|
|
925
|
+
});
|
|
926
|
+
var call = mocks.scrollContentHandle.current.scrollToPosition.mock.calls[0];
|
|
927
|
+
expect(call.slice(0, 3)).toEqual([80, 920, 'smooth']);
|
|
928
|
+
expect(call[3]).toBeFalsy();
|
|
929
|
+
});
|
|
930
|
+
test('should ease a horizontal translate scroll with the motion token', function () {
|
|
931
|
+
var _renderScroll9 = renderScroll({
|
|
932
|
+
direction: 'horizontal',
|
|
933
|
+
scrollMode: 'translate',
|
|
934
|
+
getScrollMotion: function getScrollMotion() {
|
|
935
|
+
return token();
|
|
936
|
+
}
|
|
937
|
+
}),
|
|
938
|
+
mocks = _renderScroll9.mocks,
|
|
939
|
+
handle = _renderScroll9.handle;
|
|
940
|
+
(0, _react.act)(function () {
|
|
941
|
+
handle.start({
|
|
942
|
+
targetX: 40,
|
|
943
|
+
targetY: 0
|
|
944
|
+
});
|
|
945
|
+
});
|
|
946
|
+
(0, _react.act)(function () {
|
|
947
|
+
next();
|
|
948
|
+
});
|
|
949
|
+
expect(mocks.scrollContentHandle.current.setScrollPosition).toHaveBeenCalled();
|
|
950
|
+
});
|
|
951
|
+
test('should not accept scrollend while a motion scroll is running', function () {
|
|
952
|
+
var scrollStopOnScroll = jest.fn();
|
|
953
|
+
var _renderScroll0 = renderScroll({
|
|
954
|
+
getScrollMotion: function getScrollMotion() {
|
|
955
|
+
return token();
|
|
956
|
+
},
|
|
957
|
+
scrollStopOnScroll: scrollStopOnScroll
|
|
958
|
+
}),
|
|
959
|
+
mocks = _renderScroll0.mocks,
|
|
960
|
+
handle = _renderScroll0.handle;
|
|
961
|
+
(0, _react.act)(function () {
|
|
962
|
+
handle.start({
|
|
963
|
+
targetX: 0,
|
|
964
|
+
targetY: 100
|
|
965
|
+
});
|
|
966
|
+
emitScroll(mocks.scrollContentRef.current);
|
|
967
|
+
emitScrollEnd(mocks.scrollContentRef.current);
|
|
968
|
+
});
|
|
969
|
+
expect(scrollStopOnScroll).not.toHaveBeenCalled();
|
|
970
|
+
});
|
|
971
|
+
test('should accept scrollend when the motion scroll is not running', function () {
|
|
972
|
+
var scrollStopOnScroll = jest.fn();
|
|
973
|
+
var _renderScroll1 = renderScroll({
|
|
974
|
+
scrollStopOnScroll: scrollStopOnScroll
|
|
975
|
+
}),
|
|
976
|
+
mocks = _renderScroll1.mocks;
|
|
977
|
+
(0, _react.act)(function () {
|
|
978
|
+
emitScroll(mocks.scrollContentRef.current);
|
|
979
|
+
emitScrollEnd(mocks.scrollContentRef.current);
|
|
980
|
+
});
|
|
981
|
+
expect(scrollStopOnScroll).toHaveBeenCalled();
|
|
982
|
+
});
|
|
983
|
+
test('should ignore scrollend while a key is held or the content is scrolling', function () {
|
|
984
|
+
var scrollStopOnScroll = jest.fn();
|
|
985
|
+
var _renderScroll10 = renderScroll({
|
|
986
|
+
scrollStopOnScroll: scrollStopOnScroll
|
|
987
|
+
}),
|
|
988
|
+
mocks = _renderScroll10.mocks;
|
|
989
|
+
emitScroll(mocks.scrollContentRef.current);
|
|
990
|
+
_react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
|
|
991
|
+
keyCode: 40,
|
|
992
|
+
repeat: true
|
|
993
|
+
});
|
|
994
|
+
emitScrollEnd(mocks.scrollContentRef.current);
|
|
995
|
+
expect(scrollStopOnScroll).not.toHaveBeenCalled();
|
|
996
|
+
_react.fireEvent.keyUp(mocks.scrollContainerRef.current, {
|
|
997
|
+
keyCode: 40
|
|
998
|
+
});
|
|
999
|
+
mocks.scrollContentHandle.current.scrolling = true;
|
|
1000
|
+
emitScrollEnd(mocks.scrollContentRef.current);
|
|
1001
|
+
expect(scrollStopOnScroll).not.toHaveBeenCalled();
|
|
1002
|
+
});
|
|
1003
|
+
test('should skip the native scroll when the content handle is gone', function () {
|
|
1004
|
+
var _renderScroll11 = renderScroll(),
|
|
1005
|
+
mocks = _renderScroll11.mocks,
|
|
1006
|
+
handle = _renderScroll11.handle;
|
|
1007
|
+
var inner = mocks.scrollContentHandle.current;
|
|
1008
|
+
var reads = 0;
|
|
1009
|
+
Object.defineProperty(mocks.scrollContentHandle, 'current', {
|
|
1010
|
+
configurable: true,
|
|
1011
|
+
get: function get() {
|
|
1012
|
+
reads += 1;
|
|
1013
|
+
return reads < 4 ? inner : null;
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
(0, _react.act)(function () {
|
|
1017
|
+
handle.start({
|
|
1018
|
+
targetX: 0,
|
|
1019
|
+
targetY: 100
|
|
1020
|
+
});
|
|
1021
|
+
});
|
|
1022
|
+
expect(inner.scrollToPosition).not.toHaveBeenCalled();
|
|
1023
|
+
});
|
|
1024
|
+
test('should skip a motion frame when the content handle is gone', function () {
|
|
1025
|
+
var _renderScroll12 = renderScroll({
|
|
1026
|
+
getScrollMotion: function getScrollMotion() {
|
|
1027
|
+
return token();
|
|
1028
|
+
}
|
|
1029
|
+
}),
|
|
1030
|
+
mocks = _renderScroll12.mocks,
|
|
1031
|
+
handle = _renderScroll12.handle;
|
|
1032
|
+
var scrollToPosition = mocks.scrollContentHandle.current.scrollToPosition;
|
|
1033
|
+
(0, _react.act)(function () {
|
|
1034
|
+
handle.start({
|
|
1035
|
+
targetX: 0,
|
|
1036
|
+
targetY: 100
|
|
1037
|
+
});
|
|
1038
|
+
});
|
|
1039
|
+
mocks.scrollContentHandle.current = null;
|
|
1040
|
+
(0, _react.act)(function () {
|
|
1041
|
+
next(1600);
|
|
1042
|
+
});
|
|
1043
|
+
expect(scrollToPosition).not.toHaveBeenCalled();
|
|
1044
|
+
});
|
|
1045
|
+
});
|
|
625
1046
|
});
|