Gab*_*ler 5 android z-index ios react-native react-native-flatlist
我有一个带有一些元素的 FlatList,其中顶部元素应该与底部元素重叠。为此,我想反转 zIndex,但 FlatList 不断覆盖我的 zIndex。
在下面的代码中,我试图用 zIndex 反转,zIndex: 0 - index但它不起作用
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",
},
});
Run Code Online (Sandbox Code Playgroud)
小智 4
我还没有设法在 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'
}
});Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1965 次 |
| 最近记录: |