Native base的FAB开始激活

问题描述 投票:0回答:1

我知道我的问题与这个问题有关 - React Native - Native Base FAB (Floating Action Button): Clicking the FAB automatically calls sub-buttons 'onpress'但是,如果它没有正确的答案,我会问我的。

我已经从官方文档复制了代码片段并面临着这个问题:每当我打开一个包含FAB的屏幕时,该按钮显示为按下(激活)。当我点击它(关闭它)并转到另一个屏幕时,FAB再次显示其内容。但是当我启动屏幕时,状态是“假的”。

我的错误在哪里?

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>
    );
}
}
javascript node.js react-native native-base floating-action-button
1个回答
-1
投票

你尝试过:this.state = {active:false};

© www.soinside.com 2019 - 2024. All rights reserved.