@capgo/capacitor-pretty-toast

中文文档
8.1.28发布于 2026/11/02MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4.1万

Native-first pretty toast notifications for Capacitor and the web

原始使用文档
文档目录19 节
  1. ➡️ Get started for free
  2. Key features
  3. Install
  4. Usage
  5. API
  6. show(...)
  7. success(...)
  8. error(...)
  9. info(...)
  10. warning(...)
  11. loading(...)
  12. update(...)
  13. promise(...)
  14. dismiss(...)
  15. dismissAll()
  16. Interfaces
  17. Type Aliases
  18. Example App
  19. Development

@capgo/capacitor-pretty-toast

Show beautiful toast notifications in your Capacitor app with native overlays on iOS and Android and a DOM renderer on web. Same toast.* API as react-native-pretty-toast.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-pretty-toast in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-pretty-toast to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

Animated Pretty Toast demo on an external device

Key features

  • Variants: success(), error(), info(), warning(), loading() and fully custom show().
  • Promise toasts: promise() shows loading, then success or error when your promise settles.
  • Live updates: update() changes a toast in place, dismiss() and dismissAll() close them.
  • Queueing: toasts queue by default, and force puts the new toast first and shows it once the current toast is dismissed.
  • Icons: symbol icons and raw SVG through icon, and image URIs through iconSource.
  • Platforms: iOS, Android and Web.

This package keeps the familiar toast.* surface from react-native-pretty-toast, but ships as a Capacitor plugin with:

  • native overlays on iOS and Android.
  • a DOM renderer on web.
  • queueing, force, update, dismiss, dismissAll, and promise
  • symbol icons, raw SVG through icon, and URI-based images through iconSource

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-pretty-toast` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

bun add @capgo/capacitor-pretty-toast

Then sync native platforms:

bunx cap sync

Usage

import { toast } from '@capgo/capacitor-pretty-toast';

toast.success('Saved', {
  message: 'Your changes are already on disk.',
});

const id = toast.loading('Uploading', {
  message: 'This toast stays visible until you update it.',
});

setTimeout(() => {
  toast.update(id, {
    title: 'Upload complete',
    message: 'Updated in place without replaying the enter animation.',
    icon: 'checkmark.circle.fill',
    autoDismiss: true,
  });
}, 1500);

API

Public toast controller exposed as toast.

show(...)

show(config: ToastConfig, options?: ShowOptions | undefined) => string

Show a custom toast and return its id.

ParamType
configToastConfig
optionsShowOptions

Returns: string


success(...)

success(title: string, config?: ToastConfig | undefined, options?: ShowOptions | undefined) => string

Show a success toast.

ParamType
titlestring
configToastConfig
optionsShowOptions

Returns: string


error(...)

error(title: string, config?: ToastConfig | undefined, options?: ShowOptions | undefined) => string

Show an error toast.

ParamType
titlestring
configToastConfig
optionsShowOptions

Returns: string


info(...)

info(title: string, config?: ToastConfig | undefined, options?: ShowOptions | undefined) => string

Show an informational toast.

ParamType
titlestring
configToastConfig
optionsShowOptions

Returns: string


warning(...)

warning(title: string, config?: ToastConfig | undefined, options?: ShowOptions | undefined) => string

Show a warning toast.

ParamType
titlestring
configToastConfig
optionsShowOptions

Returns: string


loading(...)

loading(title: string, config?: ToastConfig | undefined, options?: ShowOptions | undefined) => string

Show a loading toast. Loading toasts do not auto-dismiss by default.

ParamType
titlestring
configToastConfig
optionsShowOptions

Returns: string


update(...)

update(id: string, partial: ToastConfig) => void

Update an existing toast by id.

ParamType
idstring
partialToastConfig

promise(...)

promise<T>(promise: Promise<T>, messages: PromiseMessages<T>) => Promise<T>

Show a loading toast while a promise is pending, then update it for success or error.

ParamType
promisePromise<T>
messagesPromiseMessages<T>

Returns: Promise<T>


dismiss(...)

dismiss(id?: string | undefined) => void

Dismiss one toast by id, or the current toast when no id is provided.

ParamType
idstring

dismissAll()

dismissAll() => void

Dismiss the current toast and clear the queue.


Interfaces

ToastConfig

PropTypeDescription
idstringOptional stable toast id. A generated id is returned when omitted.
iconstringAccepts either an SF-symbol-like identifier or raw SVG markup. SVG mode is enabled only when the string starts with &lt;svg after trim.
iconSourceIconSourceURI-like image source. Supports https://, http://, file://, absolute file paths, data: URLs, blob: URLs, or { uri }. iconSource always wins over icon.
titlestringMain toast title.
messagestringSecondary toast message.
durationnumberAuto-dismiss delay in milliseconds.
autoDismissbooleanWhether the toast dismisses itself after duration.
enableSwipeDismissbooleanWhether swipe-to-dismiss is enabled on native overlays.
accentColorstringCSS-style accent color used by native/web renderers.
strokeColorstringCSS-style border/stroke color.
disableBackdropSamplingbooleanDisable Android/iOS backdrop sampling behind the toast.
actionToastActionOptional action button configuration.
accessibilityAnnouncementstringText announced to assistive technologies when the toast is shown.
onPress(() => void)Called when the toast body is pressed. Tapping the toast always dismisses it.
onShow(() => void)Called when the toast becomes visible.
onHide(() => void)Called when the toast is dismissed.
onAutoDismiss(() => void)Called when the toast is dismissed by its timer.

ToastAction

PropTypeDescription
labelstringText shown for the native/web action button.
onPress() => voidCalled when the action button is pressed.

ShowOptions

PropTypeDescription
forcebooleanDismiss the current toast and show this one immediately.

Type Aliases

IconSource

string | { uri: string }

PromiseMessages

{ loading: string | ToastConfig; success: string | ((value: T) => string | ToastConfig); error: string | ((error: unknown) => string | ToastConfig); }

Notes:

  • Raw SVG is accepted only through icon.
  • iconSource always takes precedence over icon.
  • toast.loading() defaults autoDismiss to false.

Example App

The repo includes example-app/, a Vite-based Capacitor app with demos for:

  • every toast.* method
  • queueing and force
  • live update
  • dismiss and dismissAll
  • promise
  • symbol icons
  • raw SVG icons
  • remote and data-URL iconSource values
  • repeatable capture modes with ?demo=hero, ?demo=flow, and ?demo=update

?demo=flow is the promo enter/exit morph used in the README video. The shipped video shows both the Android cutout path and the centered island-style path side by side.

Run it locally:

cd example-app
bun install
bun run start

Development

bun install
bun run build
bun test
bun run verify

版本与发布记录

@capgo/capacitor-pretty-toast 共发布 29 个版本,首次发布于 2026/05/21;过去 12 个月发布了 29 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.1.28latest2026/11/027 天前
8.1.272026/10/1525 天前
8.1.262026/10/1426 天前
8.1.252026/10/1326 天前
8.1.242026/10/1327 天前
8.1.232026/10/1228 天前

关于 @capgo/capacitor-pretty-toast 的常见问题

@capgo/capacitor-pretty-toast 是什么?

Native-first pretty toast notifications for Capacitor and the web

如何安装 @capgo/capacitor-pretty-toast?

在项目目录运行 npm install @capgo/capacitor-pretty-toast,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-pretty-toast 支持 TypeScript 吗?

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

@capgo/capacitor-pretty-toast 支持 ESM 还是 CommonJS?

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

@capgo/capacitor-pretty-toast 可以商用吗?

@capgo/capacitor-pretty-toast 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-pretty-toast 的下载量有多少?

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

@capgo/capacitor-pretty-toast 还在维护吗?

最新版本 8.1.28 发布于 2026/11/02(7 天前);至今共发布 29 个版本,其中过去 12 个月发布了 29 个;首次发布于 2026/05/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。