0

这是代码,非常简单:

render() {
    return (
     <View>
         <StatusBar hidden={true}/>
        <View style={{height:0}}>
            <Button>
                <Text>this button should disappears</Text>
            </Button>
        </View>
        <View style={{height:400}}>
            <Text>other view</Text>
        </View>
    </View>
   );
}

这是输出屏幕截图:

在此处输入图像描述

可以看到,因为视图的高度为0,所以按钮的容器是不可见的,但是为什么按钮还是可见的呢?

经过一番工作,我发现我必须设置 'other view' 的 backgroundColor&height 来重叠按钮,就像这样:

<View style={{height:400,backgroundColor:'white'}}>
   <Text>other view</Text>
</View>

现在该按钮将不可见。

好奇怪,就是Button组件,其他几个组件我都试过了,都ok,难道是Button的bug?

感谢 Wong Kim Hau 的提醒,Button 组件来自 'native-base',而不是 'react native'

我正在使用 react-native v0.44.0,native-base 2.1.3

4

1 回答 1

0

只需使用“react-native”中的默认按钮组件,它就可以正常工作。

于 2017-05-23T05:32:25.793 回答