Skip to content

Instantly share code, notes, and snippets.

@Muneefm
Created September 29, 2018 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Muneefm/7f57c2acb776ec4a757ae1b9ddaef7eb to your computer and use it in GitHub Desktop.
Save Muneefm/7f57c2acb776ec4a757ae1b9ddaef7eb to your computer and use it in GitHub Desktop.
/**
* 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