android - React-Native:FlatList 中的反向 zIndex

标签 android ios react-native z-index react-native-flatlist

我有一个包含一些元素的 FlatList,其中顶部元素应与底部元素重叠。为此,我想反转 zIndex,但 FlatList 不断覆盖我的 zIndex。

在下面的代码中,我尝试使用 zIndex: 0 - index 反转 zIndex,但它不起作用

import React, { Component } from "react";
import { FlatList, Text, View, StyleSheet } from "react-native";

export default class App extends React.Component {
  _renderPost({ index }) {
    return <View style={[styles.item, { zIndex: 0 - index, }]} />;
  }
  render() {
    return <FlatList data={[1, 2, 3, 4, 5,]} renderItem={this._renderPost} />;
  }
}

const styles = StyleSheet.create({
  item: { 
    height: 200, 
    borderWidth:2, 
    borderBottomLeftRadius:50, 
    borderBottomRightRadius:50, 
    marginBottom: -50, 
    backgroundColor:"white",
  },
});

link to Expo Snack

output

最佳答案

我还没有设法在 zIndex 的帮助下做到这一点,因为问题似乎是从索引设置 zIndex,它似乎不起作用。

我设法做到这一点的方法是反转 FlatList,并使用反转列弯曲方向的样式,以便它实际上也滚动到顶部。请注意,这实际上也会以相反的顺序显示帖子,因此需要翻转底层数组才能达到想要的结果

import React, { Component } from "react";
import { FlatList, Text, View, StyleSheet } from "react-native";

export default class App extends React.Component {
  _renderPost({ index }) {
    return <View style={styles.item} />;
  }
  render() {
    return <FlatList style={styles.container} inverted data={[1, 2, 3, 4, 5,]} renderItem={this._renderPost}/>;
  }
}

const styles = StyleSheet.create({
  item: { 
    height: 200, 
    borderWidth:2, 
    borderBottomLeftRadius:50, 
    borderBottomRightRadius:50, 
    marginBottom: -50, 
    backgroundColor:"white",
  },
  container: {
    flexDirection: 'column-reverse'
  }
});

关于android - React-Native:FlatList 中的反向 zIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54601102/

相关文章:

android - 是否可以使用 python 支持的框架 Django 开发 native 移动应用程序的后端?

ios - 关联对象与属性与实例变量之间的区别

android - react-native-hsm-maps 实现但显示空白?

react-native - 胜利图表 - x 轴标签缩短、自定义范围并防止重叠

javascript - undefined 不是对象(评估 this.props.navigation.navigate)

android - 如何将选项卡之间的数据作为 Activity 发送?

android - Android 上的离线 Web 应用程序 HTML5

java - 调用 onPageFinished() 时页面未完全加载

ios - OpenCV 的 Iphone 6 相机校准

ios - 如何在测试之间更改应用程序 Config.plist