5
5
Dimensions ,
6
6
ImageBackground ,
7
7
TouchableWithoutFeedback ,
8
- Animated
8
+ Animated ,
9
+ Image
9
10
} from 'react-native' ;
10
11
import { Text } from 'react-native-ui-kitten'
11
12
import { SafeAreaView } from 'react-navigation'
@@ -30,7 +31,8 @@ class HomeScreen extends Component {
30
31
{ title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
31
32
{ title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
32
33
] ,
33
- activeImage : null
34
+ activeImage : null ,
35
+ showCloseIcon : false
34
36
}
35
37
36
38
componentWillMount ( ) {
@@ -40,7 +42,6 @@ class HomeScreen extends Component {
40
42
this . dimensions = new Animated . ValueXY ( )
41
43
}
42
44
43
-
44
45
_openImage = ( index ) => {
45
46
const ref = this . allImagesRefs [ index ]
46
47
ref . measure ( ( x , y , width , height , pageX , pageY ) => {
@@ -81,7 +82,9 @@ class HomeScreen extends Component {
81
82
toValue : dHeight ,
82
83
duration : 300
83
84
} )
84
- ] ) . start ( )
85
+ ] ) . start ( ( ) => {
86
+ this . setState ( { showCloseIcon : true } )
87
+ } )
85
88
} )
86
89
} )
87
90
} )
@@ -113,7 +116,46 @@ class HomeScreen extends Component {
113
116
)
114
117
}
115
118
119
+ _closeImage = ( ) => {
120
+ this . setState ( { showCloseIcon : false } )
121
+ Animated . parallel ( [
122
+ Animated . timing ( this . position . x , {
123
+ toValue : this . oldPosition . x ,
124
+ duration : 300
125
+ } ) ,
126
+ Animated . timing ( this . position . y , {
127
+ toValue : this . oldPosition . y ,
128
+ duration : 300
129
+ } ) ,
130
+ Animated . timing ( this . dimensions . x , {
131
+ toValue : this . oldPosition . width ,
132
+ duration : 300
133
+ } ) ,
134
+ Animated . timing ( this . dimensions . y , {
135
+ toValue : this . oldPosition . height ,
136
+ duration : 300
137
+ } )
138
+ ] ) . start ( ( ) => {
139
+ this . setState ( { activeImage : null } )
140
+ } )
141
+ }
142
+
143
+ _showCloseIcon ( ) {
144
+ if ( this . state . showCloseIcon ) {
145
+ return < TouchableWithoutFeedback
146
+ onPress = { this . _closeImage }
147
+ >
148
+ < Image
149
+ style = { styles . closeIcon }
150
+ source = { require ( './img/cancel.png' ) } />
151
+ </ TouchableWithoutFeedback >
152
+ } else {
153
+ return null
154
+ }
155
+ }
156
+
116
157
render ( ) {
158
+ // These params are manipulated by Animation
117
159
const activeImageStyle = {
118
160
width : this . dimensions . x ,
119
161
height : this . dimensions . y ,
@@ -123,9 +165,6 @@ class HomeScreen extends Component {
123
165
124
166
return (
125
167
< SafeAreaView style = { styles . container } >
126
- < Text category = "h4" style = { styles . welcome } > Welcome to Home Screen</ Text >
127
- < Text style = { styles . instructions } > To get started, edit App.js</ Text >
128
-
129
168
< FlatList
130
169
data = { this . state . images }
131
170
renderItem = { this . _renderItem . bind ( this ) }
@@ -136,13 +175,14 @@ class HomeScreen extends Component {
136
175
pointerEvents = { this . state . activeImage ? 'auto' : 'none' }
137
176
>
138
177
< View
139
- style = { { flex : 2 } }
178
+ style = { { flex : 2 , marginBottom : 80 } }
140
179
ref = { view => ( this . viewImage = view ) } >
141
180
< Animated . Image
142
181
style = { [ { top : 0 , left : 0 , height : null , width : null , resizeMode : 'cover' } , activeImageStyle ] }
143
182
source = { { uri : this . state . activeImage ? this . state . activeImage . imageUrl : null } }
144
183
>
145
184
</ Animated . Image >
185
+ { this . _showCloseIcon ( ) }
146
186
</ View >
147
187
</ View >
148
188
</ SafeAreaView >
@@ -178,14 +218,12 @@ const styles = StyleSheet.create({
178
218
shadowColor : '#424242' ,
179
219
shadowRadius : 8
180
220
} ,
181
- welcome : {
182
- fontSize : 20 ,
183
- textAlign : 'center' ,
184
- margin : 10 ,
185
- } ,
186
- instructions : {
187
- textAlign : 'center' ,
188
- color : '#333333' ,
189
- marginBottom : 5 ,
190
- } ,
221
+ closeIcon : {
222
+ position : 'absolute' ,
223
+ right : 20 ,
224
+ top : 40 ,
225
+ height : 32 ,
226
+ width : 32 ,
227
+ tintColor : 'white'
228
+ }
191
229
} ) ;
0 commit comments