Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import React from 'react';
  3. import { Image ,View,List,FlatList} from 'react-native';
  4. import {AppLoading, Font} from 'expo';
  5. import MaterialCommunityIcons  from '@expo/vector-icons';
  6. import  News from './News'
  7.  
  8. import { Container,Item,Input, Header, Content, Card, CardItem, Thumbnail, Icon,Text, Button, Left, Body, Right } from 'native-base';
  9. export default class NewsFeed extends React.Component {
  10.     constructor(props) {
  11.         super(props);
  12.    
  13.         this.state = {
  14.             loading: true,
  15.             page: 1
  16.         };
  17.         this.getAutoFeed();
  18.       }
  19.  
  20.      getAutoFeed() {
  21.         return fetch('https://newsapi.org/v2/everything?q=cannabis&sortBy=publishedAt&apiKey=27b1324537e14a72b461e9cf8801abff&page='+this.state.page)
  22.           .then((response) => response.json())
  23.           .then((responseJson) => {
  24.             console.log(responseJson);
  25.             this.setState(
  26.                 {
  27.                     data : responseJson.articles,
  28.                     loading : false
  29.                 }
  30.             );
  31.           })
  32.           .catch((error) => {
  33.             console.log(error);
  34.  
  35.             console.error(error);
  36.           });
  37.       }
  38.  
  39.     handleLoadMore() {
  40.         this.setState({
  41.             page: this.state.page + 1,
  42.         }, () => {
  43.             this.getAutoFeed();
  44.         }
  45.     )
  46.     }
  47.  
  48.  
  49.   render() {
  50.    
  51.     return (
  52.     <View>
  53.        
  54.                 <List>
  55.                 <FlatList
  56.                   data={this.state.data}
  57.                   keyExtractor={item => item.url}
  58.                   onEndReached= {this.handleLoadMore}
  59.                   onEndThreshold={5}
  60.                   renderItem={({ item }) => (
  61.                     <News thumbnail={{ uri: "https://scontent.flim5-4.fna.fbcdn.net/v/t1.0-9/10622895_10152268496932606_2476213355342926994_n.jpg?oh=26e87559282f220962987b361f11152f&oe=5AFBED0D"}}
  62.                         title={item.tittle}
  63.                         bodyImg= { {uri: item.urlToImage}}
  64.                         date={item.publishedAt}
  65.                         description  = {item.description}
  66.                     />
  67.                   )}
  68.                 />
  69.               </List>
  70.        
  71.        
  72.    
  73.    
  74.     </View>
  75.  
  76.      
  77.     );
  78.   }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement