@adoratorio/hades
Version:
A smooth scrollbar based on Hermes, scroll down 'till hell
45 lines • 1.39 kB
JavaScript
class NativeRender {
_native = { x: 0, y: 0 };
context = null;
options;
nativeScrollHandler;
name = 'NativeRender';
constructor(options) {
const defaults = {
scrollNode: window,
};
this.options = { ...defaults, ...options };
this.nativeScrollHandler = (e) => this.nativeScroll(e);
this.options.scrollNode.addEventListener('scroll', this.nativeScrollHandler);
}
register(context) {
this.context = context;
}
render(context) {
context.scrollTo({
x: this._native.x,
y: this._native.y,
}, 0, true);
}
scrollTo(context, position, duration) {
this.options.scrollNode.scrollTo(position.x, position.y);
}
nativeScroll(event) {
if (this.context) {
const propX = this.options.scrollNode === window ? 'scrollX' : 'scrollLeft';
const propY = this.options.scrollNode === window ? 'scrollY' : 'scrollTop';
this._native = {
x: this.options.scrollNode[propX],
y: this.options.scrollNode[propY],
};
}
}
destroy(context) {
this.options.scrollNode.removeEventListener('scroll', this.nativeScrollHandler);
}
get native() {
return this._native;
}
}
export default NativeRender;
//# sourceMappingURL=index.js.map