@enact/ui 5.3.0 → 5.3.1
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 +6 -0
- package/package.json +3 -3
- package/useScroll/tests/useScroll-specs.js +79 -0
- package/useScroll/useScroll.js +23 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
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.1] - 2025-10-14
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `ui/Scroller` to calculate correctly targetX and targetY when scrolling to a position
|
|
10
|
+
|
|
5
11
|
## [5.3.0] - 2025-09-24
|
|
6
12
|
|
|
7
13
|
### Added
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/ui",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.1",
|
|
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.1",
|
|
36
|
+
"@enact/i18n": "^5.3.1",
|
|
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");
|
|
@@ -95,6 +97,21 @@ var useForceUpdate = function useForceUpdate() {
|
|
|
95
97
|
return x + 1;
|
|
96
98
|
}, 0);
|
|
97
99
|
};
|
|
100
|
+
function roundTarget(currentPosition, targetX, targetY) {
|
|
101
|
+
var roundedTargetX, roundedTargetY;
|
|
102
|
+
if (currentPosition !== null && currentPosition !== void 0 && currentPosition.scrollPos && _platform.platform.chrome > 120) {
|
|
103
|
+
var _currentPosition$scro, _currentPosition$scro2;
|
|
104
|
+
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);
|
|
105
|
+
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);
|
|
106
|
+
} else {
|
|
107
|
+
roundedTargetX = targetX;
|
|
108
|
+
roundedTargetY = targetY;
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
roundedTargetX: roundedTargetX,
|
|
112
|
+
roundedTargetY: roundedTargetY
|
|
113
|
+
};
|
|
114
|
+
}
|
|
98
115
|
|
|
99
116
|
/**
|
|
100
117
|
* A custom hook that passes scrollable behavior information as its render prop.
|
|
@@ -1126,10 +1143,13 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
|
|
|
1126
1143
|
}
|
|
1127
1144
|
} else {
|
|
1128
1145
|
// scrollMode 'native'
|
|
1146
|
+
var _roundTarget = roundTarget(scrollContentHandle.current, targetX, targetY),
|
|
1147
|
+
roundedTargetX = _roundTarget.roundedTargetX,
|
|
1148
|
+
roundedTargetY = _roundTarget.roundedTargetY;
|
|
1129
1149
|
if (animate) {
|
|
1130
|
-
scrollContentHandle.current.scrollToPosition(
|
|
1150
|
+
scrollContentHandle.current.scrollToPosition(roundedTargetX, roundedTargetY, 'smooth');
|
|
1131
1151
|
} else {
|
|
1132
|
-
scrollContentHandle.current.scrollToPosition(
|
|
1152
|
+
scrollContentHandle.current.scrollToPosition(roundedTargetX, roundedTargetY, 'instant');
|
|
1133
1153
|
}
|
|
1134
1154
|
if (props.start) {
|
|
1135
1155
|
props.start(animate);
|