### Start Example App Packager Source: https://github.com/backpackapp-io/react-native-toast/blob/master/CONTRIBUTING.md Starts the Metro server for the example application. Changes in JavaScript code will be reflected without a rebuild. ```sh yarn example start ``` -------------------------------- ### Run Example App on Web Source: https://github.com/backpackapp-io/react-native-toast/blob/master/CONTRIBUTING.md Builds and runs the example application on a web browser. ```sh yarn example web ``` -------------------------------- ### Install Dependencies Source: https://github.com/backpackapp-io/react-native-toast/blob/master/website/README.md Run this command to install project dependencies. ```bash yarn ``` -------------------------------- ### Start Local Development Server Source: https://github.com/backpackapp-io/react-native-toast/blob/master/website/README.md Starts a local development server for live preview. Changes are reflected without restarting. ```bash yarn start ``` -------------------------------- ### Run Example App on Android Source: https://github.com/backpackapp-io/react-native-toast/blob/master/CONTRIBUTING.md Builds and runs the example application on an Android device or emulator. Native code changes require a rebuild. ```sh yarn example android ``` -------------------------------- ### Run Example App on iOS Source: https://github.com/backpackapp-io/react-native-toast/blob/master/CONTRIBUTING.md Builds and runs the example application on an iOS simulator or device. Native code changes require a rebuild. ```sh yarn example ios ``` -------------------------------- ### Install React Native Toast Source: https://github.com/backpackapp-io/react-native-toast/blob/master/README.md Install the library using yarn or npm. Ensure peer dependencies like react-native-reanimated, react-native-safe-area-context, and react-native-gesture-handler are also installed. ```sh yarn add @backpackapp-io/react-native-toast # or npm i @backpackapp-io/react-native-toast ``` ```sh yarn add react-native-reanimated react-native-safe-area-context react-native-gesture-handler ``` ```sh npx expo install react-native-reanimated react-native-safe-area-context react-native-gesture-handler ``` -------------------------------- ### Install React Native Toast and Dependencies Source: https://context7.com/backpackapp-io/react-native-toast/llms.txt Install the package and its peer dependencies using yarn. For Expo projects, use the expo install command. ```sh yarn add @backpackapp-io/react-native-toast # Peer dependencies yarn add react-native-reanimated react-native-safe-area-context react-native-gesture-handler # Expo npx expo install react-native-reanimated react-native-safe-area-context react-native-gesture-handler ``` -------------------------------- ### Bootstrap Project Dependencies Source: https://github.com/backpackapp-io/react-native-toast/blob/master/CONTRIBUTING.md Installs all project dependencies and pods, setting up the development environment. ```sh yarn bootstrap ``` -------------------------------- ### App Setup with GestureHandlerRootView and Toasts Source: https://github.com/backpackapp-io/react-native-toast/blob/master/website/docs/getting-started.md Wrap your root component with GestureHandlerRootView and SafeAreaProvider, and include the Toasts component. This ensures proper toast rendering and gesture handling. Call toast() from anywhere after setup. ```javascript import { View, StyleSheet, Text } from 'react-native'; import { GestureHandlerRootView } from 'react-native-gesture-handler'; import { SafeAreaProvider } from 'react-native-safe-area-context'; import { toast, Toasts } from '@backpackapp-io/react-native-toast'; import { useEffect } from 'react'; export default function App() { useEffect(() => { toast('Hello'); }, []); return ( {/*The rest of your app*/} {/* <---- Add Here */} ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', }, }); ``` -------------------------------- ### Install React Native Toast with npm Source: https://github.com/backpackapp-io/react-native-toast/blob/master/website/docs/index.md Use this command to add the library to your project using npm. ```bash npm i @backpackapp-io/react-native-toast ``` -------------------------------- ### Full Custom Toast Example Source: https://github.com/backpackapp-io/react-native-toast/blob/master/website/docs/api/toast.md A comprehensive example of a custom toast using JSX, demonstrating dynamic styling and content based on toast properties like height and width. It also shows how to resolve the toast message within the custom component. ```javascript import { resolveValue } from "@backpackapp-io/react-native-toast"; tost(Math.floor(Math.random() * 1000).toString(), { width: screenWidth, disableShadow: true, customToast: (toast) => { return ( {resolveValue(toast.message, toast)} ); }, }); ``` -------------------------------- ### Install React Native Toast with Yarn Source: https://github.com/backpackapp-io/react-native-toast/blob/master/website/docs/index.md Use this command to add the library to your project using Yarn. ```bash yarn add @backpackapp-io/react-native-toast ``` -------------------------------- ### Basic Usage Source: https://github.com/backpackapp-io/react-native-toast/blob/master/website/docs/api/toast.md Demonstrates the fundamental way to call the toast function with a simple message and an example of a more customized toast with various options. ```APIDOC ## Basic Usage ### Description Shows how to display a simple toast message and a more advanced toast with custom configurations. ### Method `toast(message, options?)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **message** (string) - The message to display in the toast. - **options** (object) - Optional configuration object for the toast. - **duration** (number) - The duration in milliseconds the toast should be visible. Defaults to a system-defined value. - **position** (ToastPosition) - The vertical position of the toast (e.g., `ToastPosition.TOP`, `ToastPosition.BOTTOM`). - **icon** (string) - An icon to display next to the message. - **animationType** (string) - The type of animation to use ('timing' or 'spring'). - **animationConfig** (object) - Configuration for the toast animation. - **duration** (number) - Duration of the animation. - **flingPositionReturnDuration** (number) - Duration for returning to the original position after a fling. - **easing** (EasingFunction) - Easing function for the animation. - **customToast** (function) - A function that returns a custom React element for the toast. - **onPress** (function) - A callback function executed when the toast is pressed. - **onShow** (function) - A callback function executed when the toast is shown. - **onHide** (function) - A callback function executed when the toast is hidden, receiving the dismiss reason. ### Request Example ```js import { toast, ToastPosition, Easing } from '@backpackapp-io/react-native-toast'; // Basic toast tOast('Hello World'); // Customized toast tOast('Hello World', { duration: 4000, position: ToastPosition.TOP, icon: '👏', animationType: 'timing', animationConfig: { duration: 500, flingPositionReturnDuration: 200, easing: Easing.elastic(1), }, }); ``` ### Response None directly returned, but the toast is displayed on the screen. ``` -------------------------------- ### Install Peer Dependencies with Yarn Source: https://github.com/backpackapp-io/react-native-toast/blob/master/website/docs/index.md Install the required peer dependencies for react-native-toast using Yarn. ```bash yarn add react-native-reanimated react-native-safe-area-context react-native-gesture-handler ``` -------------------------------- ### Install Peer Dependencies with Expo Source: https://github.com/backpackapp-io/react-native-toast/blob/master/website/docs/index.md Install the required peer dependencies for react-native-toast when using Expo. ```bash npx expo install react-native-reanimated react-native-safe-area-context react-native-gesture-handler ``` -------------------------------- ### Component-Specific Logic with Toast Source: https://github.com/backpackapp-io/react-native-toast/blob/master/website/docs/api/toast.md Use individual handlers to access component-specific state, hooks, or navigation when displaying toasts. This example shows how to cancel an order and navigate after a toast interaction. ```javascript const OrderConfirmationScreen = () => { const navigation = useNavigation(); const { orderId } = useRoute().params; const { mutate: cancelOrder } = useCancelOrderMutation(); const showUndoToast = () => { toast('Order placed!', { onPress: () => { // Access component-specific state and functions cancelOrder(orderId); navigation.navigate('OrderCanceled'); }, duration: 5000, }); }; return (