我知道我的问题与此相关-React Native - Native Base FAB (Floating Action Button): Clicking the FAB automatically calls sub-buttons 'onpress' 但是,如果没有正确的答案,我会问我。
我已经从官方文档中复制了代码片段,并遇到了这个问题:每次当我打开包含FAB的屏幕时,按钮的显示就像按下(激活)一样。当我单击它(关闭它)并转到另一个屏幕时,FAB再次显示其内容。但是,当我启动屏幕时,状态为“ false”。
我的错误在哪里?
import React, {Component} from 'react';
import { Fab, Icon, Button } from 'native-base';
export default class PlusButton extends Component {
constructor(props) {
super(props);
this.state = {
active: 'false'
};
}
render() {
return (
<Fab
active = {this.state.active}
direction = "up"
containerStyle = {{ }}
style = {{ backgroundColor: '#ce4729' }}
position = "bottomRight"
onPress = {() => this.setState({ active: !this.state.active })}>
<Icon name = "share" />
<Button style = {{ backgroundColor: '#ce4729' }}>
<Icon name = "logo-whatsapp" />
</Button>
<Button style = {{ backgroundColor: '#ce4729' }}>
<Icon name = "logo-facebook" />
</Button>
<Button disabled style = {{ backgroundColor: '#ce4729' }}>
<Icon name = "mail" />
</Button>
</Fab>
);
}
}
答案 0 :(得分:-1)
您尝试过: this.state = { 活动:错误 };