|
| 1 | +import React, { Component } from 'react' |
| 2 | +import { Platform, StyleSheet, View, Image, Dimensions, ImageBackground } from 'react-native'; |
| 3 | +import { Text } from 'react-native-ui-kitten' |
| 4 | +import { SafeAreaView } from 'react-navigation' |
| 5 | +import { FlatList } from 'react-native-gesture-handler'; |
| 6 | + |
| 7 | +const WINDOW_WIDTH = Dimensions.get('window').width |
| 8 | + |
| 9 | +class HomeScreen extends Component { |
| 10 | + |
| 11 | + constructor(props) { |
| 12 | + super(props) |
| 13 | + } |
| 14 | + |
| 15 | + // TODO: replace with real data |
| 16 | + state = { |
| 17 | + data: [], |
| 18 | + 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 | + ] |
| 25 | + } |
| 26 | + |
| 27 | + _keyExtractor = (item, index) => index.toString() |
| 28 | + |
| 29 | + _renderItem = ({ item }) => { |
| 30 | + const { title, image } = item |
| 31 | + |
| 32 | + 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 > |
| 38 | + ) |
| 39 | + } |
| 40 | + |
| 41 | + render() { |
| 42 | + return ( |
| 43 | + <SafeAreaView style={styles.container}> |
| 44 | + <Text category="h4" style={styles.welcome}>Welcome to Home Screen</Text> |
| 45 | + <Text style={styles.instructions}>To get started, edit App.js</Text> |
| 46 | + |
| 47 | + <FlatList |
| 48 | + data={this.state.images} |
| 49 | + renderItem={this._renderItem.bind(this)} |
| 50 | + keyExtractor={this._keyExtractor.bind(this)} |
| 51 | + /> |
| 52 | + </SafeAreaView> |
| 53 | + ) |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +export default HomeScreen; |
| 58 | + |
| 59 | +const styles = StyleSheet.create({ |
| 60 | + container: { |
| 61 | + flex: 1, |
| 62 | + backgroundColor: '#F5FCFF', |
| 63 | + }, |
| 64 | + titleText: { |
| 65 | + alignSelf: 'flex-start', |
| 66 | + marginLeft: 20, |
| 67 | + marginBottom: 10, |
| 68 | + color: 'white' |
| 69 | + }, |
| 70 | + largeThumbnail: { |
| 71 | + width: WINDOW_WIDTH - 40, |
| 72 | + height: WINDOW_WIDTH - 40, |
| 73 | + marginRight: 20, |
| 74 | + marginLeft: 20, |
| 75 | + marginBottom: 40, |
| 76 | + borderRadius: 12, |
| 77 | + elevation: 4, |
| 78 | + shadowOffset: { height: 4, width: 4 }, |
| 79 | + shadowOpacity: 0.8, |
| 80 | + shadowColor: '#424242', |
| 81 | + shadowRadius: 8 |
| 82 | + }, |
| 83 | + welcome: { |
| 84 | + fontSize: 20, |
| 85 | + textAlign: 'center', |
| 86 | + margin: 10, |
| 87 | + }, |
| 88 | + instructions: { |
| 89 | + textAlign: 'center', |
| 90 | + color: '#333333', |
| 91 | + marginBottom: 5, |
| 92 | + }, |
| 93 | +}); |
0 commit comments