When using bottom tabs, if selecting a different default tab other than the first one, its componentDidAppear lifecycle method is not executed. Instead, the first tab's componentDidAppear method is executed.
Yes
npm i react-native-navigation and npx rnn-link.index.js and Screen.js files.index.jsimport {Navigation} from 'react-native-navigation';
import Screen from './Screen';
Navigation.registerComponent('Screen', () => Screen);
Navigation.events().registerAppLaunchedListener(() => {
Navigation.setDefaultOptions({
bottomTab: {
selectedTextColor: 'red',
},
});
Navigation.setRoot({
root: {
bottomTabs: {
id: 'BottomTabs',
options: {
bottomTabs: {
currentTabId: 'Screen2',
},
},
children: [
{
component: {
id: 'Screen1',
name: 'Screen',
options: {
bottomTab: {
text: 'Screen 1',
},
},
},
},
{
component: {
id: 'Screen2',
name: 'Screen',
options: {
bottomTab: {
text: 'Screen 2',
},
},
},
},
],
},
},
});
});
Screen.js
import React, {useEffect} from 'react';
import {Navigation} from 'react-native-navigation';
import {SafeAreaView, StyleSheet, Text} from 'react-native';
const Screen = ({componentId}) => {
useEffect(() => {
const unsubscribe = Navigation.events().registerComponentListener(
{
componentDidAppear: () =>
console.log(`componentDidAppear ${componentId}`),
componentDidDisappear: () =>
console.log(`componentDidDisappear ${componentId}`),
},
componentId,
);
return () => unsubscribe.remove();
}, [componentId]);
return (
<SafeAreaView style={styles.root}>
<Text>Screen {componentId}</Text>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
root: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'green',
},
});
export default Screen;
npx react-native run-android.componentDidAppear Screen2 should have appeared in the logs
componentDidAppear Screen1 appeared in the logs instead.
I've seen this on my app as well, have had to engineer a workaround.
@HectorRicardo Are you sure it reproduce also on iOS? I couldn't reproduce it in your demo
@yogevbd You're right, my bad, sorry about that. I updated the bug description to indicate that it only happens on Android.
Most helpful comment
@yogevbd You're right, my bad, sorry about that. I updated the bug description to indicate that it only happens on Android.