【发布时间】:2017-12-27 23:22:13
【问题描述】:
我只是一个初学者,一直在致力于一个需要尽快完成的项目。我通过 API 获取了超过 5000 个数据列表,但是,该列表在滚动时效率不高,因此会破坏应用程序。我一直在 React Native 中搜索 FlatList 组件,我无法在我的项目中正确实施。
有人可以提供有关如何解决此问题的建议。我在下面附上了我的源代码 -
import React, {Component} from 'react';
import {Text, View, FlatList, ScrollView } from 'react-native';
import axios from 'axios';
import GalleryDetail from './GalleryDetail';
class GalleryList extends Component {
state = { photos: []};
componentWillMount() {
axios.get('http://jsonplaceholder.typicode.com/photos')
.then(response => this.setState({ photos: response.data })).
catch((error)=> console.warn("fetch Error: ", error));
}
renderPhotos() {
return this.state.photos.map( photos =>
<GalleryDetail key={photos.id} photos= {photos}/>
);
}
render () {
return (
<View>
<ScrollView>
{this.renderPhotos()}
</ScrollView>
</View>
);
}
}
export default GalleryList;
我的 GalleryDetail 在哪里
import React, {Component} from 'react';
import { Text, View, Image } from 'react-native';
import Card from './Card';
import CardSection from './CardSection';
const GalleryDetail = (props)=> {
return (
<Card>
<CardSection style = {styles.headerContentStyle}>
<Image
style={styles.thumbnailStyle}
source = {{ uri: props.photos.thumbnailUrl}}/>
<Text style= {styles.textStyle}>{props.photos.title}</Text>
</CardSection>
</Card>
);
};
const styles = {
headerContentStyle: {
flexDirection: 'column',
justifyContent: 'space-around'
},
thumbnailStyle: {
height: 50,
width: 50
},
textStyle: {
textAlign: 'right',
marginLeft: 3,
marginRight: 3,
}
}
export default GalleryDetail;
很抱歉没有提供正确的代码段。请帮忙
【问题讨论】:
标签: reactjs listview react-native redux react-native-flatlist