React ScrollableTabView onChangeTab



我有一个有3个标签的应用程序,我想要实现的是当改变标签

时浮动按钮图标发生变化为此,我有onChangeTab函数和changeState,但我无法将其取出。现在当执行时,我得到

Can't find variable: index

我使用的库是react原生可滚动选项卡视图,有人能帮助我吗??

谢谢! !

export default class App extends Component{
changeState =(i, ref) => {
this.setState({index : i})
}

render() {

return(

<View style={styles.contentContainer}>
<ScrollableTabView
tabBarUnderlineIcon="#fff"
tabBarUnderlineStyle={{backgroundColor: "#fff"}}
tabBarActiveTextColor="#fff"
tabBarInactiveTextColor="#ddd"
tabBarBackgroundColor="#075e54"
onChangeTab={({i,ref}) => this.changeState(i,ref)}
>
<Chats tabLabel="CHATS" />
<States tabLabel="STATES" />
<Calls tabLabel="CALLS" />

</ScrollableTabView>
</View>
<ActionButton buttonColor="#075e54"
icon={<Icon name={index === 1 ? 'chat' : index === 2 ? 'call' : 'photo-camera'}></Icon>}
/>
</View>
)
}
}

你需要定义一个初始状态

this.state = {
index: 0
}

最新更新