mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-04-18 18:58:06 +08:00
25 lines
803 B
JavaScript
25 lines
803 B
JavaScript
const plugin =
|
|
Laya.plugin = {};
|
|
|
|
plugin.extractComponents = function(uiView, componentNames) {
|
|
const components = {};
|
|
const deepSearch = (uiView, componentNames) => {
|
|
if(!uiView.child) return;
|
|
for(let i = uiView.child.length - 1; i >= 0; i--) {
|
|
const child = uiView.child[i];
|
|
if(componentNames.includes(child?.props.name)) {
|
|
components[child.props.name] = child;
|
|
uiView.child.splice(i, 1);
|
|
continue;
|
|
}
|
|
deepSearch(child, componentNames, components);
|
|
}
|
|
};
|
|
deepSearch(uiView, componentNames);
|
|
return componentName => {
|
|
if(components[componentName]) {
|
|
return Laya.View.createComp(components[componentName]);
|
|
}
|
|
return null;
|
|
}
|
|
} |