【问题标题】:react-native: components with zIndex in flatlist does not seem to workreact-native:flatlist中带有zIndex的组件似乎不起作用
【发布时间】:2019-05-07 10:42:05
【问题描述】:

主渲染:

  render() {
    return (

    <View>
      <FlatList
      ListEmptyComponent={() => <DialogBox type="internet" />}
      ...
    </View>
     );

&lt;DialogBox type="internet" /&gt; 通过绝对位置设置样式的容器:

export const dialogBox = EStyleSheet.create({
   container : {
       position: 'absolute',
       justifyContent: 'center',
       alignItems: 'center',
       top: 0,
       left: 0,
       right: 0,
       bottom: 0,
       zIndex:10000

   },
   .... 

和对话框:

  <View style={dialogBox.container}>
       <View style={dialogBox.box}>
       ...

如果我删除 absolute 表单容器,它会显示。 但我想在屏幕中间(不是平面列表中间)显示它。

但是为什么 zIndex 在绝对值中不起作用?

我尝试将代码更改为:

    <View style={{position: 'absolute',zIndex:1}}>
      <FlatList
      style={{position: 'absolute',zIndex:2}}

或者这个:

    <View style={{position: 'relative'}}>
      <FlatList
      style={{position: 'relative'}}

但是没用

【问题讨论】:

    标签: react-native react-native-android react-native-flatlist react-native-stylesheet


    【解决方案1】:

    您可以将CellRendererComponent 添加到FlatList,即使只是简单地添加似乎也可以:

    CellRendererComponent={({children}) => children}
    

    注意:Android 会崩溃,除非你添加:

    removeClippedSubviews={false}
    

    【讨论】:

      【解决方案2】:

      zIndex 不仅适用于绝对位置。

      touchableCard: {
          justifyContent: "center",
          alignItems: "center",
          zIndex: 200,
          ...
        },
      
        emptyNotesInfo: {
          textAlign: "center",
          zIndex: 100,
          ...
        },
      

      试试这个:

         <View>
            <FlatList style={{flex: 1}}
              renderItem={ data => <View style={{zIndex: 2}}><Text>HERE example view</Text></View>}
            ...
            />
         </View>
        <View style={{ 
             position: "absolute", 
             zIndex: 1,
             alignContent: "center",
             alignItems: "center",
             alignSelf: "center"
           }}>
           <Text>HERE What you need too hide</Text>
        </View>
      

      【讨论】:

        猜你喜欢
        • 2017-04-17
        • 1970-01-01
        • 1970-01-01
        • 2020-04-12
        • 1970-01-01
        • 1970-01-01
        • 2021-10-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多