@enact/ui 5.3.0 → 5.3.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 +10 -0
- package/package.json +3 -3
- package/useScroll/tests/useScroll-specs.js +79 -0
- package/useScroll/useScroll.js +37 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
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.3.2] - 2025-10-28
|
|
6
|
+
|
|
7
|
+
No significant changes.
|
|
8
|
+
|
|
9
|
+
## [5.3.1] - 2025-10-14
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- `ui/Scroller` to calculate correctly targetX and targetY when scrolling to a position
|
|
14
|
+
|
|
5
15
|
## [5.3.0] - 2025-09-24
|
|
6
16
|
|
|
7
17
|
### Added
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/ui",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.2",
|
|
4
4
|
"description": "A collection of simplified unstyled cross-platform UI components for Enact",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@enact/core": "^5.3.
|
|
36
|
-
"@enact/i18n": "^5.3.
|
|
35
|
+
"@enact/core": "^5.3.2",
|
|
36
|
+
"@enact/i18n": "^5.3.2",
|
|
37
37
|
"classnames": "^2.5.1",
|
|
38
38
|
"ilib": "^14.21.1",
|
|
39
39
|
"invariant": "^2.2.4",
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
|
+
describe('useScroll', function () {
|
|
5
|
+
describe('Rounding target scroll position', function () {
|
|
6
|
+
beforeEach(function () {
|
|
7
|
+
jest.resetModules(); // important! clears cached modules
|
|
8
|
+
});
|
|
9
|
+
test('should round target position upwards when target is bigger than current position', function () {
|
|
10
|
+
jest.doMock('@enact/core/platform', function () {
|
|
11
|
+
return {
|
|
12
|
+
__esModule: true,
|
|
13
|
+
platform: {
|
|
14
|
+
chrome: 132
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
var _require = require('../useScroll'),
|
|
19
|
+
roundTarget = _require.roundTarget;
|
|
20
|
+
var currentPosition = {
|
|
21
|
+
scrollPos: {
|
|
22
|
+
left: 100,
|
|
23
|
+
top: 100
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var _roundTarget = roundTarget(currentPosition, 120.5, 120.4),
|
|
27
|
+
roundedTargetX = _roundTarget.roundedTargetX,
|
|
28
|
+
roundedTargetY = _roundTarget.roundedTargetY;
|
|
29
|
+
expect(roundedTargetX).toEqual(121);
|
|
30
|
+
expect(roundedTargetY).toEqual(121);
|
|
31
|
+
});
|
|
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
|
+
});
|
|
41
|
+
var _require2 = require('../useScroll'),
|
|
42
|
+
roundTarget = _require2.roundTarget;
|
|
43
|
+
var currentPosition = {
|
|
44
|
+
scrollPos: {
|
|
45
|
+
left: 100,
|
|
46
|
+
top: 100
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var _roundTarget2 = roundTarget(currentPosition, 90.4, 80.8),
|
|
50
|
+
roundedTargetX = _roundTarget2.roundedTargetX,
|
|
51
|
+
roundedTargetY = _roundTarget2.roundedTargetY;
|
|
52
|
+
expect(roundedTargetX).toEqual(90);
|
|
53
|
+
expect(roundedTargetY).toEqual(80);
|
|
54
|
+
});
|
|
55
|
+
test('should not round target position when chrome <= 120', function () {
|
|
56
|
+
jest.doMock('@enact/core/platform', function () {
|
|
57
|
+
return {
|
|
58
|
+
__esModule: true,
|
|
59
|
+
platform: {
|
|
60
|
+
chrome: 119
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
var _require3 = require('../useScroll'),
|
|
65
|
+
roundTarget = _require3.roundTarget;
|
|
66
|
+
var currentPosition = {
|
|
67
|
+
scrollPos: {
|
|
68
|
+
left: 100,
|
|
69
|
+
top: 100
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var _roundTarget3 = roundTarget(currentPosition, 90.4, 80.8),
|
|
73
|
+
roundedTargetX = _roundTarget3.roundedTargetX,
|
|
74
|
+
roundedTargetY = _roundTarget3.roundedTargetY;
|
|
75
|
+
expect(roundedTargetX).toEqual(90.4);
|
|
76
|
+
expect(roundedTargetY).toEqual(80.8);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
package/useScroll/useScroll.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = exports.constants = exports.assignPropertiesOf = void 0;
|
|
7
|
+
exports.roundTarget = roundTarget;
|
|
8
|
+
exports.useScrollBase = exports.useScroll = void 0;
|
|
7
9
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
10
|
var _handle = require("@enact/core/handle");
|
|
9
11
|
var _keymap = require("@enact/core/keymap");
|
|
@@ -96,6 +98,35 @@ var useForceUpdate = function useForceUpdate() {
|
|
|
96
98
|
}, 0);
|
|
97
99
|
};
|
|
98
100
|
|
|
101
|
+
/*
|
|
102
|
+
* Rounds the target positions based on scroll direction, if Chrome version is > 120
|
|
103
|
+
* Chrome 121+ introduced a new way to calculate target pixel position, based on the subunit value of target position
|
|
104
|
+
*
|
|
105
|
+
* @function
|
|
106
|
+
* @param {Object} currentPosition current scroll position
|
|
107
|
+
* @param {Number} targetX target X axis position
|
|
108
|
+
* @param {Number} targetY target Y axis position
|
|
109
|
+
*
|
|
110
|
+
* @returns {Object}
|
|
111
|
+
* @memberof ui/useScroll
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
function roundTarget(currentPosition, targetX, targetY) {
|
|
115
|
+
var roundedTargetX, roundedTargetY;
|
|
116
|
+
if (currentPosition !== null && currentPosition !== void 0 && currentPosition.scrollPos && _platform.platform.chrome > 120) {
|
|
117
|
+
var _currentPosition$scro, _currentPosition$scro2;
|
|
118
|
+
roundedTargetX = (currentPosition === null || currentPosition === void 0 || (_currentPosition$scro = currentPosition.scrollPos) === null || _currentPosition$scro === void 0 ? void 0 : _currentPosition$scro.left) < targetX ? Math.ceil(targetX) : Math.floor(targetX);
|
|
119
|
+
roundedTargetY = (currentPosition === null || currentPosition === void 0 || (_currentPosition$scro2 = currentPosition.scrollPos) === null || _currentPosition$scro2 === void 0 ? void 0 : _currentPosition$scro2.top) < targetY ? Math.ceil(targetY) : Math.floor(targetY);
|
|
120
|
+
} else {
|
|
121
|
+
roundedTargetX = targetX;
|
|
122
|
+
roundedTargetY = targetY;
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
roundedTargetX: roundedTargetX,
|
|
126
|
+
roundedTargetY: roundedTargetY
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
99
130
|
/**
|
|
100
131
|
* A custom hook that passes scrollable behavior information as its render prop.
|
|
101
132
|
*
|
|
@@ -1126,10 +1157,13 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
|
|
|
1126
1157
|
}
|
|
1127
1158
|
} else {
|
|
1128
1159
|
// scrollMode 'native'
|
|
1160
|
+
var _roundTarget = roundTarget(scrollContentHandle.current, targetX, targetY),
|
|
1161
|
+
roundedTargetX = _roundTarget.roundedTargetX,
|
|
1162
|
+
roundedTargetY = _roundTarget.roundedTargetY;
|
|
1129
1163
|
if (animate) {
|
|
1130
|
-
scrollContentHandle.current.scrollToPosition(
|
|
1164
|
+
scrollContentHandle.current.scrollToPosition(roundedTargetX, roundedTargetY, 'smooth');
|
|
1131
1165
|
} else {
|
|
1132
|
-
scrollContentHandle.current.scrollToPosition(
|
|
1166
|
+
scrollContentHandle.current.scrollToPosition(roundedTargetX, roundedTargetY, 'instant');
|
|
1133
1167
|
}
|
|
1134
1168
|
if (props.start) {
|
|
1135
1169
|
props.start(animate);
|