@backpackapp-io/react-native-toast

中文文档
0.15.1发布于 2025/11/03MITTypeScriptESM + CJS近 30 天下载 35.2万

A toasting library for React Native. Built in features such as swipe to dismiss, multiple toasts, & no context power this library.

原始使用文档
文档目录4 节
  1. Why?
  2. Installation
  3. Cool, now what?
  4. Example

React Native Toast

runs with expo GitHub license npm

English · 한국어

A toast library for react-native, built on react-hot-toast. It supports features such as multiple toasts, keyboard handling, swipe to dismiss, positional toasts, and JS promises. It runs on iOS, android, and web.


video


Why?

I know what you might be thinking (jeez, another toast library?). Trust me here, this is the last toast library you will need. I built this library to meet my specific app needs and decided to open-source it after realizing that it truly is a top-notch toast library. Just give it a try.

Features

  • Multiple toasts, multiple options. Want a toast on the top, bottom, different colors, or different types at the same time? Got it.
  • Keyboard handling (both iOS and Android). Move those toasts out of the way and into view when the user opens the keyboard
  • Swipe to dismiss
  • Positional toasts (top, bottom, top-left, top-right, bottom-left, bottom-right)
  • Customizable (custom styles, dimensions, duration, and even create your own component to be used in the toast)
  • Add support for promises <-- Really! Call toast.promise(my_promise) and watch react-native-toast work its magic, automatically updating the toast with a custom message on success -- or an error message on reject.
  • Runs on web
  • Support for native modals
  • Callbacks for onPress, onShow, and onHide

Documentation

View the full documentation here

Getting Started

Installation

yarn add @backpackapp-io/react-native-toast
# or
npm i @backpackapp-io/react-native-toast

Peer Dependencies

Install and link react-native-reanimated, react-native-safe-area-context, and react-native-gesture-handler

yarn add react-native-reanimated react-native-safe-area-context react-native-gesture-handler

Ensure you follow the installation of each package

Using expo?

npx expo install react-native-reanimated react-native-safe-area-context react-native-gesture-handler

Cool, now what?

Wrap your App with <GestureHandlerRootView /> and <SafeAreaProvider /> & add the <Toasts /> component to the root of your app.

Call toast("My Toast Message") whenever you are ready from anywhere in your app.

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 (
    <SafeAreaProvider>
      <GestureHandlerRootView style={styles.container}>
        <View>{/*The rest of your app*/}</View>
        <Toasts /> {/* <---- Add Here */}
      </GestureHandlerRootView>
    </SafeAreaProvider>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Example

Regular Toast

toast("This is my first toast", {
  duration: 3000,
});

Promise Toast

const sleep = new Promise((resolve, reject) => {
  setTimeout(() => {
    if (Math.random() > 0.5) {
      resolve({
        username: 'Nick',
      });
    } else {
      reject('Username is undefined');
    }
  }, 2500);
});

toast.promise(
  sleep,
  {
    loading: 'Loading...',
    success: (data: any) => 'Welcome ' + data.username,
    error: (err) => err.toString(),
  },
  {
    position: ToastPosition.BOTTOM,
  }
);

Loading Toast

const id = toast.loading('I am loading. Dismiss me whenever...');

setTimeout(() => {
  toast.dismiss(id);
}, 3000);

Success Toast

toast.success('Success!', {
  width: 300
});

Error Toast

toast.error('Wow. That Sucked!');

版本与发布记录

@backpackapp-io/react-native-toast 共发布 22 个版本,首次发布于 2022/07/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.15.1latest2025/11/031 年前
0.15.02025/10/211 年前
1.0.02025/10/211 年前
0.14.02025/04/241.5 年前
0.13.02024/11/271.9 年前
0.12.12024/11/132 年前

关于 @backpackapp-io/react-native-toast 的常见问题

@backpackapp-io/react-native-toast 是什么?

A toasting library for React Native. Built in features such as swipe to dismiss, multiple toasts, & no context power this library.

如何安装 @backpackapp-io/react-native-toast?

在项目目录运行 npm install @backpackapp-io/react-native-toast,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)、react-native-gesture-handler(>=2.2.1)、react-native-reanimated(>=2.8.0)、react-native-safe-area-context(>=4.2.4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@backpackapp-io/react-native-toast 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@backpackapp-io/react-native-toast 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@backpackapp-io/react-native-toast 可以商用吗?

@backpackapp-io/react-native-toast 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@backpackapp-io/react-native-toast 的下载量有多少?

根据 npm 官方下载统计,@backpackapp-io/react-native-toast 在 2026/10/08 – 2026/11/06 这 30 天内被下载 351,971 次,日均约 11,732 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@backpackapp-io/react-native-toast 还在维护吗?

最新版本 0.15.1 发布于 2025/11/03(1 年前);至今共发布 22 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/07/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。