Created
September 29, 2018 04:15
-
-
Save Muneefm/7f57c2acb776ec4a757ae1b9ddaef7eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sample React Native App | |
* https://github.com/facebook/react-native | |
* | |
* @format | |
* @flow | |
*/ | |
import React, {Component} from 'react'; | |
import {Platform, StyleSheet, Text, View, Button, Image} from 'react-native'; | |
type Props = {}; | |
export default class App extends Component<Props> { | |
constructor(){ | |
super(); | |
this.URL = 'https://728b324c2a.to.intercept.rest/'; | |
this.imageBaseUrl = 'https://image.tmdb.org/t/p/w500'; | |
// Now lets Create Interceptor Url | |
// Original Url = https://raw.githubusercontent.com | |
// Image base url = https://image.tmdb.org/t/p/w500 | |
this.state = { | |
isLoadingComplete: false, | |
} | |
} | |
requestData = ()=> { | |
const url = this.URL+'Muneefm/demo_data/master/movie.json?rand='+(1 + Math.random() * (99999 - 1)); | |
console.log(url) | |
fetch(url).then((response) => response.json()).then((jsonResponse) => { | |
this.setState({ | |
title: jsonResponse.original_title, | |
imagePath: jsonResponse.poster_path, | |
isLoadingComplete: true | |
}) | |
}); | |
} | |
render() { | |
return ( | |
<View style={styles.container}> | |
<Button onPress= {this.requestData.bind(this)} title ={ 'Request Data'}/> | |
{this.state.isLoadingComplete && <Image style={styles.image} source = {{uri: this.imageBaseUrl+this.state.imagePath}} />} | |
{this.state.isLoadingComplete && <Text> {this.state.title} </Text>} | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
backgroundColor: '#F5FCFF', | |
}, | |
image: { | |
width: 300, | |
height: 300, | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment