gpt4 book ai didi

react-native - React Native如何反转ListView的堆栈顺序?

转载 作者:行者123 更新时间:2023-12-04 04:04:52 29 4
gpt4 key购买 nike

我需要构建图像的 ListView。我希望前者应该像这样高于后者:

enter image description here

这是我的代码:

class PostsList extends Component {
constructor(props, context) {
super(props, context);
var dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => ri !== r2
});
this.state = {
dataSource: dataSource.cloneWithRows([
'img_1.jpg',
'img_2.jpg',
'img_3.jpg',
'img_4.jpg',
'img_5.jpg',
])
}
}
renderRow(rowData, sectionID, rowID) {
console.log(typeof rowID);
var width = Dimensions.get('window').width;
var height = width * 3 / 4;
var marginTop = (rowID === '0') ? 0 : -height/2;
var source;
if(rowID === '0') {
source = require('../assets/img/img_1.jpg');
} else if(rowID === '1') {
source = require('../assets/img/img_2.jpg');
} else if(rowID === '2') {
source = require('../assets/img/img_3.jpg');
} else if(rowID === '3') {
source = require('../assets/img/img_4.jpg');
} else if(rowID === '4') {
source = require('../assets/img/img_5.jpg');
}
return (
<Image
style={[styles.image, {width, height, marginTop}]}
source={source}
resizeMode={Image.resizeMode.contain}
/>
);
}
render() {
return(
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}
/>
);
}
};

结果是这样的:

enter image description here

我知道为什么会这样,但我不知道如何反转堆栈顺序。

这里使用的数据是假的,真正的数据将是通过 Ajax 从另一个站点获取的 JSON 文件。

最佳答案

我之前遇到过同样的要求,这是我使用的代码的关键(使用react-native-invertible-scroll-view包):

// `https://github.com/exponent/react-native-invertible-scroll-view`
...
import InvertibleScrollView from 'react-native-invertible-scroll-view';
...
this.state = { dataSource: dataSource.cloneWithRows([...].reverse()), ... }
...
<ListView renderScrollComponent={props => <InvertibleScrollView {...props} inverted />} ... />
...

关于react-native - React Native如何反转ListView的堆栈顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35109863/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com