@@ -9,9 +9,10 @@ import {
9
9
Image
10
10
} from 'react-native' ;
11
11
import Modal from 'react-native-modal'
12
- import { Text , Button } from 'react-native-ui-kitten'
12
+ import { Text , Button , Toggle } from 'react-native-ui-kitten'
13
13
import { SafeAreaView } from 'react-navigation'
14
14
import { FlatList } from 'react-native-gesture-handler' ;
15
+ import { stylesGen , LIGHT_THEME , DARK_THEME } from './styles'
15
16
16
17
const WINDOW_WIDTH = Dimensions . get ( 'window' ) . width
17
18
const WINDOW_HEIGHT = Dimensions . get ( 'window' ) . height
@@ -20,21 +21,30 @@ class HomeScreen extends Component {
20
21
21
22
constructor ( props ) {
22
23
super ( props )
24
+
25
+ // TODO: replace with real data
26
+ this . state = {
27
+ data : [ ] ,
28
+ images : [
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
+ { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
32
+ { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
33
+ { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
34
+ ] ,
35
+ activeImage : null ,
36
+ showCloseIcon : false ,
37
+ isModalVisible : false ,
38
+ darkMode : false ,
39
+ styles : stylesGen ( LIGHT_THEME )
40
+ }
23
41
}
24
42
25
- // TODO: replace with real data
26
- state = {
27
- data : [ ] ,
28
- images : [
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
- { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
32
- { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
33
- { title : "Breaking Bad" , imageUrl : "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" } ,
34
- ] ,
35
- activeImage : null ,
36
- showCloseIcon : false ,
37
- isModalVisible : false
43
+ _toggleTheme = ( dark = false ) => {
44
+ console . log ( "method called" ) ;
45
+ let theme = dark ? DARK_THEME : LIGHT_THEME
46
+ let newStyles = stylesGen ( theme )
47
+ this . setState ( { styles : newStyles } )
38
48
}
39
49
40
50
componentWillMount ( ) {
@@ -45,43 +55,32 @@ class HomeScreen extends Component {
45
55
}
46
56
47
57
_renderEpisodeItem = ( { item, index } ) => {
58
+ const { styles } = this . state
48
59
const { title, imageUrl } = item
49
60
50
61
return (
51
- < View style = { { flexDirection : 'row' , marginBottom : 10 , backgroundColor : 'yellow' } } >
52
- < Image style = { { height : 100 , width : 100 , borderRadius : 12 } } source = { { uri : imageUrl } } />
53
- < View
54
- style = { { marginLeft : 20 , flexDirection : 'column' , backgroundColor : 'blue' } }
55
- >
56
- < Text
57
- style = { { marginTop : 8 , } }
58
- category = "h6"
59
- >
60
- { title }
61
- </ Text >
62
- < View
63
- style = { { marginTop : 8 , position : 'absolute' , bottom : 8 , backgroundColor : 'red' , flexDirection : 'row' } }
64
- >
62
+ < View style = { { flexDirection : 'row' , marginBottom : 10 } } >
63
+ < Image style = { styles . episodeImage } source = { { uri : imageUrl } } />
64
+
65
+ < View style = { { marginLeft : 20 , flexDirection : 'column' } } >
66
+ < Text style = { styles . episodeTitle } category = "h6" > { title } </ Text >
67
+ < View style = { styles . ratingContainer } >
65
68
< Image
66
- style = { { height : 14 , width : 14 , alignSelf : 'center' } }
69
+ style = { styles . ratingIcon }
67
70
source = { require ( './img/star.png' ) } > </ Image >
68
- < Text style = { { alignSelf : 'center' , marginLeft : 8 } } category = "s2" > 9.3</ Text >
71
+ < Text style = { styles . ratingText } category = "s2" > 9.3</ Text >
69
72
</ View >
70
73
</ View >
71
- < View
72
- style = { { flex : 1 , backgroundColor : 'grey' } }
73
- >
74
- < Text
75
- style = { { position : 'absolute' , right : 12 , marginTop : 16 } }
76
- category = "s1" > $9.87</ Text >
74
+
75
+ < View style = { { flex : 1 } } >
76
+ < Text style = { styles . pricingText } category = "s1" > $9.87</ Text >
77
77
< Button
78
78
status = "white"
79
79
size = "tiny"
80
- style = { { backgroundColor : '#E0E0E0' , borderRadius : 30 , position : 'absolute' , right : 0 , bottom : 0 , width : 60 } }
80
+ style = { styles . playButton }
81
81
icon = { ( style ) => {
82
82
return < Image
83
- style = { { height : 16 , width : 16 } }
84
- tintColor = "#424242"
83
+ style = { { height : 12 , width : 12 } }
85
84
source = { require ( './img/media-play.png' ) } > </ Image >
86
85
} }
87
86
>
@@ -92,7 +91,7 @@ class HomeScreen extends Component {
92
91
}
93
92
94
93
_showModal ( ) {
95
- console . log ( "modal shown" , this . state . isModalVisible ) ;
94
+ const { styles } = this . state
96
95
97
96
return (
98
97
< View style = { { flex : 1 } } >
@@ -103,16 +102,17 @@ class HomeScreen extends Component {
103
102
deviceHeight = { WINDOW_HEIGHT / 2 }
104
103
deviceWidth = { WINDOW_WIDTH }
105
104
>
106
- < View style = { { height : WINDOW_HEIGHT / 1.8 , backgroundColor : 'white' , borderRadius : 24 } } >
107
- < View style = { { marginLeft : 20 , marginRight : 20 , marginTop : 20 } } >
108
- < View style = { { flexDirection : 'row' , marginBottom : 25 , justifyContent : 'space-between' } } >
109
- < Text category = "h4" > Season 1 Episodes </ Text >
105
+ < View style = { styles . episodesModal } >
106
+ < View style = { styles . episodesContainer } >
107
+ < View style = { styles . episodesHeader } >
108
+ < Text style = { styles . headerText } category = "h4" > Season 1</ Text >
110
109
{ this . _showCloseIcon ( ) }
111
110
</ View >
112
111
< FlatList
113
112
data = { this . state . images }
114
113
keyExtractor = { this . _keyExtractor }
115
114
renderItem = { this . _renderEpisodeItem }
115
+ showsVerticalScrollIndicator = { false }
116
116
/>
117
117
</ View >
118
118
</ View >
@@ -174,6 +174,7 @@ class HomeScreen extends Component {
174
174
175
175
_renderItem = ( { item, index } ) => {
176
176
const { title, imageUrl } = item
177
+ const { styles } = this . state
177
178
178
179
return (
179
180
< TouchableWithoutFeedback
@@ -222,34 +223,51 @@ class HomeScreen extends Component {
222
223
}
223
224
224
225
_showCloseIcon ( ) {
226
+ const { styles } = this . state
227
+
225
228
if ( this . state . showCloseIcon ) {
226
- return < TouchableWithoutFeedback
227
- onPress = { this . _closeImage }
228
- >
229
- < Image
230
- style = { styles . closeIcon }
231
- source = { require ( './img/delete-button.png' ) } / >
232
- </ TouchableWithoutFeedback >
229
+ return (
230
+ < TouchableWithoutFeedback onPress = { this . _closeImage } >
231
+ < Image
232
+ style = { styles . closeIcon }
233
+ source = { require ( './img/delete-button.png' ) } />
234
+ </ TouchableWithoutFeedback >
235
+ )
233
236
} else {
234
237
return null
235
238
}
236
239
}
237
240
238
241
render ( ) {
239
- // These params are manipulated by Animation
242
+ // These params are manipulated by Animation Value
240
243
const activeImageStyle = {
241
244
width : this . dimensions . x ,
242
245
height : this . dimensions . y ,
243
246
left : this . position . x ,
244
247
top : this . position . y
245
248
}
249
+ const { styles } = this . state
246
250
247
251
return (
248
252
< SafeAreaView style = { styles . container } >
253
+ < View style = { styles . header } >
254
+ < Text style = { styles . headerText } category = "h4" > Dark mode</ Text >
255
+ < Toggle
256
+ style = { { alignSelf : 'center' } }
257
+ status = "success"
258
+ checked = { this . state . darkMode }
259
+ onChange = { ( checked ) => {
260
+ this . setState ( { darkMode : checked } )
261
+ this . _toggleTheme ( checked )
262
+ } }
263
+ >
264
+ </ Toggle >
265
+ </ View >
249
266
< FlatList
250
267
data = { this . state . images }
251
268
renderItem = { this . _renderItem . bind ( this ) }
252
269
keyExtractor = { this . _keyExtractor . bind ( this ) }
270
+ showsVerticalScrollIndicator = { false }
253
271
/>
254
272
< View
255
273
style = { StyleSheet . absoluteFill }
@@ -259,8 +277,11 @@ class HomeScreen extends Component {
259
277
style = { { flex : 2 , marginBottom : 80 } }
260
278
ref = { view => ( this . viewImage = view ) } >
261
279
< Animated . Image
262
- style = { [ { top : 0 , left : 0 , height : null , width : null , resizeMode : 'cover' } , activeImageStyle ] }
263
- source = { { uri : this . state . activeImage ? this . state . activeImage . imageUrl : null } }
280
+ style = { [ styles . seriesCardImage , activeImageStyle ] }
281
+ source = { {
282
+ uri : this . state . activeImage ?
283
+ this . state . activeImage . imageUrl : null
284
+ } }
264
285
>
265
286
</ Animated . Image >
266
287
@@ -273,39 +294,3 @@ class HomeScreen extends Component {
273
294
}
274
295
275
296
export default HomeScreen ;
276
-
277
- const styles = StyleSheet . create ( {
278
- container : {
279
- flex : 1 ,
280
- backgroundColor : '#F5FCFF' ,
281
- } ,
282
- titleText : {
283
- alignSelf : 'flex-start' ,
284
- marginLeft : 20 ,
285
- marginBottom : 10 ,
286
- color : 'white'
287
- } ,
288
- imageContainer : {
289
- marginRight : 20 ,
290
- marginLeft : 20 ,
291
- marginBottom : 40 ,
292
- borderRadius : 12 ,
293
- } ,
294
- largeThumbnail : {
295
- width : WINDOW_WIDTH - 40 ,
296
- height : WINDOW_WIDTH - 40 ,
297
- elevation : 4 ,
298
- shadowOffset : { height : 4 , width : 4 } ,
299
- shadowOpacity : 0.8 ,
300
- shadowColor : '#424242' ,
301
- shadowRadius : 8
302
- } ,
303
- closeIcon : {
304
- // position: 'absolute',
305
- // right: 0,
306
- alignSelf : 'center' ,
307
- height : 24 ,
308
- width : 24 ,
309
- tintColor : '#9E9E9E'
310
- }
311
- } ) ;
0 commit comments