Posts

React Native with PHP

Problem Statement Create an App to input two numbers as num1 and num2 and send the data to some PHP file product.php to calculate the product and show that product in a dialog. React Native Code import React from 'react' ; import { TextInput , View , Button } from 'react-native' ; class DemoApp extends React . Component { constructor (props) { super (props); this .state = { num1: 0 ,num2: 0 ,product: 0 }; } calcProduct=()=> { var data = { "num1" : this .state.num1, "num2" : this .state.num2 } fetch( "https://cbse.abes.ac.in/reactnative/product.php" , { method: "POST" , headers: { 'Accept' : 'application/json' , 'Content-Type' : 'application/json' , }, body: JSON .stringify(data) }) .then( function (response){ var data= JSON .parse(response._bodyText); alert( "Product is " +data.product); }) .then( function (d...

Using Drawer in React Native

//Contributed by Rishabh Kumar -- B.Tech. 2016 Batch import React ,{ Component } from 'react' ; import { View } from 'react-native' ; import { DrawerNavigator } from 'react-navigation' import Home from './components/Home/index' ; import Register from './components/Register/index' ; import Main from './components/Main/index' ; export default class App extends Component { render(){ return ( < Drawer /> ); } } const Drawer = DrawerNavigator ({ Home :{screen: Main }, Login :{screen: Home }, Register :{screen: Register }, }) //Home --> index.js import React ,{ Component } from 'react' ; import { View , Text , TextInput , StyleSheet , TouchableOpacity } from 'react-native' ; import { Card } from 'react-native-paper' class Home extends Component { render(){ return ( ...

Using GET method with React Native

import React from 'react'; import { FlatList, ActivityIndicator, Text, View } from 'react-native'; export default class FetchExample extends React.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( <View style={{flex: 1, padding: 20}}> <ActivityIndicator/> </View> ) } return( <View style={{flex: 1, paddingTop:20}}> <FlatList data={this.state.dataSource} renderItem={({item}) => <T...

Using POST method in React Native

fetch(' https://mywebsite.com/endpoint/' , { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ firstParam: 'yourValue', secondParam: 'yourOtherValue', }), }).then((response) => response.json()) .then((responseJson) => { return responseJson.movies; }) .catch((error) => { console.error(error); });

Adding Background Image in React Native

Using ImageBackground Control to add the background image     return ( < ImageBackground source = { ... } style = { { width : '100%' , height : '100%' } } > < Text > Inside < / Text > < / ImageBackground > ) ;