-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageLazyLoading.js
55 lines (52 loc) · 1.32 KB
/
ImageLazyLoading.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* eslint-disable prettier/prettier */
import {
View,
Text,
FlatList,
Image,
Dimensions,
ActivityIndicator,
} from 'react-native';
import React, {useEffect, useState} from 'react';
import FastImage from 'react-native-fast-image';
const ImageLazyLoading = () => {
const [data, setData] = useState([]);
useEffect(() => {
getData();
}, []);
const getData = () => {
fetch('https://jsonplaceholder.typicode.com/photos')
.then(res => res.json())
.then(res => {
console.log(res);
setData(res);
});
};
return (
<View>
<FlatList
data={data}
renderItem={({item, index}) => {
return (
<View>
{/* <Image
onLoadStart={() => {}}
source={{uri: item.thumbnailUrl}}
style={{width: Dimensions.get('window').width, height: 100}}
/> */}
<FastImage
style={{width: Dimensions.get('window').width, height: 100}}
source={{
uri: item.thumbnailUrl,
priority: FastImage.priority.normal,
}}
defaultSource={require('./src/images/placeholder.jpeg')}
/>
</View>
);
}}
/>
</View>
);
};
export default ImageLazyLoading;