【问题标题】:React Native Overlay TransparentReact Native 覆盖透明
【发布时间】:2016-06-14 17:03:23
【问题描述】:

我试了很多次,还是找不到解决办法。

在一个屏幕中,我有很多组件。我在标题和内容视图组件中分开。

在内容组件中,有地图组件(图片),还有其他组件,比如人物组件(图片)。

在地图组件中,我想要一个全屏的透明覆盖,但它只覆盖地图组件。在 react native 中,没有 z-index。我该怎么做?

<View>
  <View style={styles.header}>
    .....
  </View>
  <View style={styles.content}>
    <Image style={styles.map}>
       <View style={styles.overlay}>
         <Image style={styles.people} />
         <Image style={styles.destination} />
       </View>
    </Image>
  </View>
</View>

像这个不能覆盖全屏的例子: https://rnplay.org/apps/wHCi_A

【问题讨论】:

  • 您想在另一个视图之上再添加一个视图吗?如果是这种情况,您可以使用 react-native modal.&lt;Modal transparent=true, visible=true&gt;&lt;/Modal&gt; 了解更多信息,请查看react-native modal
  • 像这个不能覆盖全屏的例子:rnplay.org/apps/wHCi_A
  • 如果我使用 react-native modal,当 modalVisible 为 false 时如何保留项目
  • 你能查一下react-native modal。如果你需要这样的东西,你可以通过将透明属性设置为 true 来实现。如果可能的话,添加图片,这样我就可以清楚地了解您想要实现的目标。

标签: reactjs react-native


【解决方案1】:

将覆盖视图移动到根视图的视图并确保将其添加为最后一个子视图。将位置设置为绝对。像这样的

const styles= StyleSheet.create({
  overlay:{
    position: 'absolute',
    top: 0,
    bottom: 0,
    left: 0,
    right: 0,
    backgroundColor: 'rgba(0,0,0,0.2)'
}); 

<View>
  <View style={styles.header}>
    .....
  </View>
  <View style={styles.content}>
    <Image style={styles.map}>
    </Image>
  </View>
  <View style={styles.overlay}>
     <Image style={styles.people} />
     <Image style={styles.destination} />
  </View>
</View>

【讨论】:

猜你喜欢
  • 2015-08-18
  • 2016-12-10
  • 2017-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 2019-06-29
  • 1970-01-01
相关资源
最近更新 更多