native-variants
Version:
A library for handling variants in React Native components with theme support.
37 lines • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.composeRefs = composeRefs;
function setRef(ref, value) {
if (typeof ref === "function") {
return ref(value);
}
else if (ref !== null && ref !== undefined) {
ref.current = value;
}
}
function composeRefs(...refs) {
return (node) => {
let hasCleanup = false;
const cleanups = refs.map((ref) => {
const cleanup = setRef(ref, node);
if (!hasCleanup && typeof cleanup == "function") {
hasCleanup = true;
}
return cleanup;
});
if (hasCleanup) {
return () => {
for (let i = 0; i < cleanups.length; i++) {
const cleanup = cleanups[i];
if (typeof cleanup == "function") {
cleanup();
}
else {
setRef(refs[i], null);
}
}
};
}
};
}
//# sourceMappingURL=compose-refs.js.map