diff --git a/docs/toastandroid.md b/docs/toastandroid.md index 0db8e967855..799586e74a6 100644 --- a/docs/toastandroid.md +++ b/docs/toastandroid.md @@ -3,92 +3,121 @@ id: toastandroid title: ToastAndroid --- -This exposes the native ToastAndroid module as a JS module. This has a function 'show' which takes the following parameters: +React Native's ToastAndroid API exposes the Android platform's ToastAndroid module as a JS module. It provides the method `show(message, duration)` which takes the following parameters: -1. String message: A string with the text to toast -2. int duration: The duration of the toast. May be ToastAndroid.SHORT or ToastAndroid.LONG +* _message_ A string with the text to toast +* _duration_ The duration of the toast—either `ToastAndroid.SHORT` or `ToastAndroid.LONG` -There is also a function `showWithGravity` to specify the layout gravity. May be ToastAndroid.TOP, ToastAndroid.BOTTOM, ToastAndroid.CENTER. +You can alternatively use `showWithGravity(message, duration, gravity)` to specify where the toast appears in the screen's layout. May be `ToastAndroid.TOP`, `ToastAndroid.BOTTOM` or `ToastAndroid.CENTER`. -The 'showWithGravityAndOffset' function adds on the ability to specify offset These offset values will translate to pixels. +The 'showWithGravityAndOffset(message, duration, gravity, xOffset, yOffset)' method adds the ability to specify an offset with in pixels. -Basic usage: +```SnackPlayer name=Toast%20Android%20API%20Example&supportedPlatforms=android +import React from "react"; +import { View, StyleSheet, ToastAndroid, Button } from "react-native"; +import Constants from "expo-constants"; +const App = () => { + const showToast = () => { + ToastAndroid.show("A pikachu appeared nearby !", ToastAndroid.SHORT); + }; -```jsx -import {ToastAndroid} from 'react-native'; - -ToastAndroid.show('A pikachu appeared nearby !', ToastAndroid.SHORT); -ToastAndroid.showWithGravity( - 'All Your Base Are Belong To Us', - ToastAndroid.SHORT, - ToastAndroid.CENTER, -); -ToastAndroid.showWithGravityAndOffset( - 'A wild toast appeared!', - ToastAndroid.LONG, - ToastAndroid.BOTTOM, - 25, - 50, -); + const showToastWithGravity = () => { + ToastAndroid.showWithGravity( + "All Your Base Are Belong To Us", + ToastAndroid.SHORT, + ToastAndroid.CENTER + ); + }; + + const showToastWithGravityAndOffset = () => { + ToastAndroid.showWithGravityAndOffset( + "A wild toast appeared!", + ToastAndroid.LONG, + ToastAndroid.BOTTOM, + 25, + 50 + ); + }; + + return ( + +