【发布时间】:2018-09-27 15:13:56
【问题描述】:
主组件:
<Tabs
initialPage={this.props.day}
tabBarUnderlineStyle={{ backgroundColor: '#5AF158' }}
renderTabBar={() => <ScrollableTab />}>
{this.renderTabHeader()}
</Tabs>
renderTabHeader() {
return (
this.props.dateArray.map((date, i) =>
<Tab
key={i}
heading={date.format('DD/MM')}
tabStyle={styles.tabStyling}
activeTabStyle={styles.activeTabStyle}
textStyle={styles.tabTextStyle}
activeTextStyle={styles.activeTabTextStyle}
>
<View style={{ backgroundColor: '#EEEEEE', flex: 1 }}>
<Content contentDate={date.format('YYYY-MM-DD')} />
</View>
</Tab>
)
);
}
内容组件:
class Content extends Component {
componentWillMount() {
console.log('Component Will Mount() ?');
this.props.loadTransactionByDate({ date: this.props.contentDate });
}
render() {
return (
<View><Text>{this.props.contentDate}</Text></View>
);
}
基本上,在 MainComponent 中有一组选项卡。我注意到Content 第一次点击或激活他们的标签时会安装一些相当奇怪的东西?
第一次的意思是,我们可以点击Tab index 2,看到控制台登录componentWillMount,然后我们切换到另一个tab,如果再次回到Tab index 2,componentWillMount将不再被触发?
【问题讨论】:
-
不确定我是否记错了,但是当您切换选项卡时,您的组件已经挂载,因此不会再次挂载。它可能会调用componentWillUpdate(),但不会调用componentWillMount();
-
您可以添加您正在使用的 Tabs 包吗?
-
@PritishVaidya:我可以知道您所说的
Tabs的 Tabs 包包含在此问题的第一部分中吗 -
@GuiHerzog:我不这么认为,因为我已经为我的
Content组件中的每个组件生命周期方法制作了控制台日志。显然这些组件生命周期只在第一次加载时触发,一旦再次访问相同的选项卡,这些组件生命周期方法都不会被触发 -
在此处查看有关此查询的更新github.com/GeekyAnts/NativeBase/issues/1798
标签: react-native components lifecycle native-base