React Native - Native Base FAB (Floating Action Button): Clicking the FAB automatically calls sub-buttons 'onpress'

强颜欢笑 提交于 2019-12-11 05:47:45

问题


I am currently trying to implement the floating action button (FAB) from the native-base framework. I simply copied the code, and added a single onPress method to one of the sub-buttoms (Facebook-Logo in this case). However, this onPress is triggered when I click the FAB button, instead of the facebook-button which should appear AFTER clicking the FAB button.

In short: desired behvaior: 1. click FAB button 2. due to number 1, let facebook button appear 3. click facebook button to trigger onPress

the behvaior I get: 1. click FAB button 2. onPress as defined in facebook's button is triggered

I have not really changed anything in the code, here is what it looks like:

<Fab
                active={this.state.fabActive}
                direction="up"
                containerStyle={{ marginLeft: 10 }}
                style={{ backgroundColor: '#5067FF' }}
                position="bottomRight"
                onPress={() => this.setState({ feedbackComponentVisible: !this.state.fabActive })}>
                <Icon name="share" />
                <Button style={{ backgroundColor: '#34A34F' }}>
                    <Icon name="logo-whatsapp" />
                </Button>
                <Button style={{ backgroundColor: '#3B5998' }} onPress={() => this.setState({feedbackComponentVisible: true})}>
                    <Icon name="logo-facebook" />
                </Button>
                <Button disabled style={{ backgroundColor: '#DD5144' }}>
                    <Icon name="mail" />
                </Button>
</Fab>

回答1:


Problem is this code segment changing the same state from both onPress functions. According to this if this.state.fabActive=false then value will change to true when you click on the FAB button which you expecting from sub-button. Try with two separate states, this should work.



来源:https://stackoverflow.com/questions/44486733/react-native-native-base-fab-floating-action-button-clicking-the-fab-automa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!