diff --git a/App.js b/App.js index 224d7db..d39e367 100644 --- a/App.js +++ b/App.js @@ -1,16 +1,47 @@ import React, { Component } from 'react'; -import { AppRegistry, Text, View } from 'react-native'; +import { FlatList, AppRegistry, ActivityIndicator, Text, View } from 'react-native'; -export default class App extends Component { - render() { - return ( - - Open up App.js to start working on your app! - Changes you make will automatically reload. - Shake your phone to open the developer menu. - - ); +export default class FetchExample extends Component { + constructor(props){ + super(props); + this.state ={ isLoading: true} + } + + componentDidMount(){ + return fetch('https://facebook.github.io/react-native/movies.json') + .then((response) => response.json()) + .then((responseJson) => { + this.setState({ + isLoading: false, + dataSource: responseJson.movies, + }, function () { + + }); + }) + .catch((error) =>{ + console.error(error); + }); + } + + render() { + if(this.state.isLoading){ + return( + + + + ) + } + + return( + + {item.title}, {item.releaseYear}} + keyExtractor={(item, index) => index} + /> + + ); } } -AppRegistry.registerComponent('react-native-tutorial', () => App); +AppRegistry.registerComponent('react-native-tutorial', () => FetchExample);