flash-section-list
Version:
SectionList base on FlashList
62 lines (61 loc) • 1.91 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _jsxRuntime = require("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] = (0, _react.useState)();
(0, _react.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__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: !disabled && {
[this.layoutManager.getSizeProperty()]: size
}
});
};
}
var _default = exports.default = Dummy;
//# sourceMappingURL=Dummy.js.map