flash-section-list
Version:
SectionList base on FlashList
58 lines (57 loc) • 1.76 kB
JavaScript
"use strict";
import { useEffect, useState } from 'react';
import { View } from 'react-native';
import { jsx as _jsx } from "react/jsx-runtime";
class Dummy {
type = '~d!u@m#m$y%^&*()';
constructor(layoutManager) {
this.layoutManager = layoutManager;
}
localIndices = new Map(); // key: sectionIndex, value: localIndex
layouts = new Map(); // key: sectionIndex, value: Layout
listeners = new Map();
setListener(sectionIndex, listener) {
this.listeners.set(sectionIndex, listener);
return () => {
this.listeners.delete(sectionIndex);
};
}
getListener(sectionIndex) {
return this.listeners.get(sectionIndex);
}
emitSize(sectionIndex, localIndex, layout) {
const oldLocalIndex = this.localIndices.get(sectionIndex) ?? 0;
if (localIndex < oldLocalIndex) return;
this.localIndices.set(sectionIndex, localIndex);
const oldLayout = this.layouts.get(sectionIndex);
if (oldLayout && !this.layoutManager.isChanged(oldLayout, layout)) {
return;
}
this.layouts.set(sectionIndex, layout);
this.getListener(sectionIndex)?.(layout);
}
View = ({
sectionIndex,
disabled
}) => {
const [size, setSize] = useState();
useEffect(() => {
if (disabled) return;
const layout = this.layouts.get(sectionIndex);
setSize(this.layoutManager.getSize(layout));
const clean = this.setListener(sectionIndex, layout => {
setSize(this.layoutManager.getSize(layout));
});
return () => {
clean();
};
}, [sectionIndex, disabled]);
return /*#__PURE__*/_jsx(View, {
style: !disabled && {
[this.layoutManager.getSizeProperty()]: size
}
});
};
}
export default Dummy;
//# sourceMappingURL=Dummy.js.map