gpt4 book ai didi

javascript - 选项卡 View 是否仅在滑动时呈现组件?

转载 作者:行者123 更新时间:2023-11-28 03:41:44 25 4
gpt4 key购买 nike

我正在处理的屏幕需要一些选项卡导航。它工作得很好,但有一个问题。仅当我按下我想要转到的选项卡时,它才会在滑动时呈现组件。它不做任何事情。例如:我在选项卡 3 上,我想转到选项卡 1。如果我单击选项卡 1,则什么也不会发生。我必须在此过程中通过选项卡 2 滑动到它。我不想那样。这是我的代码。

<TabView
navigationState={this.state}
renderScene={this.renderScene}
onIndexChange={index => this.setState({ index })}
initialLayout={{ width: Dimensions.get('window').width }}
/>

渲染场景函数

renderScene = ({ route, jumpTo }) => {
switch (route.key) {
case 'activity':
return <ProfileActivity jumpTo={jumpTo} />;
case 'circles':
return <ProfileCircles jumpTo={jumpTo} />;
case 'friends':
return <ProfileFriends jumpTo={jumpTo} />;
default:
return null;
}
};

状态

  state = {
index: 0,
routes: [
{ key: 'activity', title: 'Activity' },
{ key: 'circles', title: 'Circles' },
{ key: 'friends', title: 'Friends' }
]
};

最佳答案

你可以使用惰性 Prop !如果你想一次渲染所有选项卡,那么你应该将 false 传递给lazy prop,否则传递 true。

查看文档
https://github.com/react-native-community/react-native-tab-view/blob/master/README.md

关于javascript - 选项卡 View 是否仅在滑动时呈现组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57254223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com