Adding 'visible' event listener doesn't trigger first time hidden tab becomes visible
When you adding an event listener to a tab:
if (node.getComponent() === 'myComponent') {
node.setEventListener('visibility', () => {
setLoadedMyComponent(true);
});
}
This will only fire the second time the component becomes visible if the component starts off as a hidden tab. I can see from consoling the node.GetComp() the listener is added straight away. However the event handler doesn't seem to understand it has become visible
The problem is that the callback is called from the layout method, before the component is actually rendered (via a call to the factory), so by the time the factory method is called it's too late to register the handler for the first callback.
I hadn't realised this before, may need to change how this works.
One way around it is to register the listener against the model using something like:
model.visitNodes((node: Node, level: number) => {
if (node instanceof TabNode) {
node.setEventListener("visibility", function(p){console.log("visibility", node.getName(), p);});
}
});
This sounds good, is a it a big change? I've actually come across a second use case for this today.
I'll see if I can use the model in the mean time
EDIT: Works a treat, thanks @nealus