All tab bars are rendered into the screen simultaneously. This behaviour results in wrong Firebase Analytics reports. I'm used to track the current active screen when the component is mounted, but this doesn't seem to be a good option as all the tabs screen components are mounted at the same time.
So even if the user never opens a certain tab will be reported as if he did. How can I overcome this? Should I try send the current screen to analytics in other way than the component did mount?
Have you tried using componentDidAppear? Doc here
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.
Have you tried using
componentDidAppear? Doc here
How do I get to use this method with functional components?
I'm using Hooks for my entire app
You can put this in your functional component:
React.useEffect(() => {
const navigationEventListener =
Navigation.events().registerComponentDidAppearListener(({ componentId: id }) => {
// Check whether the event is fired in this screen.
if (componentId !== id) return
// put your code here...
})
return () => {
navigationEventListener.remove()
}
}, [])
You can turn this into a util function if you are using this pattern alot:
export const useComponentAppear = ({ componentId, onAppear }: Props) => {
React.useEffect(() => {
const navigationEventListener =
Navigation.events().registerComponentDidAppearListener(
({ componentId: compId }) => {
if (componentId !== compId) return
onAppear()
}
)
return () => navigationEventListener.remove()
}, [])
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.
Most helpful comment
You can put this in your functional component:
You can turn this into a util function if you are using this pattern alot: