I have a TabView
component that has multiple tabs containing components. These components have entire hierarchies of other components. How could I know from any child component nested arbitrarily deep in one of these hierarchies whether or not it's parent tab is in focus in the TabView
?
Preferably, I would want to implement this similar to react-navigation
's withNavigationFocus
(or an equivalent hook) so that any component can know if it's in tab focus without having to pass props down the chain of components. I'm thinking you could have a TabViewContext
that components can register themselves as focus listeners to by doing a useContext
. The TabViewContext
would be provided by the TabView
and the TabView
would be responsible for determining what registered listeners are in focus when tabs change. My dilemma is I don't know how the TabView
could determine efficiently what nested child components come into focus when the tab changes. Any ideas?