@enact/ui 4.5.2 → 4.5.4
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 +1 -40
- package/AnnounceDecorator/AnnounceDecorator.js +3 -21
- package/AnnounceDecorator/tests/Announce-specs.js +2 -7
- package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +2 -6
- package/AnnounceDecorator/tests/useAnnounce-specs.js +8 -19
- package/AnnounceDecorator/useAnnounce.js +0 -6
- package/BodyText/BodyText.js +6 -26
- package/BodyText/tests/BodyText-specs.js +0 -19
- package/Button/Button.js +26 -56
- package/Button/tests/Button-specs.js +0 -26
- package/CHANGELOG.md +10 -0
- package/Cancelable/Cancelable.js +8 -47
- package/Cancelable/cancelHandler.js +5 -12
- package/Cancelable/modalHandler.js +3 -11
- package/Cancelable/tests/Cancelable-specs.js +3 -57
- package/Changeable/Changeable.js +2 -34
- package/Changeable/tests/Changeable-specs.js +20 -66
- package/ComponentOverride/ComponentOverride.js +1 -13
- package/FloatingLayer/FloatingLayer.js +17 -73
- package/FloatingLayer/FloatingLayerContainer.js +0 -15
- package/FloatingLayer/FloatingLayerDecorator.js +4 -17
- package/FloatingLayer/Scrim.js +9 -53
- package/FloatingLayer/index.js +0 -4
- package/FloatingLayer/tests/FloatingLayer-specs.js +8 -22
- package/FloatingLayer/tests/Scrim-specs.js +0 -9
- package/FloatingLayer/tests/useFloatingLayerDecorator-specs.js +0 -13
- package/FloatingLayer/useFloatingLayer.js +3 -14
- package/FloatingLayer/useFloatingLayerDecorator.js +3 -11
- package/ForwardRef/ForwardRef.js +1 -10
- package/GridListImageItem/GridListImageItem.js +17 -50
- package/Group/Group.js +4 -35
- package/Group/GroupItem.js +15 -32
- package/Group/tests/Group-specs.js +0 -32
- package/Heading/Heading.js +7 -35
- package/Heading/tests/Heading-specs.js +81 -14
- package/Icon/Icon.js +14 -48
- package/Icon/tests/Icon-specs.js +0 -22
- package/IconButton/IconButton.js +12 -50
- package/IconButton/tests/IconButton-specs.js +0 -7
- package/Image/Image.js +16 -45
- package/Image/tests/Image-specs.js +0 -14
- package/ImageItem/ImageItem.js +17 -46
- package/ImageItem/tests/ImageItem-specs.js +0 -25
- package/Item/Item.js +8 -32
- package/Item/tests/Item-specs.js +0 -24
- package/LabeledIcon/LabeledIcon.js +19 -50
- package/LabeledIcon/tests/LabeledIcon-specs.js +0 -14
- package/Layout/Cell.js +11 -37
- package/Layout/Layout.js +14 -37
- package/Layout/tests/Layout-specs.js +10 -39
- package/Marquee/MarqueeBase.js +29 -63
- package/Marquee/MarqueeController.js +11 -72
- package/Marquee/MarqueeDecorator.js +62 -196
- package/Marquee/index.js +1 -5
- package/Marquee/tests/Marquee-specs.js +258 -87
- package/Measurable/Measurable.js +12 -34
- package/Measurable/tests/Measurable-specs.js +115 -0
- package/Media/Media.js +15 -65
- package/Media/tests/Media-specs.js +168 -0
- package/Placeholder/PlaceholderControllerDecorator.js +7 -43
- package/Placeholder/PlaceholderDecorator.js +7 -38
- package/Placeholder/index.js +0 -4
- package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +25 -0
- package/Placeholder/tests/PlaceholderDecorator-specs.js +28 -0
- package/ProgressBar/ProgressBar.js +13 -44
- package/ProgressBar/tests/ProgressBar-specs.js +0 -17
- package/RadioDecorator/RadioControllerDecorator.js +1 -29
- package/RadioDecorator/RadioDecorator.js +4 -42
- package/RadioDecorator/tests/RadioDecorator-specs.js +12 -49
- package/Repeater/Repeater.js +9 -33
- package/Repeater/tests/Repeater-specs.js +0 -38
- package/Resizable/Resizable.js +7 -35
- package/Resizable/tests/Resizable-specs.js +34 -0
- package/Routable/Link.js +8 -44
- package/Routable/Routable.js +10 -33
- package/Routable/Route.js +0 -6
- package/Routable/Router.js +13 -56
- package/Routable/tests/Routable-specs.js +7 -33
- package/Routable/tests/Router-specs.js +18 -44
- package/Routable/useLink.js +4 -8
- package/Routable/util.js +18 -24
- package/Scrollable/ScrollAnimator.js +49 -65
- package/Scrollable/ScrollThumb.js +2 -13
- package/Scrollable/Scrollable.js +179 -386
- package/Scrollable/ScrollableNative.js +188 -391
- package/Scrollable/Scrollbar.js +28 -100
- package/Scroller/Scroller.js +15 -39
- package/Scroller/ScrollerBasic.js +34 -89
- package/Scroller/UiScrollerBase.js +31 -84
- package/Skinnable/Skinnable.js +11 -38
- package/Skinnable/tests/Skinnable-specs.js +3 -74
- package/Skinnable/tests/useSkins-specs.js +1 -13
- package/Skinnable/tests/util-specs.js +0 -14
- package/Skinnable/useSkins.js +8 -15
- package/Skinnable/util.js +9 -20
- package/Slider/Knob.js +5 -24
- package/Slider/PositionDecorator.js +16 -54
- package/Slider/Slider.js +26 -64
- package/Slider/tests/Slider-specs.js +94 -7
- package/Slider/utils.js +0 -2
- package/SlotItem/SlotItem.js +15 -41
- package/SlotItem/tests/SlotItem-specs.js +0 -5
- package/Slottable/Slottable.js +4 -12
- package/Slottable/tests/Slottable-specs.js +19 -46
- package/Slottable/tests/useSlots-specs.js +27 -65
- package/Slottable/useSlots.js +8 -33
- package/Spinner/Spinner.js +15 -42
- package/Spinner/tests/Spinner-specs.js +0 -15
- package/ToggleIcon/ToggleIcon.js +10 -36
- package/ToggleIcon/tests/ToggleIcon-specs.js +0 -16
- package/ToggleItem/ToggleItem.js +15 -52
- package/ToggleItem/tests/ToggleItem-specs.js +0 -30
- package/Toggleable/Toggle.js +1 -15
- package/Toggleable/Toggleable.js +12 -45
- package/Toggleable/tests/Toggleable-specs.js +28 -96
- package/Toggleable/useToggle.js +3 -19
- package/Touchable/ClickAllow.js +5 -14
- package/Touchable/Drag.js +16 -54
- package/Touchable/Flick.js +11 -42
- package/Touchable/Hold.js +21 -68
- package/Touchable/Touch.js +37 -65
- package/Touchable/Touchable.js +32 -71
- package/Touchable/config.js +8 -22
- package/Touchable/tests/Touchable-specs.js +270 -119
- package/Touchable/tests/useTouch-specs.js +6 -80
- package/Touchable/useTouch.js +17 -34
- package/Transition/Transition.js +37 -118
- package/Transition/tests/Transition-specs.js +20 -60
- package/ViewManager/Arranger.js +10 -22
- package/ViewManager/TransitionGroup.js +31 -106
- package/ViewManager/View.js +35 -91
- package/ViewManager/ViewManager.js +19 -83
- package/ViewManager/tests/View-specs.js +0 -17
- package/ViewManager/tests/ViewManager-specs.js +236 -305
- package/ViewManager/tests/test-utils.js +0 -8
- package/VirtualList/UiVirtualListBase.js +256 -406
- package/VirtualList/VirtualList.js +29 -69
- package/VirtualList/VirtualListBase.js +0 -3
- package/VirtualList/VirtualListBasic.js +270 -428
- package/VirtualList/tests/VirtualList-specs.js +9 -37
- package/internal/IdProvider/IdProvider.js +7 -21
- package/internal/IdProvider/Provider.js +4 -17
- package/internal/IdProvider/tests/IdProvider-specs.js +44 -0
- package/internal/IdProvider/tests/useId-specs.js +7 -22
- package/internal/IdProvider/useId.js +0 -6
- package/internal/Pure/Pure.js +3 -30
- package/internal/Pure/tests/Pure-specs.js +88 -0
- package/internal/localized-fonts/localized-fonts.js +33 -62
- package/internal/localized-fonts/tests/localized-fonts-specs.js +33 -0
- package/internal/selection/selection.js +1 -6
- package/internal/selection/tests/selection-specs.js +6 -4
- package/internal/validators/tests/validators-specs.js +80 -0
- package/internal/validators/validators.js +14 -34
- package/package.json +8 -2
- package/resolution/ResolutionDecorator.js +4 -40
- package/resolution/index.js +0 -7
- package/resolution/resolution.js +42 -80
- package/resolution/tests/ResolutionDecorator-specs.js +4 -11
- package/resolution/tests/resolution-specs.js +2 -2
- package/useControlledState/tests/useControlledState-specs.js +15 -46
- package/useControlledState/useControlledState.js +11 -22
- package/useScroll/ScrollAnimator.js +49 -65
- package/useScroll/Scrollbar.js +22 -58
- package/useScroll/ScrollbarTrack.js +3 -19
- package/useScroll/useScroll.js +325 -502
- package/useScroll/utilDOM.js +8 -14
- package/useScroll/utilEvent.js +0 -4
package/useScroll/useScroll.js
CHANGED
|
@@ -4,122 +4,88 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useScrollBase = exports.useScroll = exports["default"] = exports.constants = exports.assignPropertiesOf = void 0;
|
|
7
|
-
|
|
8
7
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
-
|
|
10
8
|
var _handle = require("@enact/core/handle");
|
|
11
|
-
|
|
12
9
|
var _keymap = require("@enact/core/keymap");
|
|
13
|
-
|
|
14
10
|
var _platform = require("@enact/core/platform");
|
|
15
|
-
|
|
16
11
|
var _Registry = _interopRequireDefault(require("@enact/core/internal/Registry"));
|
|
17
|
-
|
|
18
12
|
var _util = require("@enact/core/util");
|
|
19
|
-
|
|
20
13
|
var _clamp = _interopRequireDefault(require("ramda/src/clamp"));
|
|
21
|
-
|
|
22
14
|
var _react = require("react");
|
|
23
|
-
|
|
24
15
|
var _warning = _interopRequireDefault(require("warning"));
|
|
25
|
-
|
|
26
16
|
var _ForwardRef = _interopRequireDefault(require("../ForwardRef"));
|
|
27
|
-
|
|
28
17
|
var _Resizable = require("../Resizable");
|
|
29
|
-
|
|
30
18
|
var _resolution = _interopRequireDefault(require("../resolution"));
|
|
31
|
-
|
|
32
19
|
var _Touchable = _interopRequireDefault(require("../Touchable"));
|
|
33
|
-
|
|
34
20
|
var _ScrollAnimator = _interopRequireDefault(require("./ScrollAnimator"));
|
|
35
|
-
|
|
36
21
|
var _utilDOM = _interopRequireDefault(require("./utilDOM"));
|
|
37
|
-
|
|
38
22
|
var _utilEvent = _interopRequireDefault(require("./utilEvent"));
|
|
39
|
-
|
|
40
23
|
var _useScrollModule = _interopRequireDefault(require("./useScroll.module.css"));
|
|
41
|
-
|
|
42
24
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
43
|
-
|
|
44
25
|
var _excluded = ["componentRef"],
|
|
45
|
-
|
|
46
|
-
|
|
26
|
+
_excluded2 = ["childProps", "children", "className", "clientSize", "assignProperties", "dataSize", "direction", "horizontalScrollbar", "horizontalScrollbarHandle", "itemRenderer", "itemSize", "itemSizes", "noScrollByDrag", "noScrollByWheel", "overhang", "overscrollEffectOn", "pageScroll", "role", "rtl", "scrollContainerRef", "scrollContentHandle", "scrollContentRef", "scrollMode", "setScrollContainerHandle", "snapToCenter", "spacing", "spotlightContainerDisabled", "verticalScrollbar", "verticalScrollbarHandle", "wrap"];
|
|
47
27
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
48
|
-
|
|
49
28
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
50
|
-
|
|
51
29
|
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."); }
|
|
52
|
-
|
|
53
30
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
54
|
-
|
|
55
31
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
56
|
-
|
|
57
32
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
58
|
-
|
|
59
33
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
60
|
-
|
|
61
34
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
62
|
-
|
|
63
35
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
64
|
-
|
|
65
36
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
66
|
-
|
|
67
37
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
68
|
-
|
|
69
38
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
70
|
-
|
|
71
39
|
var constants = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
40
|
+
animationDuration: 1000,
|
|
41
|
+
epsilon: 1,
|
|
42
|
+
flickConfig: {
|
|
43
|
+
maxDuration: null
|
|
44
|
+
},
|
|
45
|
+
isPageDown: (0, _keymap.is)('pageDown'),
|
|
46
|
+
isPageUp: (0, _keymap.is)('pageUp'),
|
|
47
|
+
nop: function nop() {},
|
|
48
|
+
overscrollDefaultRatio: 0.5,
|
|
49
|
+
overscrollTypeNone: 0,
|
|
50
|
+
overscrollTypeHold: 1,
|
|
51
|
+
overscrollTypeOnce: 2,
|
|
52
|
+
overscrollTypeDone: 9,
|
|
53
|
+
overscrollVelocityFactor: 300,
|
|
54
|
+
// scrollMode 'native'
|
|
55
|
+
paginationPageMultiplier: 0.66,
|
|
56
|
+
scrollStopWaiting: 200,
|
|
57
|
+
scrollWheelPageMultiplierForMaxPixel: 0.2 // The ratio of the maximum distance scrolled by wheel to the size of the viewport.
|
|
76
58
|
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
animationDuration = constants.animationDuration,
|
|
93
|
-
epsilon = constants.epsilon,
|
|
94
|
-
flickConfig = constants.flickConfig,
|
|
95
|
-
isPageDown = constants.isPageDown,
|
|
96
|
-
isPageUp = constants.isPageUp,
|
|
97
|
-
overscrollDefaultRatio = constants.overscrollDefaultRatio,
|
|
98
|
-
overscrollTypeDone = constants.overscrollTypeDone,
|
|
99
|
-
overscrollTypeHold = constants.overscrollTypeHold,
|
|
100
|
-
overscrollTypeNone = constants.overscrollTypeNone,
|
|
101
|
-
overscrollTypeOnce = constants.overscrollTypeOnce,
|
|
102
|
-
overscrollVelocityFactor = constants.overscrollVelocityFactor,
|
|
103
|
-
paginationPageMultiplier = constants.paginationPageMultiplier,
|
|
104
|
-
scrollStopWaiting = constants.scrollStopWaiting,
|
|
105
|
-
scrollWheelPageMultiplierForMaxPixel = constants.scrollWheelPageMultiplierForMaxPixel;
|
|
59
|
+
animationDuration = constants.animationDuration,
|
|
60
|
+
epsilon = constants.epsilon,
|
|
61
|
+
flickConfig = constants.flickConfig,
|
|
62
|
+
isPageDown = constants.isPageDown,
|
|
63
|
+
isPageUp = constants.isPageUp,
|
|
64
|
+
overscrollDefaultRatio = constants.overscrollDefaultRatio,
|
|
65
|
+
overscrollTypeDone = constants.overscrollTypeDone,
|
|
66
|
+
overscrollTypeHold = constants.overscrollTypeHold,
|
|
67
|
+
overscrollTypeNone = constants.overscrollTypeNone,
|
|
68
|
+
overscrollTypeOnce = constants.overscrollTypeOnce,
|
|
69
|
+
overscrollVelocityFactor = constants.overscrollVelocityFactor,
|
|
70
|
+
paginationPageMultiplier = constants.paginationPageMultiplier,
|
|
71
|
+
scrollStopWaiting = constants.scrollStopWaiting,
|
|
72
|
+
scrollWheelPageMultiplierForMaxPixel = constants.scrollWheelPageMultiplierForMaxPixel;
|
|
106
73
|
exports.constants = constants;
|
|
107
74
|
var TouchableDiv = (0, _ForwardRef["default"])({
|
|
108
75
|
prop: 'componentRef'
|
|
109
76
|
}, (0, _Touchable["default"])(function (_ref) {
|
|
110
77
|
var componentRef = _ref.componentRef,
|
|
111
|
-
|
|
112
|
-
|
|
78
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
113
79
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
|
|
114
80
|
ref: componentRef
|
|
115
81
|
}));
|
|
116
82
|
}));
|
|
117
|
-
|
|
118
83
|
var useForceUpdate = function useForceUpdate() {
|
|
119
84
|
return (0, _react.useReducer)(function (x) {
|
|
120
85
|
return x + 1;
|
|
121
86
|
}, 0);
|
|
122
87
|
};
|
|
88
|
+
|
|
123
89
|
/**
|
|
124
90
|
* A custom hook that passes scrollable behavior information as its render prop.
|
|
125
91
|
*
|
|
@@ -128,45 +94,43 @@ var useForceUpdate = function useForceUpdate() {
|
|
|
128
94
|
* @ui
|
|
129
95
|
* @private
|
|
130
96
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
97
|
var useScrollBase = function useScrollBase(props) {
|
|
134
98
|
var childProps = props.childProps,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
99
|
+
children = props.children,
|
|
100
|
+
className = props.className,
|
|
101
|
+
clientSize = props.clientSize,
|
|
102
|
+
assignProperties = props.assignProperties,
|
|
103
|
+
dataSize = props.dataSize,
|
|
104
|
+
direction = props.direction,
|
|
105
|
+
horizontalScrollbar = props.horizontalScrollbar,
|
|
106
|
+
horizontalScrollbarHandle = props.horizontalScrollbarHandle,
|
|
107
|
+
itemRenderer = props.itemRenderer,
|
|
108
|
+
itemSize = props.itemSize,
|
|
109
|
+
itemSizes = props.itemSizes,
|
|
110
|
+
noScrollByDrag = props.noScrollByDrag,
|
|
111
|
+
noScrollByWheel = props.noScrollByWheel,
|
|
112
|
+
overhang = props.overhang,
|
|
113
|
+
overscrollEffectOn = props.overscrollEffectOn,
|
|
114
|
+
pageScroll = props.pageScroll,
|
|
115
|
+
role = props.role,
|
|
116
|
+
rtl = props.rtl,
|
|
117
|
+
scrollContainerRef = props.scrollContainerRef,
|
|
118
|
+
scrollContentHandle = props.scrollContentHandle,
|
|
119
|
+
scrollContentRef = props.scrollContentRef,
|
|
120
|
+
scrollMode = props.scrollMode,
|
|
121
|
+
setScrollContainerHandle = props.setScrollContainerHandle,
|
|
122
|
+
snapToCenter = props.snapToCenter,
|
|
123
|
+
spacing = props.spacing,
|
|
124
|
+
spotlightContainerDisabled = props.spotlightContainerDisabled,
|
|
125
|
+
verticalScrollbar = props.verticalScrollbar,
|
|
126
|
+
verticalScrollbarHandle = props.verticalScrollbarHandle,
|
|
127
|
+
wrap = props.wrap,
|
|
128
|
+
rest = _objectWithoutProperties(props, _excluded2),
|
|
129
|
+
scrollClasses = (0, _classnames["default"])(_useScrollModule["default"].scroll, className);
|
|
130
|
+
|
|
131
|
+
// The following props are the one having the same naming function in this scope.
|
|
166
132
|
// So it is better to use props[propName]
|
|
167
133
|
// instead of extracting it from the `props` and renaming it
|
|
168
|
-
|
|
169
|
-
|
|
170
134
|
delete rest.addEventListeners;
|
|
171
135
|
delete rest.applyOverscrollEffect;
|
|
172
136
|
delete rest.cbScrollTo;
|
|
@@ -181,29 +145,24 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
181
145
|
delete rest.onWheel;
|
|
182
146
|
delete rest.removeEventListeners;
|
|
183
147
|
delete rest.scrollStopOnScroll; // scrollMode 'native'
|
|
184
|
-
|
|
185
148
|
delete rest.scrollTo;
|
|
186
149
|
delete rest.start; // scrollMode 'native'
|
|
187
|
-
|
|
188
150
|
delete rest.stop; // scrollMode 'translate'
|
|
151
|
+
|
|
189
152
|
// Mutable value and Hooks
|
|
190
153
|
|
|
191
154
|
var _useForceUpdate = useForceUpdate(),
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
155
|
+
_useForceUpdate2 = _slicedToArray(_useForceUpdate, 2),
|
|
156
|
+
forceUpdate = _useForceUpdate2[1];
|
|
195
157
|
var context = (0, _react.useContext)(_Resizable.ResizeContext);
|
|
196
|
-
|
|
197
158
|
var _useState = (0, _react.useState)(horizontalScrollbar === 'visible'),
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
159
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
160
|
+
isHorizontalScrollbarVisible = _useState2[0],
|
|
161
|
+
setIsHorizontalScrollbarVisible = _useState2[1];
|
|
202
162
|
var _useState3 = (0, _react.useState)(verticalScrollbar === 'visible'),
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
163
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
164
|
+
isVerticalScrollbarVisible = _useState4[0],
|
|
165
|
+
setIsVerticalScrollbarVisible = _useState4[1];
|
|
207
166
|
var mutableRef = (0, _react.useRef)({
|
|
208
167
|
overscrollEnabled: !!props.applyOverscrollEffect,
|
|
209
168
|
// Enable the early bail out of repeated scrolling to the same position
|
|
@@ -213,6 +172,7 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
213
172
|
pixelPerLine: 39,
|
|
214
173
|
scrollWheelMultiplierForDeltaPixel: 1.5,
|
|
215
174
|
// The ratio of wheel 'delta' units to pixels scrolled.
|
|
175
|
+
|
|
216
176
|
// status
|
|
217
177
|
deferScrollTo: true,
|
|
218
178
|
isScrollAnimationTargetAccumulated: false,
|
|
@@ -254,6 +214,7 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
254
214
|
isDragging: false,
|
|
255
215
|
isTouching: false,
|
|
256
216
|
// scrollMode 'native'
|
|
217
|
+
|
|
257
218
|
// scroll info
|
|
258
219
|
scrolling: false,
|
|
259
220
|
scrollLeft: 0,
|
|
@@ -276,92 +237,82 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
276
237
|
}
|
|
277
238
|
});
|
|
278
239
|
|
|
240
|
+
/* istanbul ignore next */
|
|
241
|
+
var themeScrollContainerHandle = (0, _react.useRef)({
|
|
242
|
+
get animator() {
|
|
243
|
+
return mutableRef.current.animator;
|
|
244
|
+
},
|
|
245
|
+
get bounds() {
|
|
246
|
+
return mutableRef.current.bounds;
|
|
247
|
+
},
|
|
248
|
+
get isDragging() {
|
|
249
|
+
return mutableRef.current.isDragging;
|
|
250
|
+
},
|
|
251
|
+
set isDragging(val) {
|
|
252
|
+
mutableRef.current.isDragging = val;
|
|
253
|
+
},
|
|
254
|
+
get isScrollAnimationTargetAccumulated() {
|
|
255
|
+
return mutableRef.current.isScrollAnimationTargetAccumulated;
|
|
256
|
+
},
|
|
257
|
+
set isScrollAnimationTargetAccumulated(val) {
|
|
258
|
+
mutableRef.current.isScrollAnimationTargetAccumulated = val;
|
|
259
|
+
},
|
|
260
|
+
get lastInputType() {
|
|
261
|
+
return mutableRef.current.lastInputType;
|
|
262
|
+
},
|
|
263
|
+
set lastInputType(val) {
|
|
264
|
+
mutableRef.current.lastInputType = val;
|
|
265
|
+
},
|
|
266
|
+
get rtl() {
|
|
267
|
+
return rtl;
|
|
268
|
+
},
|
|
269
|
+
get scrollBounds() {
|
|
270
|
+
return getScrollBounds();
|
|
271
|
+
},
|
|
272
|
+
get scrollHeight() {
|
|
273
|
+
return mutableRef.current.bounds.scrollHeight;
|
|
274
|
+
},
|
|
275
|
+
get scrolling() {
|
|
276
|
+
return mutableRef.current.scrolling;
|
|
277
|
+
},
|
|
278
|
+
get scrollLeft() {
|
|
279
|
+
return mutableRef.current.scrollLeft;
|
|
280
|
+
},
|
|
281
|
+
get scrollToInfo() {
|
|
282
|
+
return mutableRef.current.scrollToInfo;
|
|
283
|
+
},
|
|
284
|
+
get scrollTop() {
|
|
285
|
+
return mutableRef.current.scrollTop;
|
|
286
|
+
},
|
|
287
|
+
get wheelDirection() {
|
|
288
|
+
return mutableRef.current.wheelDirection;
|
|
289
|
+
},
|
|
290
|
+
set wheelDirection(val) {
|
|
291
|
+
mutableRef.current.wheelDirection = val;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
279
294
|
if (mutableRef.current.animator == null) {
|
|
280
295
|
mutableRef.current.animator = new _ScrollAnimator["default"]();
|
|
281
296
|
}
|
|
282
|
-
|
|
283
297
|
(0, _react.useLayoutEffect)(function () {
|
|
298
|
+
/* istanbul ignore next */
|
|
284
299
|
if (setScrollContainerHandle) {
|
|
285
|
-
|
|
286
|
-
animator: mutableRef.current.animator,
|
|
300
|
+
Object.assign(themeScrollContainerHandle.current, {
|
|
287
301
|
applyOverscrollEffect: applyOverscrollEffect,
|
|
288
|
-
bounds: mutableRef.current.bounds,
|
|
289
302
|
calculateDistanceByWheel: calculateDistanceByWheel,
|
|
290
303
|
canScrollHorizontally: canScrollHorizontally,
|
|
291
304
|
canScrollVertically: canScrollVertically,
|
|
292
305
|
checkAndApplyOverscrollEffect: checkAndApplyOverscrollEffect,
|
|
293
306
|
getScrollBounds: getScrollBounds,
|
|
294
|
-
|
|
295
|
-
get isDragging() {
|
|
296
|
-
return mutableRef.current.isDragging;
|
|
297
|
-
},
|
|
298
|
-
|
|
299
|
-
set isDragging(val) {
|
|
300
|
-
mutableRef.current.isDragging = val;
|
|
301
|
-
},
|
|
302
|
-
|
|
303
|
-
get isScrollAnimationTargetAccumulated() {
|
|
304
|
-
return mutableRef.current.isScrollAnimationTargetAccumulated;
|
|
305
|
-
},
|
|
306
|
-
|
|
307
|
-
set isScrollAnimationTargetAccumulated(val) {
|
|
308
|
-
mutableRef.current.isScrollAnimationTargetAccumulated = val;
|
|
309
|
-
},
|
|
310
|
-
|
|
311
|
-
get lastInputType() {
|
|
312
|
-
return mutableRef.current.lastInputType;
|
|
313
|
-
},
|
|
314
|
-
|
|
315
|
-
set lastInputType(val) {
|
|
316
|
-
mutableRef.current.lastInputType = val;
|
|
317
|
-
},
|
|
318
|
-
|
|
319
|
-
get rtl() {
|
|
320
|
-
return rtl;
|
|
321
|
-
},
|
|
322
|
-
|
|
323
|
-
get scrollBounds() {
|
|
324
|
-
return getScrollBounds();
|
|
325
|
-
},
|
|
326
|
-
|
|
327
|
-
get scrollHeight() {
|
|
328
|
-
return mutableRef.current.bounds.scrollHeight;
|
|
329
|
-
},
|
|
330
|
-
|
|
331
|
-
get scrolling() {
|
|
332
|
-
return mutableRef.current.scrolling;
|
|
333
|
-
},
|
|
334
|
-
|
|
335
|
-
get scrollLeft() {
|
|
336
|
-
return mutableRef.current.scrollLeft;
|
|
337
|
-
},
|
|
338
|
-
|
|
339
307
|
scrollTo: scrollTo,
|
|
340
308
|
scrollToAccumulatedTarget: scrollToAccumulatedTarget,
|
|
341
|
-
|
|
342
|
-
get scrollToInfo() {
|
|
343
|
-
return mutableRef.current.scrollToInfo;
|
|
344
|
-
},
|
|
345
|
-
|
|
346
|
-
get scrollTop() {
|
|
347
|
-
return mutableRef.current.scrollTop;
|
|
348
|
-
},
|
|
349
|
-
|
|
350
309
|
setOverscrollStatus: setOverscrollStatus,
|
|
351
310
|
showScrollbarTrack: showScrollbarTrack,
|
|
352
311
|
start: start,
|
|
353
312
|
startHidingScrollbarTrack: startHidingScrollbarTrack,
|
|
354
|
-
stop: stop
|
|
355
|
-
|
|
356
|
-
get wheelDirection() {
|
|
357
|
-
return mutableRef.current.wheelDirection;
|
|
358
|
-
},
|
|
359
|
-
|
|
360
|
-
set wheelDirection(val) {
|
|
361
|
-
mutableRef.current.wheelDirection = val;
|
|
362
|
-
}
|
|
363
|
-
|
|
313
|
+
stop: stop
|
|
364
314
|
});
|
|
315
|
+
setScrollContainerHandle(themeScrollContainerHandle.current);
|
|
365
316
|
}
|
|
366
317
|
});
|
|
367
318
|
(0, _react.useLayoutEffect)(function () {
|
|
@@ -372,11 +323,9 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
372
323
|
|
|
373
324
|
(0, _react.useLayoutEffect)(function () {
|
|
374
325
|
var containerRef = scrollContainerRef.current;
|
|
375
|
-
|
|
376
326
|
if (!containerRef) {
|
|
377
327
|
return;
|
|
378
328
|
}
|
|
379
|
-
|
|
380
329
|
if (typeof ResizeObserver === 'function') {
|
|
381
330
|
var resizeObserver = new ResizeObserver(function () {
|
|
382
331
|
if (scrollContentHandle.current && scrollContentHandle.current.syncClientSize) {
|
|
@@ -394,27 +343,29 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
394
343
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
395
344
|
|
|
396
345
|
(0, _react.useLayoutEffect)(function () {
|
|
397
|
-
mutableRef.current.resizeRegistry.parent = context;
|
|
346
|
+
mutableRef.current.resizeRegistry.parent = context;
|
|
398
347
|
|
|
348
|
+
// componentWillUnmount
|
|
399
349
|
return function () {
|
|
400
350
|
var _mutableRef$current = mutableRef.current,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
351
|
+
animator = _mutableRef$current.animator,
|
|
352
|
+
resizeRegistry = _mutableRef$current.resizeRegistry,
|
|
353
|
+
scrolling = _mutableRef$current.scrolling,
|
|
354
|
+
scrollStopJob = _mutableRef$current.scrollStopJob; // eslint-disable-line react-hooks/exhaustive-deps
|
|
405
355
|
|
|
406
|
-
resizeRegistry.parent = null;
|
|
356
|
+
resizeRegistry.parent = null;
|
|
407
357
|
|
|
358
|
+
// Before call cancelAnimationFrame, you must send scrollStop Event.
|
|
408
359
|
if (scrolling) {
|
|
409
360
|
forwardScrollEvent('onScrollStop', getReachedEdgeInfo());
|
|
410
361
|
}
|
|
362
|
+
scrollStopJob.stop();
|
|
411
363
|
|
|
412
|
-
|
|
413
|
-
|
|
364
|
+
// scrollMode 'translate' [
|
|
414
365
|
if (animator.isAnimating()) {
|
|
415
366
|
animator.stop();
|
|
416
|
-
}
|
|
417
|
-
|
|
367
|
+
}
|
|
368
|
+
// scrollMode 'translate' ]
|
|
418
369
|
};
|
|
419
370
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
420
371
|
|
|
@@ -423,21 +374,23 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
423
374
|
return function () {
|
|
424
375
|
removeEventListeners();
|
|
425
376
|
};
|
|
426
|
-
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// scrollMode 'translate' [[
|
|
427
380
|
// TODO: consider replacing forceUpdate() by storing bounds in state rather than a non-
|
|
428
381
|
// state member.
|
|
429
|
-
|
|
430
382
|
var enqueueForceUpdate = (0, _react.useCallback)(function () {
|
|
431
383
|
scrollContentHandle.current.calculateMetrics(scrollContentHandle.current.props);
|
|
432
384
|
forceUpdate();
|
|
433
|
-
}, [forceUpdate, scrollContentHandle]);
|
|
385
|
+
}, [forceUpdate, scrollContentHandle]);
|
|
386
|
+
// scrollMode 'translate' ]]
|
|
434
387
|
|
|
435
388
|
function handleResizeWindow() {
|
|
436
|
-
var propsHandleResizeWindow = props.handleResizeWindow;
|
|
389
|
+
var propsHandleResizeWindow = props.handleResizeWindow;
|
|
437
390
|
|
|
391
|
+
// `handleSize` in `ui/resolution.ResolutionDecorator` should be executed first.
|
|
438
392
|
setTimeout(function () {
|
|
439
393
|
var handleResizeResult = propsHandleResizeWindow === null || propsHandleResizeWindow === void 0 ? void 0 : propsHandleResizeWindow();
|
|
440
|
-
|
|
441
394
|
if (handleResizeResult) {
|
|
442
395
|
if (scrollMode === 'translate') {
|
|
443
396
|
scrollTo({
|
|
@@ -451,47 +404,44 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
451
404
|
scrollContentHandle.current.scrollToPosition(0, 0, 'instant');
|
|
452
405
|
}
|
|
453
406
|
}
|
|
454
|
-
|
|
455
407
|
enqueueForceUpdate();
|
|
456
408
|
});
|
|
457
|
-
}
|
|
458
|
-
|
|
409
|
+
}
|
|
459
410
|
|
|
411
|
+
// scrollMode 'translate' [[
|
|
460
412
|
var handleResize = (0, _react.useCallback)(function (ev) {
|
|
461
413
|
if (ev.action === 'invalidateBounds') {
|
|
462
414
|
enqueueForceUpdate();
|
|
463
415
|
}
|
|
464
|
-
}, [enqueueForceUpdate]);
|
|
416
|
+
}, [enqueueForceUpdate]);
|
|
417
|
+
// scrollMode 'translate' ]]
|
|
465
418
|
|
|
466
419
|
if (mutableRef.current.resizeRegistry == null) {
|
|
467
420
|
mutableRef.current.resizeRegistry = _Registry["default"].create(handleResize);
|
|
468
421
|
}
|
|
469
|
-
|
|
470
422
|
(0, _react.useLayoutEffect)(function () {
|
|
471
423
|
var ref = mutableRef.current;
|
|
472
|
-
|
|
473
424
|
if (scrollMode === 'translate') {
|
|
474
425
|
ref.scrollStopJob = new _util.Job(doScrollStop, scrollStopWaiting);
|
|
475
426
|
} else {
|
|
476
427
|
ref.scrollStopJob = new _util.Job(scrollStopOnScroll, scrollStopWaiting);
|
|
477
428
|
}
|
|
478
|
-
|
|
479
429
|
return function () {
|
|
480
430
|
if (ref.scrolling) {
|
|
481
431
|
ref.scrollStopJob.run();
|
|
482
432
|
}
|
|
483
|
-
|
|
484
433
|
ref.scrollStopJob.stop();
|
|
485
434
|
};
|
|
486
435
|
}, [direction, isHorizontalScrollbarVisible, isVerticalScrollbarVisible, rtl, scrollMode, spotlightContainerDisabled]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
487
436
|
|
|
488
437
|
(0, _react.useLayoutEffect)(function () {
|
|
489
438
|
var hasDataSizeChanged = scrollContentHandle.current.hasDataSizeChanged,
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
439
|
+
_mutableRef$current2 = mutableRef.current,
|
|
440
|
+
prevState = _mutableRef$current2.prevState,
|
|
441
|
+
resizeRegistry = _mutableRef$current2.resizeRegistry,
|
|
442
|
+
scrollToInfo = _mutableRef$current2.scrollToInfo;
|
|
494
443
|
|
|
444
|
+
// Need to sync calculated client size if it is different from the real size
|
|
495
445
|
if (scrollContentHandle.current.syncClientSize) {
|
|
496
446
|
// If we actually synced, we need to reset scroll position.
|
|
497
447
|
if (scrollContentHandle.current.syncClientSize()) {
|
|
@@ -499,7 +449,6 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
499
449
|
setScrollTop(0);
|
|
500
450
|
}
|
|
501
451
|
}
|
|
502
|
-
|
|
503
452
|
clampScrollPosition(); // scrollMode 'translate'
|
|
504
453
|
|
|
505
454
|
if (hasDataSizeChanged === false && (isHorizontalScrollbarVisible && !prevState.isHorizontalScrollbarVisible || isVerticalScrollbarVisible && !prevState.isVerticalScrollbarVisible)) {
|
|
@@ -508,55 +457,51 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
508
457
|
} else {
|
|
509
458
|
updateScrollbars();
|
|
510
459
|
}
|
|
511
|
-
|
|
512
460
|
if (scrollToInfo !== null) {
|
|
513
461
|
if (!mutableRef.current.deferScrollTo) {
|
|
514
462
|
scrollTo(scrollToInfo);
|
|
515
463
|
}
|
|
516
|
-
}
|
|
517
|
-
|
|
464
|
+
}
|
|
518
465
|
|
|
466
|
+
// publish container resize changes
|
|
519
467
|
var horizontal = isHorizontalScrollbarVisible !== prevState.isHorizontalScrollbarVisible;
|
|
520
468
|
var vertical = isVerticalScrollbarVisible !== prevState.isVerticalScrollbarVisible;
|
|
521
|
-
|
|
522
469
|
if (horizontal || vertical) {
|
|
523
470
|
resizeRegistry.notify({});
|
|
524
471
|
}
|
|
525
|
-
});
|
|
472
|
+
});
|
|
526
473
|
|
|
474
|
+
// scrollMode 'translate' [[
|
|
527
475
|
function clampScrollPosition() {
|
|
528
476
|
var bounds = getScrollBounds();
|
|
529
|
-
|
|
530
477
|
if (mutableRef.current.scrollTop > bounds.maxTop) {
|
|
531
478
|
mutableRef.current.scrollTop = bounds.maxTop;
|
|
532
479
|
}
|
|
533
|
-
|
|
534
480
|
if (mutableRef.current.scrollLeft > bounds.maxLeft) {
|
|
535
481
|
mutableRef.current.scrollLeft = bounds.maxLeft;
|
|
536
482
|
}
|
|
537
|
-
}
|
|
538
|
-
//
|
|
483
|
+
}
|
|
484
|
+
// scrollMode 'translate' ]]
|
|
539
485
|
|
|
486
|
+
// drag/flick event handlers
|
|
540
487
|
|
|
541
488
|
function getRtlX(x) {
|
|
542
489
|
return rtl ? -x : x;
|
|
543
490
|
}
|
|
544
|
-
|
|
545
491
|
function onMouseDown(ev) {
|
|
546
492
|
if (snapToCenter) {
|
|
547
493
|
ev.preventDefault();
|
|
548
494
|
}
|
|
549
|
-
|
|
550
495
|
if ((0, _handle.forwardWithPrevent)('onMouseDown', ev, props) && !snapToCenter) {
|
|
551
496
|
stop();
|
|
552
497
|
}
|
|
553
|
-
}
|
|
554
|
-
|
|
498
|
+
}
|
|
555
499
|
|
|
500
|
+
// scrollMode 'native' [[
|
|
556
501
|
function onTouchStart() {
|
|
557
502
|
mutableRef.current.isTouching = true;
|
|
558
|
-
}
|
|
559
|
-
|
|
503
|
+
}
|
|
504
|
+
// scrollMode 'native' ]]
|
|
560
505
|
|
|
561
506
|
function onDragStart(ev) {
|
|
562
507
|
if (scrollMode === 'translate') {
|
|
@@ -570,20 +515,18 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
570
515
|
if (!mutableRef.current.isTouching) {
|
|
571
516
|
stop();
|
|
572
517
|
mutableRef.current.isDragging = true;
|
|
573
|
-
}
|
|
574
|
-
|
|
518
|
+
}
|
|
575
519
|
|
|
520
|
+
// these values are used also for touch inputs
|
|
576
521
|
mutableRef.current.dragStartX = mutableRef.current.scrollLeft + getRtlX(ev.x);
|
|
577
522
|
mutableRef.current.dragStartY = mutableRef.current.scrollTop + ev.y;
|
|
578
523
|
}
|
|
579
524
|
}
|
|
580
|
-
|
|
581
525
|
function onDrag(ev) {
|
|
582
526
|
if (scrollMode === 'translate') {
|
|
583
527
|
if (ev.type === 'drag') {
|
|
584
528
|
return;
|
|
585
529
|
}
|
|
586
|
-
|
|
587
530
|
mutableRef.current.lastInputType = 'drag';
|
|
588
531
|
(0, _handle.forward)('onDrag', ev, props);
|
|
589
532
|
start({
|
|
@@ -596,11 +539,10 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
596
539
|
});
|
|
597
540
|
} else {
|
|
598
541
|
var targetX = direction === 'vertical' ? 0 : mutableRef.current.dragStartX - getRtlX(ev.x),
|
|
599
|
-
|
|
600
|
-
|
|
542
|
+
// 'horizontal' or 'both'
|
|
543
|
+
targetY = direction === 'horizontal' ? 0 : mutableRef.current.dragStartY - ev.y; // 'vertical' or 'both'
|
|
601
544
|
|
|
602
545
|
mutableRef.current.lastInputType = 'drag';
|
|
603
|
-
|
|
604
546
|
if (!mutableRef.current.isTouching) {
|
|
605
547
|
start({
|
|
606
548
|
targetX: targetX,
|
|
@@ -613,21 +555,18 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
613
555
|
}
|
|
614
556
|
}
|
|
615
557
|
}
|
|
616
|
-
|
|
617
558
|
function onDragEnd(ev) {
|
|
618
559
|
if (scrollMode === 'translate') {
|
|
619
560
|
if (ev.type === 'dragend') {
|
|
620
561
|
return;
|
|
621
562
|
}
|
|
622
|
-
|
|
623
563
|
mutableRef.current.isDragging = false;
|
|
624
564
|
(0, _handle.forward)('onDragEnd', ev, props);
|
|
625
|
-
|
|
626
565
|
if (mutableRef.current.flickTarget) {
|
|
627
566
|
var _mutableRef$current$f = mutableRef.current.flickTarget,
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
567
|
+
targetX = _mutableRef$current$f.targetX,
|
|
568
|
+
targetY = _mutableRef$current$f.targetY,
|
|
569
|
+
duration = _mutableRef$current$f.duration;
|
|
631
570
|
mutableRef.current.lastInputType = 'drag';
|
|
632
571
|
mutableRef.current.isScrollAnimationTargetAccumulated = false;
|
|
633
572
|
start({
|
|
@@ -639,22 +578,18 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
639
578
|
} else {
|
|
640
579
|
stop();
|
|
641
580
|
}
|
|
642
|
-
|
|
643
581
|
if (mutableRef.current.overscrollEnabled) {
|
|
644
582
|
// not check overscrollEffectOn && overscrollEffectOn.drag for safety
|
|
645
583
|
clearAllOverscrollEffects();
|
|
646
584
|
}
|
|
647
|
-
|
|
648
585
|
mutableRef.current.flickTarget = null;
|
|
649
586
|
} else {
|
|
650
587
|
mutableRef.current.isDragging = false;
|
|
651
588
|
mutableRef.current.lastInputType = 'drag';
|
|
652
|
-
|
|
653
589
|
if (mutableRef.current.flickTarget) {
|
|
654
590
|
var _mutableRef$current$f2 = mutableRef.current.flickTarget,
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
591
|
+
_targetX = _mutableRef$current$f2.targetX,
|
|
592
|
+
_targetY = _mutableRef$current$f2.targetY;
|
|
658
593
|
if (!mutableRef.current.isTouching) {
|
|
659
594
|
mutableRef.current.isScrollAnimationTargetAccumulated = false;
|
|
660
595
|
start({
|
|
@@ -668,20 +603,16 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
668
603
|
} else if (!mutableRef.current.isTouching) {
|
|
669
604
|
stop();
|
|
670
605
|
}
|
|
671
|
-
|
|
672
606
|
if (mutableRef.current.overscrollEnabled) {
|
|
673
607
|
// not check overscrollEffectOn && overscrollEffectOn.drag for safety
|
|
674
608
|
clearAllOverscrollEffects();
|
|
675
609
|
}
|
|
676
|
-
|
|
677
610
|
mutableRef.current.isTouching = false;
|
|
678
611
|
mutableRef.current.flickTarget = null;
|
|
679
612
|
}
|
|
680
613
|
}
|
|
681
|
-
|
|
682
614
|
function onFlick(ev) {
|
|
683
615
|
var isVerticalFlick = ev.direction === 'vertical';
|
|
684
|
-
|
|
685
616
|
if (scrollMode === 'translate' || !mutableRef.current.isTouching) {
|
|
686
617
|
// except touch input in 'native' mode
|
|
687
618
|
mutableRef.current.flickTarget = mutableRef.current.animator.simulate(mutableRef.current.scrollLeft, mutableRef.current.scrollTop, direction !== 'vertical' && !isVerticalFlick ? getRtlX(-ev.velocityX) : 0, direction !== 'horizontal' && isVerticalFlick ? -ev.velocityY : 0);
|
|
@@ -691,7 +622,6 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
691
622
|
targetX: mutableRef.current.scrollLeft + (!isVerticalFlick ? getRtlX(-ev.velocityX) : 0) * overscrollVelocityFactor,
|
|
692
623
|
// 'horizontal' or 'both'
|
|
693
624
|
targetY: mutableRef.current.scrollTop + (isVerticalFlick ? -ev.velocityY : 0) * overscrollVelocityFactor // 'vertical' or 'both'
|
|
694
|
-
|
|
695
625
|
};
|
|
696
626
|
}
|
|
697
627
|
|
|
@@ -699,7 +629,6 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
699
629
|
(0, _handle.forward)('onFlick', ev, props);
|
|
700
630
|
}
|
|
701
631
|
}
|
|
702
|
-
|
|
703
632
|
function calculateDistanceByWheel(deltaMode, delta, maxPixel) {
|
|
704
633
|
if (deltaMode === 0) {
|
|
705
634
|
delta = (0, _clamp["default"])(-maxPixel, maxPixel, _resolution["default"].scale(delta * mutableRef.current.scrollWheelMultiplierForDeltaPixel));
|
|
@@ -710,37 +639,32 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
710
639
|
// page
|
|
711
640
|
delta = delta < 0 ? -maxPixel : maxPixel;
|
|
712
641
|
}
|
|
713
|
-
|
|
714
642
|
return delta;
|
|
715
643
|
}
|
|
644
|
+
|
|
716
645
|
/*
|
|
717
646
|
* wheel event handler;
|
|
718
647
|
* - for horizontal scroll, supports wheel action on any children nodes since web engine cannot support this
|
|
719
648
|
* - for vertical scroll, supports wheel action on scrollbars only
|
|
720
649
|
*/
|
|
721
|
-
|
|
722
|
-
|
|
723
650
|
function onWheel(ev) {
|
|
724
651
|
if (mutableRef.current.isDragging) {
|
|
725
652
|
ev.preventDefault();
|
|
726
653
|
ev.stopPropagation();
|
|
727
654
|
} else {
|
|
728
655
|
var bounds = getScrollBounds(),
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
656
|
+
canScrollH = canScrollHorizontally(bounds),
|
|
657
|
+
canScrollV = canScrollVertically(bounds),
|
|
658
|
+
eventDeltaMode = ev.deltaMode,
|
|
659
|
+
eventDelta = -ev.wheelDeltaY || ev.deltaY;
|
|
733
660
|
var delta = 0;
|
|
734
661
|
mutableRef.current.lastInputType = 'wheel';
|
|
735
|
-
|
|
736
662
|
if (noScrollByWheel) {
|
|
737
663
|
if (scrollMode === 'native' && canScrollV) {
|
|
738
664
|
ev.preventDefault();
|
|
739
665
|
}
|
|
740
|
-
|
|
741
666
|
return;
|
|
742
667
|
}
|
|
743
|
-
|
|
744
668
|
if (snapToCenter) {
|
|
745
669
|
if (scrollMode === 'native' && (canScrollV || canScrollH)) {
|
|
746
670
|
ev.preventDefault();
|
|
@@ -748,27 +672,22 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
748
672
|
return;
|
|
749
673
|
}
|
|
750
674
|
}
|
|
751
|
-
|
|
752
675
|
if (scrollMode === 'translate') {
|
|
753
676
|
if (canScrollV) {
|
|
754
677
|
delta = calculateDistanceByWheel(eventDeltaMode, eventDelta, bounds.clientHeight * scrollWheelPageMultiplierForMaxPixel);
|
|
755
678
|
} else if (canScrollH) {
|
|
756
679
|
delta = calculateDistanceByWheel(eventDeltaMode, eventDelta, bounds.clientWidth * scrollWheelPageMultiplierForMaxPixel);
|
|
757
680
|
}
|
|
758
|
-
|
|
759
681
|
var dir = Math.sign(delta);
|
|
760
|
-
|
|
761
682
|
if (dir !== mutableRef.current.wheelDirection) {
|
|
762
683
|
mutableRef.current.isScrollAnimationTargetAccumulated = false;
|
|
763
684
|
mutableRef.current.wheelDirection = dir;
|
|
764
685
|
}
|
|
765
|
-
|
|
766
686
|
(0, _handle.forward)('onWheel', {
|
|
767
687
|
delta: delta,
|
|
768
688
|
horizontalScrollbarHandle: horizontalScrollbarHandle,
|
|
769
689
|
verticalScrollbarHandle: verticalScrollbarHandle
|
|
770
690
|
}, props);
|
|
771
|
-
|
|
772
691
|
if (delta !== 0) {
|
|
773
692
|
scrollToAccumulatedTarget(delta, canScrollV, overscrollEffectOn && overscrollEffectOn.wheel);
|
|
774
693
|
ev.preventDefault();
|
|
@@ -778,15 +697,14 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
778
697
|
// scrollMode 'native'
|
|
779
698
|
var overscrollEffectRequired = mutableRef.current.overscrollEnabled && overscrollEffectOn && overscrollEffectOn.wheel;
|
|
780
699
|
var needToHideScrollbarTrack = false;
|
|
781
|
-
|
|
782
700
|
if (props.onWheel) {
|
|
783
701
|
(0, _handle.forward)('onWheel', ev, props);
|
|
784
702
|
return;
|
|
785
703
|
}
|
|
704
|
+
showScrollbarTrack(bounds);
|
|
786
705
|
|
|
787
|
-
|
|
706
|
+
// FIXME This routine is a temporary support for horizontal wheel scroll.
|
|
788
707
|
// FIXME If web engine supports horizontal wheel, this routine should be refined or removed.
|
|
789
|
-
|
|
790
708
|
if (canScrollV) {
|
|
791
709
|
// This routine handles wheel events on scrollbars for vertical scroll.
|
|
792
710
|
if (eventDelta < 0 && mutableRef.current.scrollTop > 0 || eventDelta > 0 && mutableRef.current.scrollTop < bounds.maxTop) {
|
|
@@ -798,13 +716,11 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
798
716
|
} else if (overscrollEffectRequired) {
|
|
799
717
|
checkAndApplyOverscrollEffect('vertical', eventDelta > 0 ? 'after' : 'before', overscrollTypeOnce);
|
|
800
718
|
}
|
|
801
|
-
|
|
802
719
|
ev.stopPropagation();
|
|
803
720
|
} else {
|
|
804
721
|
if (overscrollEffectRequired && (eventDelta < 0 && mutableRef.current.scrollTop <= 0 || eventDelta > 0 && mutableRef.current.scrollTop >= bounds.maxTop)) {
|
|
805
722
|
applyOverscrollEffect('vertical', eventDelta > 0 ? 'after' : 'before', overscrollTypeOnce);
|
|
806
723
|
}
|
|
807
|
-
|
|
808
724
|
needToHideScrollbarTrack = true;
|
|
809
725
|
}
|
|
810
726
|
} else if (canScrollH) {
|
|
@@ -818,72 +734,62 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
818
734
|
if (overscrollEffectRequired && (eventDelta < 0 && mutableRef.current.scrollLeft <= 0 || eventDelta > 0 && mutableRef.current.scrollLeft >= bounds.maxLeft)) {
|
|
819
735
|
applyOverscrollEffect('horizontal', eventDelta > 0 ? 'after' : 'before', overscrollTypeOnce);
|
|
820
736
|
}
|
|
821
|
-
|
|
822
737
|
needToHideScrollbarTrack = true;
|
|
823
738
|
}
|
|
824
739
|
}
|
|
825
|
-
|
|
826
740
|
if (delta !== 0) {
|
|
827
|
-
var _dir = Math.sign(delta);
|
|
828
|
-
|
|
741
|
+
var _dir = Math.sign(delta);
|
|
829
742
|
|
|
743
|
+
// Not to accumulate scroll position if wheel direction is different from hold direction
|
|
830
744
|
if (_dir !== mutableRef.current.wheelDirection) {
|
|
831
745
|
mutableRef.current.isScrollAnimationTargetAccumulated = false;
|
|
832
746
|
mutableRef.current.wheelDirection = _dir;
|
|
833
747
|
}
|
|
834
|
-
|
|
835
748
|
scrollToAccumulatedTarget(delta, canScrollV, overscrollEffectOn && overscrollEffectOn.wheel);
|
|
836
749
|
}
|
|
837
|
-
|
|
838
750
|
if (needToHideScrollbarTrack) {
|
|
839
751
|
startHidingScrollbarTrack();
|
|
840
752
|
}
|
|
841
753
|
}
|
|
842
754
|
}
|
|
843
|
-
}
|
|
844
|
-
|
|
755
|
+
}
|
|
845
756
|
|
|
757
|
+
// scrollMode 'translate' [[
|
|
846
758
|
function scrollByPage(keyCode) {
|
|
847
759
|
var bounds = getScrollBounds(),
|
|
848
|
-
|
|
849
|
-
|
|
760
|
+
canScrollV = canScrollVertically(bounds),
|
|
761
|
+
pageDistance = (isPageUp(keyCode) ? -1 : 1) * (canScrollV ? bounds.clientHeight : bounds.clientWidth) * paginationPageMultiplier;
|
|
850
762
|
mutableRef.current.lastInputType = 'pageKey';
|
|
851
763
|
scrollToAccumulatedTarget(pageDistance, canScrollV, overscrollEffectOn && overscrollEffectOn.pageKey);
|
|
852
|
-
}
|
|
853
|
-
// scrollMode '
|
|
854
|
-
|
|
764
|
+
}
|
|
765
|
+
// scrollMode 'translate' ]]
|
|
855
766
|
|
|
767
|
+
// scrollMode 'native' [[
|
|
856
768
|
function onScroll(ev) {
|
|
857
769
|
var _ev$target = ev.target,
|
|
858
|
-
|
|
859
|
-
|
|
770
|
+
scrollLeft = _ev$target.scrollLeft,
|
|
771
|
+
scrollTop = _ev$target.scrollTop;
|
|
860
772
|
var bounds = getScrollBounds(),
|
|
861
|
-
|
|
862
|
-
|
|
773
|
+
canScrollH = canScrollHorizontally(bounds);
|
|
863
774
|
if (!mutableRef.current.scrolling) {
|
|
864
775
|
scrollStartOnScroll();
|
|
865
776
|
}
|
|
866
|
-
|
|
867
777
|
if (rtl && canScrollH) {
|
|
868
778
|
scrollLeft = _platform.platform.ios || _platform.platform.safari || _platform.platform.chrome >= 85 || _platform.platform.androidChrome >= 85 ? -scrollLeft : bounds.maxLeft - scrollLeft;
|
|
869
779
|
}
|
|
870
|
-
|
|
871
780
|
if (scrollLeft !== mutableRef.current.scrollLeft) {
|
|
872
781
|
setScrollLeft(scrollLeft);
|
|
873
782
|
}
|
|
874
|
-
|
|
875
783
|
if (scrollTop !== mutableRef.current.scrollTop) {
|
|
876
784
|
setScrollTop(scrollTop);
|
|
877
785
|
}
|
|
878
|
-
|
|
879
786
|
if (scrollContentHandle.current.didScroll) {
|
|
880
787
|
scrollContentHandle.current.didScroll(mutableRef.current.scrollLeft, mutableRef.current.scrollTop);
|
|
881
788
|
}
|
|
882
|
-
|
|
883
789
|
forwardScrollEvent('onScroll');
|
|
884
790
|
mutableRef.current.scrollStopJob.start();
|
|
885
|
-
}
|
|
886
|
-
|
|
791
|
+
}
|
|
792
|
+
// scrollMode 'native' ]]
|
|
887
793
|
|
|
888
794
|
function onKeyDown(ev) {
|
|
889
795
|
if (scrollMode === 'translate') {
|
|
@@ -896,27 +802,25 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
896
802
|
(0, _handle.forward)('onKeyDown', ev, props);
|
|
897
803
|
}
|
|
898
804
|
}
|
|
899
|
-
|
|
900
805
|
function scrollToAccumulatedTarget(delta, vertical, overscrollEffect) {
|
|
901
806
|
if (!mutableRef.current.isScrollAnimationTargetAccumulated) {
|
|
902
807
|
mutableRef.current.accumulatedTargetX = mutableRef.current.scrollLeft;
|
|
903
808
|
mutableRef.current.accumulatedTargetY = mutableRef.current.scrollTop;
|
|
904
809
|
mutableRef.current.isScrollAnimationTargetAccumulated = true;
|
|
905
810
|
}
|
|
906
|
-
|
|
907
811
|
if (vertical) {
|
|
908
812
|
mutableRef.current.accumulatedTargetY += delta;
|
|
909
813
|
} else {
|
|
910
814
|
mutableRef.current.accumulatedTargetX += delta;
|
|
911
815
|
}
|
|
912
|
-
|
|
913
816
|
start({
|
|
914
817
|
targetX: mutableRef.current.accumulatedTargetX,
|
|
915
818
|
targetY: mutableRef.current.accumulatedTargetY,
|
|
916
819
|
overscrollEffect: overscrollEffect
|
|
917
820
|
});
|
|
918
|
-
}
|
|
821
|
+
}
|
|
919
822
|
|
|
823
|
+
// overscroll effect
|
|
920
824
|
|
|
921
825
|
function getEdgeFromPosition(position, maxPosition) {
|
|
922
826
|
if (position <= 0) {
|
|
@@ -927,24 +831,20 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
927
831
|
return null;
|
|
928
832
|
}
|
|
929
833
|
}
|
|
930
|
-
|
|
931
834
|
function setOverscrollStatus(orientation, edge, overscrollEffectType, ratio) {
|
|
932
835
|
var status = mutableRef.current.overscrollStatus[orientation][edge];
|
|
933
836
|
status.type = overscrollEffectType;
|
|
934
837
|
status.ratio = ratio;
|
|
935
838
|
}
|
|
936
|
-
|
|
937
839
|
function getOverscrollStatus(orientation, edge) {
|
|
938
840
|
return mutableRef.current.overscrollStatus[orientation][edge];
|
|
939
841
|
}
|
|
940
|
-
|
|
941
842
|
function calculateOverscrollRatio(orientation, position) {
|
|
942
843
|
var bounds = getScrollBounds(),
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
844
|
+
isVertical = orientation === 'vertical',
|
|
845
|
+
baseSize = isVertical ? bounds.clientHeight : bounds.clientWidth,
|
|
846
|
+
maxPos = bounds[isVertical ? 'maxTop' : 'maxLeft'];
|
|
946
847
|
var overDistance = 0;
|
|
947
|
-
|
|
948
848
|
if (position < 0) {
|
|
949
849
|
overDistance = -position;
|
|
950
850
|
} else if (position > maxPos) {
|
|
@@ -952,22 +852,18 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
952
852
|
} else {
|
|
953
853
|
return 0;
|
|
954
854
|
}
|
|
955
|
-
|
|
956
855
|
return Math.min(1, 2 * overDistance / baseSize);
|
|
957
856
|
}
|
|
958
|
-
|
|
959
857
|
function applyOverscrollEffect(orientation, edge, overscrollEffectType) {
|
|
960
858
|
var ratio = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : overscrollDefaultRatio;
|
|
961
859
|
props.applyOverscrollEffect(orientation, edge, overscrollEffectType, ratio);
|
|
962
860
|
setOverscrollStatus(orientation, edge, overscrollEffectType === overscrollTypeOnce ? overscrollTypeDone : overscrollEffectType, ratio);
|
|
963
861
|
}
|
|
964
|
-
|
|
965
862
|
function checkAndApplyOverscrollEffect(orientation, edge, overscrollEffectType) {
|
|
966
863
|
var ratio = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : overscrollDefaultRatio;
|
|
967
864
|
var isVertical = orientation === 'vertical',
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
865
|
+
curPos = isVertical ? mutableRef.current.scrollTop : mutableRef.current.scrollLeft,
|
|
866
|
+
maxPos = getScrollBounds()[isVertical ? 'maxTop' : 'maxLeft'];
|
|
971
867
|
if (edge === 'before' && curPos <= 0 || edge === 'after' && curPos >= maxPos - epsilon) {
|
|
972
868
|
// Already on the edge
|
|
973
869
|
applyOverscrollEffect(orientation, edge, overscrollEffectType, ratio);
|
|
@@ -975,7 +871,6 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
975
871
|
setOverscrollStatus(orientation, edge, overscrollEffectType, ratio);
|
|
976
872
|
}
|
|
977
873
|
}
|
|
978
|
-
|
|
979
874
|
function clearOverscrollEffect(orientation, edge) {
|
|
980
875
|
if (getOverscrollStatus(orientation, edge).type !== overscrollTypeNone) {
|
|
981
876
|
if (props.clearOverscrollEffect) {
|
|
@@ -985,7 +880,6 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
985
880
|
}
|
|
986
881
|
}
|
|
987
882
|
}
|
|
988
|
-
|
|
989
883
|
function clearAllOverscrollEffects() {
|
|
990
884
|
['horizontal', 'vertical'].forEach(function (orientation) {
|
|
991
885
|
['before', 'after'].forEach(function (edge) {
|
|
@@ -993,57 +887,52 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
993
887
|
});
|
|
994
888
|
});
|
|
995
889
|
}
|
|
996
|
-
|
|
997
890
|
function applyOverscrollEffectOnDrag(orientation, edge, targetPosition, overscrollEffectType) {
|
|
998
891
|
if (edge) {
|
|
999
892
|
var oppositeEdge = edge === 'before' ? 'after' : 'before',
|
|
1000
|
-
|
|
893
|
+
ratio = calculateOverscrollRatio(orientation, targetPosition);
|
|
1001
894
|
applyOverscrollEffect(orientation, edge, overscrollEffectType, ratio);
|
|
1002
895
|
clearOverscrollEffect(orientation, oppositeEdge);
|
|
1003
896
|
} else {
|
|
1004
897
|
clearOverscrollEffect(orientation, 'before');
|
|
1005
898
|
clearOverscrollEffect(orientation, 'after');
|
|
1006
899
|
}
|
|
1007
|
-
}
|
|
1008
|
-
|
|
900
|
+
}
|
|
1009
901
|
|
|
902
|
+
// scrollMode 'native' [[
|
|
1010
903
|
function checkAndApplyOverscrollEffectOnDrag(targetX, targetY, overscrollEffectType) {
|
|
1011
904
|
var bounds = getScrollBounds();
|
|
1012
|
-
|
|
1013
905
|
if (canScrollHorizontally(bounds)) {
|
|
1014
906
|
applyOverscrollEffectOnDrag('horizontal', getEdgeFromPosition(targetX, bounds.maxLeft), targetX, overscrollEffectType);
|
|
1015
907
|
}
|
|
1016
|
-
|
|
1017
908
|
if (canScrollVertically(bounds)) {
|
|
1018
909
|
applyOverscrollEffectOnDrag('vertical', getEdgeFromPosition(targetY, bounds.maxTop), targetY, overscrollEffectType);
|
|
1019
910
|
}
|
|
1020
|
-
}
|
|
1021
|
-
|
|
911
|
+
}
|
|
912
|
+
// scrollMode 'native' ]]
|
|
1022
913
|
|
|
1023
914
|
function checkAndApplyOverscrollEffectOnScroll(orientation) {
|
|
1024
915
|
['before', 'after'].forEach(function (edge) {
|
|
1025
916
|
var _getOverscrollStatus = getOverscrollStatus(orientation, edge),
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
917
|
+
ratio = _getOverscrollStatus.ratio,
|
|
918
|
+
overscrollEffectType = _getOverscrollStatus.type;
|
|
1029
919
|
if (overscrollEffectType === overscrollTypeOnce) {
|
|
1030
920
|
checkAndApplyOverscrollEffect(orientation, edge, overscrollEffectType, ratio);
|
|
1031
921
|
}
|
|
1032
922
|
});
|
|
1033
923
|
}
|
|
1034
|
-
|
|
1035
924
|
function checkAndApplyOverscrollEffectOnStart(orientation, edge, targetPosition) {
|
|
1036
925
|
if (mutableRef.current.isDragging) {
|
|
1037
926
|
applyOverscrollEffectOnDrag(orientation, edge, targetPosition, overscrollTypeHold);
|
|
1038
927
|
} else if (edge) {
|
|
1039
928
|
checkAndApplyOverscrollEffect(orientation, edge, overscrollTypeOnce);
|
|
1040
929
|
}
|
|
1041
|
-
}
|
|
930
|
+
}
|
|
1042
931
|
|
|
932
|
+
// call scroll callbacks
|
|
1043
933
|
|
|
1044
934
|
var addObserverOnScroll = (0, _react.useCallback)(function (fn) {
|
|
1045
935
|
var observerOnScroll = mutableRef.current.observerOnScroll;
|
|
1046
|
-
|
|
1047
936
|
if (typeof fn === 'function' && !observerOnScroll.includes(fn)) {
|
|
1048
937
|
observerOnScroll.push(fn);
|
|
1049
938
|
}
|
|
@@ -1051,12 +940,10 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1051
940
|
var removeObserverOnScroll = (0, _react.useCallback)(function (fn) {
|
|
1052
941
|
var observerOnScroll = mutableRef.current.observerOnScroll;
|
|
1053
942
|
var index = observerOnScroll.indexOf(fn);
|
|
1054
|
-
|
|
1055
943
|
if (index !== -1) {
|
|
1056
944
|
observerOnScroll.splice(index, 1);
|
|
1057
945
|
}
|
|
1058
946
|
}, []);
|
|
1059
|
-
|
|
1060
947
|
function forwardScrollEvent(type, reachedEdgeInfo) {
|
|
1061
948
|
var data = {
|
|
1062
949
|
scrollLeft: mutableRef.current.scrollLeft,
|
|
@@ -1065,79 +952,69 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1065
952
|
reachedEdgeInfo: reachedEdgeInfo
|
|
1066
953
|
};
|
|
1067
954
|
(0, _handle.forward)(type, data, props);
|
|
1068
|
-
|
|
1069
955
|
if (type === 'onScroll') {
|
|
1070
956
|
mutableRef.current.observerOnScroll.forEach(function (fn) {
|
|
1071
957
|
return fn(data);
|
|
1072
958
|
});
|
|
1073
959
|
}
|
|
1074
|
-
}
|
|
1075
|
-
// call scroll callbacks and update scrollbars for native scroll
|
|
960
|
+
}
|
|
1076
961
|
|
|
962
|
+
// scrollMode 'native' [[
|
|
963
|
+
// call scroll callbacks and update scrollbars for native scroll
|
|
1077
964
|
|
|
1078
965
|
function scrollStartOnScroll() {
|
|
1079
966
|
mutableRef.current.scrolling = true;
|
|
1080
967
|
showScrollbarTrack(getScrollBounds());
|
|
1081
968
|
forwardScrollEvent('onScrollStart');
|
|
1082
969
|
}
|
|
1083
|
-
|
|
1084
970
|
function scrollStopOnScroll() {
|
|
1085
971
|
if (props.scrollStopOnScroll) {
|
|
1086
972
|
props.scrollStopOnScroll();
|
|
1087
973
|
}
|
|
1088
|
-
|
|
1089
974
|
if (mutableRef.current.overscrollEnabled && !mutableRef.current.isDragging) {
|
|
1090
975
|
// not check overscrollEffectOn && overscrollEffectOn for safety
|
|
1091
976
|
clearAllOverscrollEffects();
|
|
1092
977
|
}
|
|
1093
|
-
|
|
1094
978
|
mutableRef.current.lastInputType = null;
|
|
1095
979
|
mutableRef.current.isScrollAnimationTargetAccumulated = false;
|
|
1096
980
|
mutableRef.current.scrolling = false;
|
|
1097
981
|
forwardScrollEvent('onScrollStop', getReachedEdgeInfo());
|
|
1098
982
|
startHidingScrollbarTrack();
|
|
1099
|
-
}
|
|
1100
|
-
//
|
|
983
|
+
}
|
|
984
|
+
// scrollMode 'native' ]]
|
|
1101
985
|
|
|
986
|
+
// update scroll position
|
|
1102
987
|
|
|
1103
988
|
function setScrollLeft(value) {
|
|
1104
989
|
var bounds = getScrollBounds();
|
|
1105
990
|
mutableRef.current.scrollLeft = (0, _clamp["default"])(0, bounds.maxLeft, value);
|
|
1106
|
-
|
|
1107
991
|
if (mutableRef.current.overscrollEnabled && overscrollEffectOn && overscrollEffectOn[mutableRef.current.lastInputType]) {
|
|
1108
992
|
checkAndApplyOverscrollEffectOnScroll('horizontal');
|
|
1109
993
|
}
|
|
1110
|
-
|
|
1111
994
|
if (isHorizontalScrollbarVisible) {
|
|
1112
995
|
updateScrollbarTrack(horizontalScrollbarHandle, bounds);
|
|
1113
996
|
}
|
|
1114
997
|
}
|
|
1115
|
-
|
|
1116
998
|
function setScrollTop(value) {
|
|
1117
999
|
var bounds = getScrollBounds();
|
|
1118
1000
|
mutableRef.current.scrollTop = (0, _clamp["default"])(0, bounds.maxTop, value);
|
|
1119
|
-
|
|
1120
1001
|
if (mutableRef.current.overscrollEnabled && overscrollEffectOn && overscrollEffectOn[mutableRef.current.lastInputType]) {
|
|
1121
1002
|
checkAndApplyOverscrollEffectOnScroll('vertical');
|
|
1122
1003
|
}
|
|
1123
|
-
|
|
1124
1004
|
if (isVerticalScrollbarVisible) {
|
|
1125
1005
|
updateScrollbarTrack(verticalScrollbarHandle, bounds);
|
|
1126
1006
|
}
|
|
1127
1007
|
}
|
|
1128
|
-
|
|
1129
1008
|
function getReachedEdgeInfo() {
|
|
1130
1009
|
var bounds = getScrollBounds(),
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1010
|
+
reachedEdgeInfo = {
|
|
1011
|
+
bottom: false,
|
|
1012
|
+
left: false,
|
|
1013
|
+
right: false,
|
|
1014
|
+
top: false
|
|
1015
|
+
};
|
|
1138
1016
|
if (canScrollHorizontally(bounds)) {
|
|
1139
1017
|
var edge = getEdgeFromPosition(mutableRef.current.scrollLeft, bounds.maxLeft);
|
|
1140
|
-
|
|
1141
1018
|
if (edge) {
|
|
1142
1019
|
// if edge is null, no need to check which edge is reached.
|
|
1143
1020
|
if (edge === 'before' && !rtl || edge === 'after' && rtl) {
|
|
@@ -1147,43 +1024,41 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1147
1024
|
}
|
|
1148
1025
|
}
|
|
1149
1026
|
}
|
|
1150
|
-
|
|
1151
1027
|
if (canScrollVertically(bounds)) {
|
|
1152
1028
|
var _edge = getEdgeFromPosition(mutableRef.current.scrollTop, bounds.maxTop);
|
|
1153
|
-
|
|
1154
1029
|
if (_edge === 'before') {
|
|
1155
1030
|
reachedEdgeInfo.top = true;
|
|
1156
1031
|
} else if (_edge === 'after') {
|
|
1157
1032
|
reachedEdgeInfo.bottom = true;
|
|
1158
1033
|
}
|
|
1159
1034
|
}
|
|
1160
|
-
|
|
1161
1035
|
return reachedEdgeInfo;
|
|
1162
|
-
}
|
|
1163
|
-
// scrollMode 'translate' [[
|
|
1036
|
+
}
|
|
1164
1037
|
|
|
1038
|
+
// scroll start/stop
|
|
1165
1039
|
|
|
1040
|
+
// scrollMode 'translate' [[
|
|
1166
1041
|
function doScrollStop() {
|
|
1167
1042
|
mutableRef.current.scrolling = false;
|
|
1168
1043
|
forwardScrollEvent('onScrollStop', getReachedEdgeInfo());
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1044
|
+
}
|
|
1045
|
+
// scrollMode 'translate' ]]
|
|
1171
1046
|
|
|
1172
1047
|
function start(_ref2) {
|
|
1173
1048
|
var targetX = _ref2.targetX,
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1049
|
+
targetY = _ref2.targetY,
|
|
1050
|
+
_ref2$animate = _ref2.animate,
|
|
1051
|
+
animate = _ref2$animate === void 0 ? true : _ref2$animate,
|
|
1052
|
+
_ref2$duration = _ref2.duration,
|
|
1053
|
+
duration = _ref2$duration === void 0 ? animationDuration : _ref2$duration,
|
|
1054
|
+
_ref2$overscrollEffec = _ref2.overscrollEffect,
|
|
1055
|
+
overscrollEffect = _ref2$overscrollEffec === void 0 ? false : _ref2$overscrollEffec;
|
|
1181
1056
|
var _mutableRef$current3 = mutableRef.current,
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1057
|
+
scrollLeft = _mutableRef$current3.scrollLeft,
|
|
1058
|
+
scrollTop = _mutableRef$current3.scrollTop,
|
|
1059
|
+
bounds = getScrollBounds(),
|
|
1060
|
+
maxLeft = bounds.maxLeft,
|
|
1061
|
+
maxTop = bounds.maxTop;
|
|
1187
1062
|
var updatedAnimationInfo = scrollMode === 'translate' ? {
|
|
1188
1063
|
sourceX: scrollLeft,
|
|
1189
1064
|
sourceY: scrollTop,
|
|
@@ -1193,50 +1068,40 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1193
1068
|
} : {
|
|
1194
1069
|
targetX: targetX,
|
|
1195
1070
|
targetY: targetY
|
|
1196
|
-
};
|
|
1071
|
+
};
|
|
1197
1072
|
|
|
1073
|
+
// bail early when scrolling to the same position
|
|
1198
1074
|
if ((scrollMode === 'translate' && mutableRef.current.animator.isAnimating() || scrollMode === 'native' && mutableRef.current.scrolling) && mutableRef.current.animationInfo && mutableRef.current.animationInfo.targetX === targetX && mutableRef.current.animationInfo.targetY === targetY) {
|
|
1199
1075
|
return;
|
|
1200
1076
|
}
|
|
1201
|
-
|
|
1202
1077
|
mutableRef.current.animationInfo = updatedAnimationInfo;
|
|
1203
|
-
|
|
1204
1078
|
if (scrollMode === 'translate') {
|
|
1205
1079
|
mutableRef.current.animator.stop();
|
|
1206
|
-
|
|
1207
1080
|
if (!mutableRef.current.scrolling) {
|
|
1208
1081
|
mutableRef.current.scrolling = true;
|
|
1209
1082
|
forwardScrollEvent('onScrollStart');
|
|
1210
1083
|
}
|
|
1211
|
-
|
|
1212
1084
|
mutableRef.current.scrollStopJob.stop();
|
|
1213
1085
|
}
|
|
1214
|
-
|
|
1215
1086
|
if (Math.abs(maxLeft - targetX) < epsilon) {
|
|
1216
1087
|
targetX = maxLeft;
|
|
1217
1088
|
}
|
|
1218
|
-
|
|
1219
1089
|
if (Math.abs(maxTop - targetY) < epsilon) {
|
|
1220
1090
|
targetY = maxTop;
|
|
1221
1091
|
}
|
|
1222
|
-
|
|
1223
1092
|
if (mutableRef.current.overscrollEnabled && overscrollEffect) {
|
|
1224
1093
|
if (scrollLeft !== targetX && canScrollHorizontally(bounds)) {
|
|
1225
1094
|
checkAndApplyOverscrollEffectOnStart('horizontal', getEdgeFromPosition(targetX, maxLeft), targetX);
|
|
1226
1095
|
}
|
|
1227
|
-
|
|
1228
1096
|
if (scrollTop !== targetY && canScrollVertically(bounds)) {
|
|
1229
1097
|
checkAndApplyOverscrollEffectOnStart('vertical', getEdgeFromPosition(targetY, maxTop), targetY);
|
|
1230
1098
|
}
|
|
1231
1099
|
}
|
|
1232
|
-
|
|
1233
1100
|
if (scrollMode === 'translate') {
|
|
1234
1101
|
showScrollbarTrack(bounds);
|
|
1235
|
-
|
|
1236
1102
|
if (scrollContentHandle.current && scrollContentHandle.current.setScrollPositionTarget) {
|
|
1237
1103
|
scrollContentHandle.current.setScrollPositionTarget(targetX, targetY);
|
|
1238
1104
|
}
|
|
1239
|
-
|
|
1240
1105
|
if (animate) {
|
|
1241
1106
|
mutableRef.current.animator.animate(scrollAnimation(mutableRef.current.animationInfo));
|
|
1242
1107
|
} else {
|
|
@@ -1250,50 +1115,42 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1250
1115
|
} else {
|
|
1251
1116
|
scrollContentHandle.current.scrollToPosition(targetX, targetY, 'instant');
|
|
1252
1117
|
}
|
|
1253
|
-
|
|
1254
1118
|
if (props.start) {
|
|
1255
1119
|
props.start(animate);
|
|
1256
1120
|
}
|
|
1257
1121
|
}
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1122
|
+
}
|
|
1260
1123
|
|
|
1124
|
+
// scrollMode 'translate' [[
|
|
1261
1125
|
function scrollAnimation(animationInfo) {
|
|
1262
1126
|
return function (curTime) {
|
|
1263
1127
|
var sourceX = animationInfo.sourceX,
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1128
|
+
sourceY = animationInfo.sourceY,
|
|
1129
|
+
targetX = animationInfo.targetX,
|
|
1130
|
+
targetY = animationInfo.targetY,
|
|
1131
|
+
duration = animationInfo.duration,
|
|
1132
|
+
bounds = getScrollBounds();
|
|
1270
1133
|
if (curTime < duration) {
|
|
1271
1134
|
var toBeContinued = false,
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1135
|
+
curTargetX = sourceX,
|
|
1136
|
+
curTargetY = sourceY;
|
|
1275
1137
|
if (canScrollHorizontally(bounds)) {
|
|
1276
1138
|
curTargetX = mutableRef.current.animator.timingFunction(sourceX, targetX, duration, curTime);
|
|
1277
|
-
|
|
1278
1139
|
if (Math.abs(curTargetX - targetX) < epsilon) {
|
|
1279
1140
|
curTargetX = targetX;
|
|
1280
1141
|
} else {
|
|
1281
1142
|
toBeContinued = true;
|
|
1282
1143
|
}
|
|
1283
1144
|
}
|
|
1284
|
-
|
|
1285
1145
|
if (canScrollVertically(bounds)) {
|
|
1286
1146
|
curTargetY = mutableRef.current.animator.timingFunction(sourceY, targetY, duration, curTime);
|
|
1287
|
-
|
|
1288
1147
|
if (Math.abs(curTargetY - targetY) < epsilon) {
|
|
1289
1148
|
curTargetY = targetY;
|
|
1290
1149
|
} else {
|
|
1291
1150
|
toBeContinued = true;
|
|
1292
1151
|
}
|
|
1293
1152
|
}
|
|
1294
|
-
|
|
1295
1153
|
scroll(curTargetX, curTargetY);
|
|
1296
|
-
|
|
1297
1154
|
if (!toBeContinued) {
|
|
1298
1155
|
stop();
|
|
1299
1156
|
}
|
|
@@ -1303,62 +1160,54 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1303
1160
|
}
|
|
1304
1161
|
};
|
|
1305
1162
|
}
|
|
1306
|
-
|
|
1307
1163
|
function scroll(left, top) {
|
|
1308
1164
|
if (left !== mutableRef.current.scrollLeft) {
|
|
1309
1165
|
setScrollLeft(left);
|
|
1310
1166
|
}
|
|
1311
|
-
|
|
1312
1167
|
if (top !== mutableRef.current.scrollTop) {
|
|
1313
1168
|
setScrollTop(top);
|
|
1314
1169
|
}
|
|
1315
|
-
|
|
1316
1170
|
scrollContentHandle.current.setScrollPosition(mutableRef.current.scrollLeft, mutableRef.current.scrollTop);
|
|
1317
1171
|
forwardScrollEvent('onScroll');
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1172
|
+
}
|
|
1173
|
+
// scrollMode 'translate' ]]
|
|
1320
1174
|
|
|
1321
1175
|
function stopForTranslate() {
|
|
1322
1176
|
mutableRef.current.animator.stop();
|
|
1323
1177
|
mutableRef.current.lastInputType = null;
|
|
1324
1178
|
mutableRef.current.isScrollAnimationTargetAccumulated = false;
|
|
1325
1179
|
startHidingScrollbarTrack();
|
|
1326
|
-
|
|
1327
1180
|
if (mutableRef.current.overscrollEnabled && !mutableRef.current.isDragging) {
|
|
1328
1181
|
// not check overscrollEffectOn && overscrollEffectOn for safety
|
|
1329
1182
|
clearAllOverscrollEffects();
|
|
1330
1183
|
}
|
|
1331
|
-
|
|
1332
1184
|
if (props.stop) {
|
|
1333
1185
|
props.stop();
|
|
1334
1186
|
}
|
|
1335
|
-
|
|
1336
1187
|
if (mutableRef.current.scrolling) {
|
|
1337
1188
|
mutableRef.current.scrollStopJob.start();
|
|
1338
1189
|
}
|
|
1339
1190
|
}
|
|
1340
|
-
|
|
1341
1191
|
function stopForNative() {
|
|
1342
1192
|
scrollContentHandle.current.scrollToPosition(mutableRef.current.scrollLeft + (rtl ? -0.1 : 0.1), mutableRef.current.scrollTop + 0.1, 'instant');
|
|
1343
1193
|
}
|
|
1344
|
-
|
|
1345
1194
|
function stop() {
|
|
1346
1195
|
if (scrollMode === 'translate') {
|
|
1347
1196
|
stopForTranslate();
|
|
1348
1197
|
} else {
|
|
1349
1198
|
stopForNative();
|
|
1350
1199
|
}
|
|
1351
|
-
}
|
|
1200
|
+
}
|
|
1352
1201
|
|
|
1202
|
+
// scrollTo API
|
|
1353
1203
|
|
|
1354
1204
|
function getPositionForScrollTo(opt) {
|
|
1355
1205
|
var bounds = getScrollBounds(),
|
|
1356
|
-
|
|
1357
|
-
|
|
1206
|
+
canScrollH = canScrollHorizontally(bounds),
|
|
1207
|
+
canScrollV = canScrollVertically(bounds);
|
|
1358
1208
|
var itemPos,
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1209
|
+
left = null,
|
|
1210
|
+
top = null;
|
|
1362
1211
|
if (opt instanceof Object) {
|
|
1363
1212
|
if (opt.position instanceof Object) {
|
|
1364
1213
|
if (canScrollH) {
|
|
@@ -1367,7 +1216,6 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1367
1216
|
} else {
|
|
1368
1217
|
left = 0;
|
|
1369
1218
|
}
|
|
1370
|
-
|
|
1371
1219
|
if (canScrollV) {
|
|
1372
1220
|
// We need '!=' to check if opt.position.y is null or undefined
|
|
1373
1221
|
top = opt.position.y != null ? opt.position.y : mutableRef.current.scrollTop;
|
|
@@ -1382,7 +1230,6 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1382
1230
|
left = bounds.maxLeft;
|
|
1383
1231
|
}
|
|
1384
1232
|
}
|
|
1385
|
-
|
|
1386
1233
|
if (canScrollV) {
|
|
1387
1234
|
if (opt.align.includes('top')) {
|
|
1388
1235
|
top = 0;
|
|
@@ -1398,44 +1245,35 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1398
1245
|
itemPos = scrollContentHandle.current.getNodePosition(opt.node);
|
|
1399
1246
|
}
|
|
1400
1247
|
}
|
|
1401
|
-
|
|
1402
1248
|
if (itemPos) {
|
|
1403
1249
|
if (canScrollH) {
|
|
1404
1250
|
left = itemPos.left;
|
|
1405
1251
|
}
|
|
1406
|
-
|
|
1407
1252
|
if (canScrollV) {
|
|
1408
1253
|
top = itemPos.top;
|
|
1409
1254
|
}
|
|
1410
1255
|
}
|
|
1411
1256
|
}
|
|
1412
1257
|
}
|
|
1413
|
-
|
|
1414
1258
|
return {
|
|
1415
1259
|
left: left,
|
|
1416
1260
|
top: top
|
|
1417
1261
|
};
|
|
1418
1262
|
}
|
|
1419
|
-
|
|
1420
1263
|
function scrollTo(opt) {
|
|
1421
1264
|
if (!mutableRef.current.deferScrollTo) {
|
|
1422
1265
|
var _getPositionForScroll = getPositionForScrollTo(opt),
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1266
|
+
left = _getPositionForScroll.left,
|
|
1267
|
+
top = _getPositionForScroll.top;
|
|
1426
1268
|
var targetX = left !== null ? left : mutableRef.current.scrollLeft;
|
|
1427
1269
|
var targetY = top !== null ? top : mutableRef.current.scrollTop;
|
|
1428
|
-
|
|
1429
1270
|
if (props.scrollTo) {
|
|
1430
1271
|
props.scrollTo(opt);
|
|
1431
1272
|
}
|
|
1432
|
-
|
|
1433
1273
|
mutableRef.current.scrollToInfo = null;
|
|
1434
|
-
|
|
1435
1274
|
if (scrollMode === 'native' && scrollContentHandle.current && scrollContentHandle.current.setScrollToPositionTarget) {
|
|
1436
1275
|
scrollContentHandle.current.setScrollToPositionTarget(targetX, targetY);
|
|
1437
1276
|
}
|
|
1438
|
-
|
|
1439
1277
|
start({
|
|
1440
1278
|
targetX: targetX,
|
|
1441
1279
|
targetY: targetY,
|
|
@@ -1445,52 +1283,46 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1445
1283
|
mutableRef.current.scrollToInfo = opt;
|
|
1446
1284
|
}
|
|
1447
1285
|
}
|
|
1448
|
-
|
|
1449
1286
|
function canScrollHorizontally(bounds) {
|
|
1450
1287
|
return (direction === 'horizontal' || direction === 'both') && bounds.scrollWidth > bounds.clientWidth && !isNaN(bounds.scrollWidth);
|
|
1451
1288
|
}
|
|
1452
|
-
|
|
1453
1289
|
function canScrollVertically(bounds) {
|
|
1454
1290
|
return (direction === 'vertical' || direction === 'both') && bounds.scrollHeight > bounds.clientHeight && !isNaN(bounds.scrollHeight);
|
|
1455
|
-
}
|
|
1291
|
+
}
|
|
1456
1292
|
|
|
1293
|
+
// scroll bar
|
|
1457
1294
|
|
|
1458
1295
|
function showScrollbarTrack(bounds) {
|
|
1459
1296
|
if (isHorizontalScrollbarVisible && canScrollHorizontally(bounds) && horizontalScrollbarHandle.current) {
|
|
1460
1297
|
horizontalScrollbarHandle.current.showScrollbarTrack();
|
|
1461
1298
|
}
|
|
1462
|
-
|
|
1463
1299
|
if (isVerticalScrollbarVisible && canScrollVertically(bounds) && verticalScrollbarHandle.current) {
|
|
1464
1300
|
verticalScrollbarHandle.current.showScrollbarTrack();
|
|
1465
1301
|
}
|
|
1466
1302
|
}
|
|
1467
|
-
|
|
1468
1303
|
function updateScrollbarTrack(scrollbarRef, bounds) {
|
|
1469
1304
|
scrollbarRef.current.update(_objectSpread(_objectSpread({}, bounds), {}, {
|
|
1470
1305
|
scrollLeft: mutableRef.current.scrollLeft,
|
|
1471
1306
|
scrollTop: mutableRef.current.scrollTop
|
|
1472
1307
|
}));
|
|
1473
1308
|
}
|
|
1474
|
-
|
|
1475
1309
|
function startHidingScrollbarTrack() {
|
|
1476
1310
|
if (isHorizontalScrollbarVisible && horizontalScrollbarHandle.current) {
|
|
1477
1311
|
horizontalScrollbarHandle.current.startHidingScrollbarTrack();
|
|
1478
1312
|
}
|
|
1479
|
-
|
|
1480
1313
|
if (isVerticalScrollbarVisible && verticalScrollbarHandle.current) {
|
|
1481
1314
|
verticalScrollbarHandle.current.startHidingScrollbarTrack();
|
|
1482
1315
|
}
|
|
1483
1316
|
}
|
|
1484
|
-
|
|
1485
1317
|
function updateScrollbars() {
|
|
1486
1318
|
var bounds = getScrollBounds(),
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1319
|
+
canScrollH = canScrollHorizontally(bounds),
|
|
1320
|
+
canScrollV = canScrollVertically(bounds),
|
|
1321
|
+
curHorizontalScrollbarVisible = horizontalScrollbar === 'auto' ? canScrollH : horizontalScrollbar === 'visible',
|
|
1322
|
+
curVerticalScrollbarVisible = verticalScrollbar === 'auto' ? canScrollV : verticalScrollbar === 'visible';
|
|
1491
1323
|
|
|
1324
|
+
// determine if we should hide or show any scrollbars
|
|
1492
1325
|
var isVisibilityChanged = isHorizontalScrollbarVisible !== curHorizontalScrollbarVisible || isVerticalScrollbarVisible !== curVerticalScrollbarVisible;
|
|
1493
|
-
|
|
1494
1326
|
if (isVisibilityChanged) {
|
|
1495
1327
|
// one or both scrollbars have changed visibility
|
|
1496
1328
|
setIsHorizontalScrollbarVisible(curHorizontalScrollbarVisible);
|
|
@@ -1500,14 +1332,12 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1500
1332
|
updateScrollbarTrackSize();
|
|
1501
1333
|
}
|
|
1502
1334
|
}
|
|
1503
|
-
|
|
1504
1335
|
function updateScrollbarTrackSize() {
|
|
1505
1336
|
var bounds = getScrollBounds(),
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1337
|
+
canScrollH = canScrollHorizontally(bounds),
|
|
1338
|
+
canScrollV = canScrollVertically(bounds),
|
|
1339
|
+
curHorizontalScrollbarVisible = horizontalScrollbar === 'auto' ? canScrollH : horizontalScrollbar === 'visible',
|
|
1340
|
+
curVerticalScrollbarVisible = verticalScrollbar === 'auto' ? canScrollV : verticalScrollbar === 'visible';
|
|
1511
1341
|
if (curHorizontalScrollbarVisible || curVerticalScrollbarVisible) {
|
|
1512
1342
|
// no visibility change but need to notify whichever scrollbars are visible of the
|
|
1513
1343
|
// updated bounds and scroll position
|
|
@@ -1515,75 +1345,73 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1515
1345
|
scrollLeft: mutableRef.current.scrollLeft,
|
|
1516
1346
|
scrollTop: mutableRef.current.scrollTop
|
|
1517
1347
|
});
|
|
1518
|
-
|
|
1519
1348
|
if (curHorizontalScrollbarVisible && horizontalScrollbarHandle.current) {
|
|
1520
1349
|
horizontalScrollbarHandle.current.update(updatedBounds);
|
|
1521
1350
|
}
|
|
1522
|
-
|
|
1523
1351
|
if (curVerticalScrollbarVisible && verticalScrollbarHandle.current) {
|
|
1524
1352
|
verticalScrollbarHandle.current.update(updatedBounds);
|
|
1525
1353
|
}
|
|
1526
|
-
|
|
1527
1354
|
return true;
|
|
1528
1355
|
}
|
|
1529
|
-
|
|
1530
1356
|
return false;
|
|
1531
|
-
}
|
|
1357
|
+
}
|
|
1532
1358
|
|
|
1359
|
+
// ref
|
|
1533
1360
|
|
|
1534
1361
|
function getScrollBounds() {
|
|
1535
1362
|
if (scrollContentHandle.current && typeof scrollContentHandle.current.getScrollBounds === 'function') {
|
|
1536
1363
|
return scrollContentHandle.current.getScrollBounds();
|
|
1537
1364
|
}
|
|
1538
1365
|
}
|
|
1539
|
-
|
|
1540
1366
|
function getMoreInfo() {
|
|
1541
1367
|
if (scrollContentHandle.current && typeof scrollContentHandle.current.getMoreInfo === 'function') {
|
|
1542
1368
|
return scrollContentHandle.current.getMoreInfo();
|
|
1543
1369
|
}
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1370
|
+
}
|
|
1546
1371
|
|
|
1372
|
+
// FIXME setting event handlers directly to work on the V8 snapshot.
|
|
1547
1373
|
function addEventListeners() {
|
|
1548
1374
|
(0, _utilEvent["default"])('wheel').addEventListener(scrollContainerRef, onWheel);
|
|
1549
1375
|
(0, _utilEvent["default"])('keydown').addEventListener(scrollContainerRef, onKeyDown);
|
|
1550
|
-
(0, _utilEvent["default"])('mousedown').addEventListener(scrollContainerRef, onMouseDown);
|
|
1376
|
+
(0, _utilEvent["default"])('mousedown').addEventListener(scrollContainerRef, onMouseDown);
|
|
1551
1377
|
|
|
1378
|
+
// scrollMode 'native' [[
|
|
1552
1379
|
if (scrollMode === 'native' && scrollContentRef.current) {
|
|
1553
1380
|
(0, _utilEvent["default"])('scroll').addEventListener(scrollContentRef, onScroll, {
|
|
1554
1381
|
passive: true
|
|
1555
1382
|
});
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1383
|
+
}
|
|
1384
|
+
// scrollMode 'native' ]]
|
|
1558
1385
|
|
|
1559
1386
|
if (props.addEventListeners) {
|
|
1560
1387
|
props.addEventListeners(scrollContentRef);
|
|
1561
1388
|
}
|
|
1562
|
-
|
|
1563
1389
|
if (window) {
|
|
1564
1390
|
(0, _utilEvent["default"])('resize').addEventListener(window, handleResizeWindow);
|
|
1565
1391
|
}
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1392
|
+
}
|
|
1568
1393
|
|
|
1394
|
+
// FIXME setting event handlers directly to work on the V8 snapshot.
|
|
1569
1395
|
function removeEventListeners() {
|
|
1570
1396
|
(0, _utilEvent["default"])('wheel').removeEventListener(scrollContainerRef, onWheel);
|
|
1571
1397
|
(0, _utilEvent["default"])('keydown').removeEventListener(scrollContainerRef, onKeyDown);
|
|
1572
|
-
(0, _utilEvent["default"])('mousedown').removeEventListener(scrollContainerRef, onMouseDown);
|
|
1398
|
+
(0, _utilEvent["default"])('mousedown').removeEventListener(scrollContainerRef, onMouseDown);
|
|
1573
1399
|
|
|
1400
|
+
// scrollMode 'native' [[
|
|
1574
1401
|
(0, _utilEvent["default"])('scroll').removeEventListener(scrollContentRef, onScroll, {
|
|
1575
1402
|
passive: true
|
|
1576
|
-
});
|
|
1403
|
+
});
|
|
1404
|
+
// scrollMode 'native' ]]
|
|
1577
1405
|
|
|
1578
1406
|
if (props.removeEventListeners) {
|
|
1579
1407
|
props.removeEventListeners(scrollContentRef);
|
|
1580
1408
|
}
|
|
1581
|
-
|
|
1582
1409
|
(0, _utilEvent["default"])('resize').removeEventListener(window, handleResizeWindow);
|
|
1583
|
-
}
|
|
1584
|
-
// scrollMode 'translate' [[
|
|
1410
|
+
}
|
|
1585
1411
|
|
|
1412
|
+
// render
|
|
1586
1413
|
|
|
1414
|
+
// scrollMode 'translate' [[
|
|
1587
1415
|
function handleScroll() {
|
|
1588
1416
|
// Prevent scroll by focus.
|
|
1589
1417
|
// VirtualList and VirtualGridList DO NOT receive `onscroll` event.
|
|
@@ -1593,13 +1421,12 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1593
1421
|
scrollContentRef.current.scrollTop = mutableRef.current.scrollTop;
|
|
1594
1422
|
scrollContentRef.current.scrollLeft = scrollContentHandle.current.getRtlPositionX(mutableRef.current.scrollLeft);
|
|
1595
1423
|
}
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1424
|
+
}
|
|
1425
|
+
// scrollMode 'translate' ]]
|
|
1598
1426
|
|
|
1599
1427
|
function scrollContainerContainsDangerously(target) {
|
|
1600
1428
|
return _utilDOM["default"].containsDangerously(scrollContainerRef, target);
|
|
1601
1429
|
}
|
|
1602
|
-
|
|
1603
1430
|
assignProperties('scrollContainerProps', _objectSpread(_objectSpread({}, rest), {}, {
|
|
1604
1431
|
className: [scrollClasses]
|
|
1605
1432
|
}));
|
|
@@ -1615,9 +1442,10 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1615
1442
|
onDragStart: onDragStart,
|
|
1616
1443
|
onFlick: onFlick,
|
|
1617
1444
|
onTouchStart: scrollMode === 'native' ? onTouchStart : null // scrollMode 'native'
|
|
1618
|
-
|
|
1619
1445
|
}));
|
|
1620
|
-
|
|
1446
|
+
|
|
1447
|
+
var scrollContentProps = props.itemRenderer ?
|
|
1448
|
+
// If the child component is a VirtualList
|
|
1621
1449
|
{
|
|
1622
1450
|
childProps: childProps,
|
|
1623
1451
|
clientSize: clientSize,
|
|
@@ -1636,15 +1464,12 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1636
1464
|
cbScrollTo: scrollTo,
|
|
1637
1465
|
className: [_useScrollModule["default"].scrollFill],
|
|
1638
1466
|
direction: direction,
|
|
1639
|
-
|
|
1640
1467
|
get isHorizontalScrollbarVisible() {
|
|
1641
1468
|
return isHorizontalScrollbarVisible;
|
|
1642
1469
|
},
|
|
1643
|
-
|
|
1644
1470
|
get isVerticalScrollbarVisible() {
|
|
1645
1471
|
return isVerticalScrollbarVisible;
|
|
1646
1472
|
},
|
|
1647
|
-
|
|
1648
1473
|
onScroll: scrollMode === 'translate' ? handleScroll : null,
|
|
1649
1474
|
role: role,
|
|
1650
1475
|
rtl: rtl,
|
|
@@ -1682,56 +1507,53 @@ var useScrollBase = function useScrollBase(props) {
|
|
|
1682
1507
|
}
|
|
1683
1508
|
};
|
|
1684
1509
|
};
|
|
1685
|
-
|
|
1686
1510
|
exports.useScrollBase = useScrollBase;
|
|
1687
|
-
|
|
1688
1511
|
var assignPropertiesOf = function assignPropertiesOf(instance) {
|
|
1689
1512
|
return function (name, properties) {
|
|
1690
1513
|
if (!instance[name]) {
|
|
1691
1514
|
instance[name] = {};
|
|
1692
1515
|
}
|
|
1693
|
-
|
|
1694
1516
|
if (typeof properties === 'object') {
|
|
1695
1517
|
for (var property in properties) {
|
|
1696
1518
|
if (property === 'className') {
|
|
1697
1519
|
process.env.NODE_ENV !== "production" ? (0, _warning["default"])(Array.isArray(properties.className), 'Unsupported other types for `className` prop except Array') : void 0;
|
|
1698
1520
|
instance[name].className = (0, _classnames["default"])(instance[name].className, properties.className);
|
|
1699
1521
|
} else {
|
|
1700
|
-
process.env.NODE_ENV !== "production" ? (0, _warning["default"])(!instance[name][property], 'Unsupported to push value in the same ' + property + ' prop.') : void 0;
|
|
1522
|
+
process.env.NODE_ENV !== "production" ? (0, _warning["default"])(!instance[name][property], 'Unsupported to push value in the same ' + property + ' prop.') : void 0;
|
|
1701
1523
|
|
|
1524
|
+
// Override the previous value.
|
|
1702
1525
|
instance[name][property] = properties[property];
|
|
1703
1526
|
}
|
|
1704
1527
|
}
|
|
1705
1528
|
}
|
|
1706
1529
|
};
|
|
1707
1530
|
};
|
|
1708
|
-
|
|
1709
1531
|
exports.assignPropertiesOf = assignPropertiesOf;
|
|
1710
|
-
|
|
1711
1532
|
var useScroll = function useScroll(props) {
|
|
1712
1533
|
// Mutable value
|
|
1534
|
+
|
|
1713
1535
|
var scrollContainerRef = (0, _react.useRef)({});
|
|
1714
1536
|
var scrollContentHandle = (0, _react.useRef)({});
|
|
1715
1537
|
var scrollContentRef = (0, _react.useRef)({});
|
|
1716
1538
|
var itemRefs = (0, _react.useRef)([]);
|
|
1717
1539
|
var horizontalScrollbarHandle = (0, _react.useRef)({});
|
|
1718
|
-
var verticalScrollbarHandle = (0, _react.useRef)({});
|
|
1540
|
+
var verticalScrollbarHandle = (0, _react.useRef)({});
|
|
1719
1541
|
|
|
1720
|
-
|
|
1721
|
-
assignProperties = assignPropertiesOf(collectionOfProperties);
|
|
1542
|
+
// Hooks
|
|
1722
1543
|
|
|
1544
|
+
var collectionOfProperties = {},
|
|
1545
|
+
assignProperties = assignPropertiesOf(collectionOfProperties);
|
|
1723
1546
|
var _useScrollBase = useScrollBase(_objectSpread(_objectSpread({}, props), {}, {
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1547
|
+
assignProperties: assignProperties,
|
|
1548
|
+
horizontalScrollbarHandle: horizontalScrollbarHandle,
|
|
1549
|
+
scrollContainerRef: scrollContainerRef,
|
|
1550
|
+
scrollContentHandle: scrollContentHandle,
|
|
1551
|
+
scrollContentRef: scrollContentRef,
|
|
1552
|
+
verticalScrollbarHandle: verticalScrollbarHandle
|
|
1553
|
+
})),
|
|
1554
|
+
scrollContentWrapper = _useScrollBase.scrollContentWrapper,
|
|
1555
|
+
isHorizontalScrollbarVisible = _useScrollBase.isHorizontalScrollbarVisible,
|
|
1556
|
+
isVerticalScrollbarVisible = _useScrollBase.isVerticalScrollbarVisible;
|
|
1735
1557
|
assignProperties('scrollContainerProps', {
|
|
1736
1558
|
ref: scrollContainerRef
|
|
1737
1559
|
});
|
|
@@ -1745,7 +1567,9 @@ var useScroll = function useScroll(props) {
|
|
|
1745
1567
|
});
|
|
1746
1568
|
assignProperties('horizontalScrollbarProps', {
|
|
1747
1569
|
scrollbarHandle: horizontalScrollbarHandle
|
|
1748
|
-
});
|
|
1570
|
+
});
|
|
1571
|
+
|
|
1572
|
+
// Return
|
|
1749
1573
|
|
|
1750
1574
|
return _objectSpread(_objectSpread({}, collectionOfProperties), {}, {
|
|
1751
1575
|
scrollContentWrapper: scrollContentWrapper,
|
|
@@ -1754,7 +1578,6 @@ var useScroll = function useScroll(props) {
|
|
|
1754
1578
|
isVerticalScrollbarVisible: isVerticalScrollbarVisible
|
|
1755
1579
|
});
|
|
1756
1580
|
};
|
|
1757
|
-
|
|
1758
1581
|
exports.useScroll = useScroll;
|
|
1759
1582
|
var _default = useScroll;
|
|
1760
1583
|
exports["default"] = _default;
|