toast in react native code example

Example 1: touchableopacity as button in react native

//React Native Button element doesn't have style props and offers very 
//few customization. Use TochableXXX elements instead.
//TouchableOpacity works fine

import {
  TouchableOpacity,
  Text,
} from "react-native";


          Add
			


const styles = StyleSheet.create({

  button: {
    width: 200,
    marginTop: 20,
    backgroundColor: "green",
    padding: 15,
    borderRadius: 50,
  },
  btnText: {
    color: "white",
    fontSize: 20,
    justifyContent: "center",
    textAlign: "center",
  },
});

Example 2: toast in react native

import {ToastAndroid} from 'react-native' ;

.... 

ToastAndroid.showWithGravity(
	"All Your Base Are Belong To Us",
    ToastAndroid.SHORT,
    ToastAndroid.CENTER
);

....

Example 3: toast in react native

import {ToastAndroid} from 'react-native' ;

.... 

ToastAndroid.showWithGravity(
	"All Your Base Are Belong To Us",
    ToastAndroid.SHORT,
    ToastAndroid.CENTER
);

....

Example 4: hooks in react

import React, { useState, useEffect } from "react";
export default props => {
  console.log("componentWillMount");
  console.log("componentWillReceiveProps", props);
  const [x, setX] = useState(0);
  const [y, setY] = useState(0);
  const [moveCount, setMoveCount] = useState(0);
  const [cross, setCross] = useState(0);
  const mouseMoveHandler = event => {
    setX(event.clientX);
    setY(event.clientY);
  };
  useEffect(() => {
    console.log("componentDidMount");
    document.addEventListener("mousemove", mouseMoveHandler);
    return () => {
      console.log("componentWillUnmount");
      document.removeEventListener("mousemove", mouseMoveHandler);
    };
  }, []); // empty-array means don't watch for any updates
  useEffect(
    () => {
      // if (componentDidUpdate & (x or y changed))
      setMoveCount(moveCount + 1);
    },
    [x, y]
  );
useEffect(() => {
    // if componentDidUpdate or componentDidMount
    if (x === y) {
      setCross(x);
    }
  });
  return (
    

Your mouse is at {x}, {y} position.

Your mouse has moved {moveCount} times

X and Y positions were last equal at {cross}, {cross}

); };

Example 5: toast in react native

import {ToastAndroid} from 'react-native' ;

.... 

ToastAndroid.showWithGravity(
	"All Your Base Are Belong To Us",
    ToastAndroid.SHORT,
    ToastAndroid.CENTER
);

....

Example 6: toast in react native

import {ToastAndroid} from 'react-native' ;

.... 

ToastAndroid.showWithGravity(
	"All Your Base Are Belong To Us",
    ToastAndroid.SHORT,
    ToastAndroid.CENTER
);

....

Tags:

Misc Example