1
1
import React , { Component } from 'react'
2
- import { Platform , StyleSheet , View , Image , Dimensions , ImageBackground } from 'react-native' ;
2
+ import {
3
+ StyleSheet ,
4
+ View ,
5
+ Dimensions ,
6
+ ImageBackground ,
7
+ TouchableWithoutFeedback ,
8
+ Animated
9
+ } from 'react-native' ;
3
10
import { Text } from 'react-native-ui-kitten'
4
11
import { SafeAreaView } from 'react-navigation'
5
- import { FlatList } from 'react-native-gesture-handler' ;
12
+ import { FlatList , TouchableOpacity } from 'react-native-gesture-handler' ;
6
13
7
14
const WINDOW_WIDTH = Dimensions . get ( 'window' ) . width
8
15
@@ -16,25 +23,71 @@ class HomeScreen extends Component {
16
23
state = {
17
24
data : [ ] ,
18
25
images : [
19
- { title : "Breaking Bad" , image : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
20
- { title : "Breaking Bad" , image : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
21
- { title : "Breaking Bad" , image : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
22
- { title : "Breaking Bad" , image : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
23
- { title : "Breaking Bad" , image : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
24
- ]
26
+ { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
27
+ { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
28
+ { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
29
+ { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
30
+ { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
31
+ ] ,
32
+ activeImage : null
33
+ }
34
+
35
+ componentWillMount ( ) {
36
+ this . allImagesRefs = { }
37
+ this . oldPosition = { }
38
+ this . position = new Animated . ValueXY ( )
39
+ this . dimensions = new Animated . ValueXY ( )
40
+ }
41
+
42
+
43
+ _openImage = ( index ) => {
44
+ const ref = this . allImagesRefs [ index ]
45
+ ref . measure ( ( x , y , width , height , pageX , pageY ) => {
46
+ this . oldPosition . x = pageX
47
+ this . oldPosition . y = pageY
48
+ this . oldPosition . width = width
49
+ this . oldPosition . height = height
50
+
51
+ this . position . setValue ( {
52
+ x : pageX ,
53
+ y : pageY
54
+ } )
55
+
56
+ this . dimensions . setValue ( {
57
+ x : width ,
58
+ y : height
59
+ } )
60
+
61
+ const img = this . state . images [ index ]
62
+ this . setState ( {
63
+ activeImage : img
64
+ } )
65
+ } )
25
66
}
26
67
27
68
_keyExtractor = ( item , index ) => index . toString ( )
28
69
29
- _renderItem = ( { item } ) => {
30
- const { title, image } = item
70
+ _renderItem = ( { item, index } ) => {
71
+ const { title, imageUrl } = item
31
72
32
73
return (
33
- < ImageBackground source = { { uri : image } } style = { styles . largeThumbnail } imageStyle = { { borderRadius : 12 } } >
34
- < View style = { { position : 'absolute' , bottom : 0 } } >
35
- < Text category = "h4" style = { styles . titleText } > { title } </ Text >
36
- </ View >
37
- </ ImageBackground >
74
+ < TouchableWithoutFeedback
75
+ onPress = { ( ) => this . _openImage ( index ) }
76
+ key = { index } >
77
+ < Animated . View style = { styles . imageContainer } >
78
+ < View
79
+ ref = { imgRef => ( this . allImagesRefs [ index ] = imgRef ) } >
80
+ < ImageBackground
81
+ source = { { uri : imageUrl } }
82
+ style = { styles . largeThumbnail }
83
+ imageStyle = { { borderRadius : 12 } } >
84
+ < View style = { { position : 'absolute' , bottom : 0 } } >
85
+ < Text category = "h4" style = { styles . titleText } > { title } </ Text >
86
+ </ View >
87
+ </ ImageBackground >
88
+ </ View >
89
+ </ Animated . View >
90
+ </ TouchableWithoutFeedback >
38
91
)
39
92
}
40
93
@@ -49,6 +102,18 @@ class HomeScreen extends Component {
49
102
renderItem = { this . _renderItem . bind ( this ) }
50
103
keyExtractor = { this . _keyExtractor . bind ( this ) }
51
104
/>
105
+ < View
106
+ style = { StyleSheet . absoluteFill }
107
+ pointerEvents = { this . state . activeImage ? 'auto' : 'none' }
108
+ >
109
+ < View style = { { flex : 2 } } >
110
+ < Animated . Image
111
+ style = { { height : "80%" , width : "100%" } }
112
+ source = { { uri : this . state . activeImage ? this . state . activeImage . imageUrl : null } }
113
+ >
114
+ </ Animated . Image >
115
+ </ View >
116
+ </ View >
52
117
</ SafeAreaView >
53
118
)
54
119
}
@@ -67,13 +132,15 @@ const styles = StyleSheet.create({
67
132
marginBottom : 10 ,
68
133
color : 'white'
69
134
} ,
70
- largeThumbnail : {
71
- width : WINDOW_WIDTH - 40 ,
72
- height : WINDOW_WIDTH - 40 ,
135
+ imageContainer : {
73
136
marginRight : 20 ,
74
137
marginLeft : 20 ,
75
138
marginBottom : 40 ,
76
139
borderRadius : 12 ,
140
+ } ,
141
+ largeThumbnail : {
142
+ width : WINDOW_WIDTH - 40 ,
143
+ height : WINDOW_WIDTH - 40 ,
77
144
elevation : 4 ,
78
145
shadowOffset : { height : 4 , width : 4 } ,
79
146
shadowOpacity : 0.8 ,
0 commit comments