-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
index.tsx
118 lines (108 loc) · 2.55 KB
/
index.tsx
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React, { useState, useCallback } from 'react'
import { Text, View, Image, Dimensions, StyleSheet } from 'react-native'
import Swiper from 'react-native-swiper'
import { Model } from 'react-model'
const { width } = Dimensions.get('window')
const loading = require('./img/loading.gif')
const styles = StyleSheet.create({
wrapper: {},
slide: {
flex: 1,
justifyContent: 'center',
backgroundColor: 'transparent'
},
image: {
width,
flex: 1,
backgroundColor: 'transparent'
},
loadingView: {
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundColor: 'rgba(0,0,0,.5)'
},
loadingImage: {
width: 60,
height: 60
}
})
interface SlideState {
imgList: string[]
loadQueue: number[]
}
interface SlideActions {
loaded: number
}
const SlideSchema: ModelType<SlideState, SlideActions> = {
state: {
imgList: [
'https://www.mordeo.org/files/uploads/2016/10/Cute-Angry-Birds-Mobile-Wallpaper.jpg',
'http://www.glittergraphics.org/img/74/743564/cute-wallpapers-for-mobile.jpg',
'https://wallpapercave.com/wp/wp2807409.jpg',
'https://preppywallpapers.com/wp-content/uploads/2018/08/Gorgeous-iPhone-Wallpaper-Collection-11.jpg'
],
loadQueue: [0, 0, 0, 0]
},
actions: {
loaded: index => {
return state => {
state.loadQueue[index] = 1
}
}
}
}
const Slide = props => {
return (
<View style={styles.slide}>
<Image
onLoad={() => {
props.loadHandle(props.i)
}}
style={styles.image}
source={{ uri: props.uri }}
/>
{!props.loaded && (
<View style={styles.loadingView}>
<Image style={styles.loadingImage} source={loading} />
</View>
)}
</View>
)
}
const Page = () => {
const [{ useStore }] = useState(() => Model(SlideSchema))
const [state, actions] = useStore()
const loadHandle = useCallback((i: number) => {
actions.loaded(i)
}, [])
return (
<View style={{ flex: 1 }}>
<Swiper
loadMinimal
loadMinimalSize={1}
// index={0}
style={styles.wrapper}
loop={true}
>
{state.imgList.map((item, i) => (
<Slide
loadHandle={loadHandle}
uri={item}
i={i}
key={i}
loaded={state.loadQueue[i]}
/>
))}
</Swiper>
<View>
<Text>Current Loaded Images: {state.loadQueue}</Text>
</View>
</View>
)
}
export default Page