这是代码,非常简单:
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