@scrolia/react-native
Version:
A headless scrollbar component
33 lines (31 loc) • 1.08 kB
JavaScript
import { tryPlugin } from "../../../functions/plugin.mjs";
const setLengthFn = ({ axis, disabled, animated, plugins, hvTrack, hvThumb, total, view, viewOffset, scrollbarLength, setScrollbarLength }) => {
return () => {
const _total = total.current;
const _view = view.current;
const _viewOffset = viewOffset.current;
const scrollbarLengthNext = _view / _total * _view;
let result;
for (const plugin of plugins) {
if (!plugin.onSetLength) continue;
result = tryPlugin(plugin, plugin.onSetLength, {
axis,
isDisabled: disabled,
isAnimated: animated,
isDefined: hvTrack && hvThumb,
total: _total,
view: _view,
viewOffset: _viewOffset,
scrollbarLengthPrev: scrollbarLength,
scrollbarLengthNext: result?.scrollbarLength ?? scrollbarLengthNext
}) ?? result;
}
let length;
if (result?.scrollbarLength) length = result.scrollbarLength;
else length = scrollbarLengthNext;
if (_view >= _total) setScrollbarLength(0);
else setScrollbarLength(length);
};
};
export { setLengthFn };
//# sourceMappingURL=length.mjs.map