Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import { View, StyleSheet, Image, Text, FlatList } from 'react-native';
  3. import { Header, Icon } from 'react-native-elements';
  4. import { Thumbnail } from 'native-base';
  5.  
  6. export default class DashboardScreen extends React.Component {
  7.     static navigationOptions = {
  8.         title: 'Dashboard',
  9.     };
  10.  
  11.     state = {
  12.         streamsData: []
  13.     }
  14.  
  15.     async componentWillMount() {
  16.         await fetch('https://api.twitch.tv/helix/games/top', {
  17.             method: 'GET',
  18.             headers: {
  19.                 'Client-ID': 'urv4sceohtr6tljxoethd3slru1344',
  20.             }
  21.         }).then(response => response.text())
  22.         .then(response => JSON.parse(response))
  23.         .then(streamsData => this.setState({ streamsData: streamsData["data"] }));
  24.     }
  25.  
  26.     render() {
  27.         return(
  28.             <View style={styles.container}>
  29.                 <Header backgroundColor='#202225'>
  30.                     <Image source={require('../assets/images/logo.png')} style={{ width: 40, height: 40 }} />
  31.                     <Text style={{ fontSize: 20, color: 'skyblue' }}>Dashboard</Text>
  32.                     <Icon type='font-awesome' name='plus' color='skyblue' />
  33.                 </Header>
  34.                 <FlatList
  35.                     data={this.state.streamsData}
  36.                     renderItem={(item) => {
  37.                         var url = item.item['box_art_url'].replace("{width}", '80').replace("{height}", '80');
  38.                         return(
  39.                             <View style={{
  40.                                 padding: 10,
  41.                             }}>
  42.                                 <Thumbnail large source={{ uri: url }} />
  43.                                 <Text style={{
  44.                                     textAlign: 'center',
  45.                                     width: 80,
  46.                                     marginTop: 10,
  47.                                 }}>{ item.item['name'] }</Text>
  48.                             </View>
  49.                         );
  50.                     }}
  51.                     horizontal={true}
  52.                     showsHorizontalScrollIndicator={false}
  53.                     style={{
  54.                         height: 10,
  55.                     }}
  56.                 />
  57.             </View>
  58.         );
  59.     }
  60.  
  61. }
  62.  
  63. const styles = StyleSheet.create({
  64.     container: {
  65.         flex: 1,
  66.         //alignItems: 'center',
  67.         //justifyContent: 'center',
  68.         backgroundColor: '#363636',
  69.     },
  70. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement