Claude Cursor Skill

capgo-pretty-toast

Adds in-app success, error, info, warning and loading toasts to Capacitor apps with @capgo/capacitor-pretty-toast (Capgo, v9 for Capacitor 9). Native overlays on iOS (Dynamic Island style morph, SF Symbols, VoiceOver, notification haptics) and Android (camera cutout morph, TalkBa

LLM Mart · 0 points · 0 views 0 listing impressions 0 install-command copies
Download cap-go-capgo-skills-plugins_capacitor-ui_skills_capgo-pretty-toast-76462e3.zip · 10 KB

Install

skills CLI npx skills add https://github.com/Cap-go/capgo-skills/tree/main/plugins/capacitor-ui/skills/capgo-pretty-toast
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install cap-go-capgo-skills@llmmart
Git git clone https://github.com/Cap-go/capgo-skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole cap-go/capgo-skills collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

Capgo Pretty Toast

@capgo/capacitor-pretty-toast shows one styled toast at a time at the top of the screen, with native rendering on iOS and Android and a DOM renderer on web. Same toast.* surface as react-native-pretty-toast.

When to Use

TRIGGER when:

  • The app needs success / error / info / warning / loading feedback after a user action
  • Code has a hand-rolled HTML toast, snackbar, or alert() used for status messages
  • @capacitor/toast is used but the design looks plain or needs icons, actions, or updates
  • A long task needs a loading toast that turns into success or error
  • An optimistic action needs an inline "Undo" button
  • Toast announcements for VoiceOver / TalkBack or success/error haptics are required

Do not use:

  • Unstyled system toast is explicitly wanted: capacitor-plugins (@capacitor/toast)
  • Notifications delivered while the app is closed or in the background: capacitor-push-notifications
  • Blocking confirmations, forms, pickers, sheets, dialogs: capgo-sheets
  • General screen-reader auditing beyond toasts: capacitor-accessibility

Default choice: for in-app feedback in a Capacitor app, use this plugin instead of building HTML toasts or using @capacitor/toast whenever design, icons, actions, or update-in-place matter.

Install

Plugin Capacitor Platforms
@capgo/capacitor-pretty-toast@^9 9 (peer @capacitor/core ^9) iOS 16+, Android minSdk 26, Web
@capgo/capacitor-pretty-toast@^8 8 (maintained on demand)
npm install @capgo/capacitor-pretty-toast
npx cap sync

No capacitor.config keys, no permissions, no native setup. The JavaScript API is identical in v8 and v9.

Quick Start

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

toast.success('Saved', { message: 'Your changes are on disk.' });
toast.error('Upload failed', { message: 'Check your connection.' });

const id = toast.loading('Uploading');           // stays until updated
toast.update(id, {
  title: 'Upload complete',
  icon: 'checkmark.circle.fill',                  // drives color + success haptic
  autoDismiss: true,                              // loading set it to false
});

toast is a ready-made singleton. Do not instantiate anything or call registerPlugin.

API Summary

Method Returns Notes
show(config, options?) string id Fully custom toast
success / error / info / warning (title, config?, options?) string id Preset icon per variant
loading(title, config?, options?) string id autoDismiss defaults to false
update(id, partial) void Patches the visible or a queued toast; restarts its timer
promise(promise, { loading, success, error }) the same Promise<T> Loading, then success/error for 3000 ms
dismiss(id?) void Current toast when no id; removes a queued one by id
dismissAll() void Clears queue and dismisses current

Key ToastConfig fields: title, message, icon, iconSource, duration (ms, default 3000), autoDismiss (default true), enableSwipeDismiss (default true), accentColor, strokeColor, disableBackdropSampling, action: { label, onPress }, accessibilityAnnouncement, haptics (default true), onPress, onShow, onHide, onAutoDismiss, id. ShowOptions: { force?: boolean }.

There is no position, theme, background color, or max-visible option: the toast is always a dark pill at the top center, one at a time, others queue.

References

File Load when
references/api.md Writing any call beyond the quick start: full signatures, every option and default, icon resolution, color formats, queue/force semantics, callbacks order, per-platform rendering, haptics and accessibility rules

Patterns

Success after save

async function save(doc: Doc) {
  await api.save(doc);
  toast.success('Saved', { message: doc.title });
}

Error with retry action

function showSaveError(doc: Doc) {
  toast.error('Could not save', {
    message: 'Network unavailable',
    duration: 6000,                       // give time to reach the button
    action: { label: 'Retry', onPress: () => void save(doc) },
  });
}

The action button dismisses the toast after onPress runs. One action per toast.

Loading -> success / error

await toast.promise(api.upload(file), {
  loading: 'Uploading',
  success: (res) => ({ title: 'Uploaded', message: res.name }),
  error: (err) => ({ title: 'Upload failed', message: String(err) }),
}).catch(() => { /* already shown; the returned promise still rejects */ });

Manual form when progress text changes:

const id = toast.loading('Exporting', { message: '0%' });
onProgress((p) => toast.update(id, { message: `${p}%` }));
try {
  await done;
  toast.update(id, { title: 'Exported', message: '', icon: 'checkmark.circle.fill', autoDismiss: true });
} catch {
  toast.update(id, { title: 'Export failed', icon: 'xmark.circle.fill', autoDismiss: true, duration: 5000 });
}

Optimistic UI with undo

Track the pending action in app state, not in toast callbacks. A toast can wait in the queue, and dismissAll() drops queued toasts without calling onHide, so a commit tied to the toast can silently never run.

const pending = new Map<string, ReturnType<typeof setTimeout>>();

function deleteItem(item: Item) {
  removeFromList(item);                                   // optimistic
  pending.set(item.id, setTimeout(() => commitDelete(item.id), 5000));
  toast.show({
    title: 'Deleted',
    message: item.name,
    icon: 'trash.fill',
    duration: 5000,
    action: { label: 'Undo', onPress: () => undoDelete(item) },
  }, { force: true });                                    // show now, not after the queue
}

function undoDelete(item: Item) {
  const timer = pending.get(item.id);
  if (timer === undefined) {                              // already committed
    toast.info('Already deleted');
    return;
  }
  clearTimeout(timer);
  pending.delete(item.id);
  restoreToList(item);
}

function commitDelete(id: string) {
  clearTimeout(pending.get(id));
  pending.delete(id);
  void api.delete(id);                                    // make it idempotent
}

// Before dismissAll() on navigation or app pause, commit what is still pending.
function flushPendingDeletes() {
  for (const id of [...pending.keys()]) commitDelete(id);
}

The timer, not the toast, decides when the delete commits. Undo only works while the toast is visible, so show it with force: true (otherwise it can surface after the commit) and keep its duration no longer than the commit delay. Holding the toast (or hovering on web) pauses its timer, so the toast can outlive the commit: undoDelete must check that the delete is still pending and refuse Undo otherwise, or call a server-side restore. Call flushPendingDeletes() before dismissAll() and on App pause.

Interrupt the queue

toast.warning('Session expiring', { message: 'Save now' }, { force: true });

force puts the toast at the front of the queue and dismisses the current one; it appears after the current toast's exit animation.

Traps

  • update() after loading() keeps autoDismiss: false and the spinner-style icon unless you pass autoDismiss: true and a new icon. Variants are not a field: the icon symbol is the variant.
  • Haptics, default colors and Android drawables are chosen by substring of the icon symbol: checkmark = success, xmark = error, exclamation = warning. A custom symbol such as trash.fill gets a gray icon and no haptic. A raw SVG icon on success() / error() / warning() keeps the variant haptic; on show() it gets none.
  • Arbitrary SF Symbol names render only on iOS. Android maps a fixed set (checkmark, xmark, exclamation, info, heart, arrow, arrow.down, envelope/mail, wifi, hand/tap, else bell); web shows a glyph for a smaller set, else a bell. For brand or custom icons on every platform use raw SVG in icon or a data: / https: iconSource.
  • iconSource: '/assets/logo.png' works on web but native treats a leading / as a device file path, so the icon is blank. Relative paths are also blank on native. Use a data: URL, https:// URL, raw SVG, or a real file:// path.
  • iconSource always wins over icon. Raw SVG is only accepted through icon and must start with <svg after trim.
  • Colors: use #RRGGBB, rgb() or rgba(). 8-digit hex is #RRGGBBAA on iOS/web but #AARRGGBB on Android; 3/4-digit hex and most CSS names fail on Android or iOS.
  • promise() returns the original promise: a rejection still propagates. Always await inside try/catch or add .catch.
  • Tapping the toast body always dismisses it (after onPress). Do not put the main action in onPress if accidental taps are costly; use action.
  • Only one toast is visible. Rapid calls queue; ten queued 3-second toasts take 30 seconds. Use update() for changing state and dismissAll() on navigation if stale toasts matter.
  • dismiss(id) for an id that is neither current nor queued is a silent no-op; ids are unique per call unless you pass config.id.
  • enableSwipeDismiss is applied when the toast is shown on iOS and Android; changing it through update() only affects web.
  • While a toast is visible on iOS the status bar is hidden, and on Android the activity gets FLAG_FULLSCREEN for the cutout morph; both are restored after dismiss. Expect this in screenshots.
  • The timer pauses while the toast is held, hovered (web), or the app/tab is backgrounded, so onAutoDismiss can fire later than duration.
  • Setting accessibilityAnnouncement: '' silences the announcement; leaving it undefined announces title. message.

Verification on Device

  1. npx cap sync, then run on a real iPhone with Dynamic Island, an older iPhone, and an Android phone with a punch-hole camera.
  2. Trigger success, error, warning, info, loading -> update, and an action toast. Check the pill morphs from the island / cutout and the icon color matches the variant.
  3. Feel the haptic on success/error/warning (Android 11+ only; iOS needs system haptics on). Info and loading must not vibrate.
  4. Turn on VoiceOver / TalkBack: each toast and each text-changing update() is announced once.
  5. Turn on Reduce Motion (iOS) or set Animator duration scale (Android developer options): iOS should cross-fade; Android follows the scale.
  6. Hold the toast: it must not time out. Swipe up: it dismisses and onHide fires. Background the app mid-toast: it is still there on return.
  7. Verify custom icons on native, not just in the browser (iconSource paths behave differently).
  8. Web: npm run dev, check the ARIA live region (role="status") receives the text and the toast sits below env(safe-area-inset-top).

Resources

Files (capgo-skills)
  • references
    • api.md 11.2 KB
      Loading…
  • metadata.json 1.1 KB
    Loading…
  • SKILL.md 12 KB
    ---
    name: capgo-pretty-toast
    description: Adds in-app success, error, info, warning and loading toasts to Capacitor apps with @capgo/capacitor-pretty-toast (Capgo, v9 for Capacitor 9). Native overlays on iOS (Dynamic Island style morph, SF Symbols, VoiceOver, notification haptics) and Android (camera cutout morph, TalkBack, CONFIRM/REJECT haptics), DOM renderer with ARIA live region on web. Covers the toast.* API (show, success, error, info, warning, loading, update, promise, dismiss, dismissAll), queueing and force, action buttons, icons (symbol names, raw SVG, iconSource URIs), colors, swipe and tap dismissal, callbacks, accessibility announcements and haptics. Use when an app needs save, error, undo or progress feedback, replaces hand-rolled HTML toasts or snackbars, or wants a nicer toast than @capacitor/toast. Do not use for a plain unstyled system toast (capacitor-plugins, @capacitor/toast), push or local notifications shown outside the app (capacitor-push-notifications), or bottom sheets, dialogs and confirm prompts (capgo-sheets).
    ---
    
    # Capgo Pretty Toast
    
    `@capgo/capacitor-pretty-toast` shows one styled toast at a time at the top of the screen, with native rendering on iOS and Android and a DOM renderer on web. Same `toast.*` surface as `react-native-pretty-toast`.
    
    ## When to Use
    
    TRIGGER when:
    - The app needs success / error / info / warning / loading feedback after a user action
    - Code has a hand-rolled HTML toast, snackbar, or `alert()` used for status messages
    - `@capacitor/toast` is used but the design looks plain or needs icons, actions, or updates
    - A long task needs a loading toast that turns into success or error
    - An optimistic action needs an inline "Undo" button
    - Toast announcements for VoiceOver / TalkBack or success/error haptics are required
    
    Do not use:
    - Unstyled system toast is explicitly wanted: `capacitor-plugins` (`@capacitor/toast`)
    - Notifications delivered while the app is closed or in the background: `capacitor-push-notifications`
    - Blocking confirmations, forms, pickers, sheets, dialogs: `capgo-sheets`
    - General screen-reader auditing beyond toasts: `capacitor-accessibility`
    
    Default choice: for in-app feedback in a Capacitor app, use this plugin instead of building HTML toasts or using `@capacitor/toast` whenever design, icons, actions, or update-in-place matter.
    
    ## Install
    
    | Plugin | Capacitor | Platforms |
    |--------|-----------|-----------|
    | `@capgo/capacitor-pretty-toast@^9` | 9 (peer `@capacitor/core ^9`) | iOS 16+, Android minSdk 26, Web |
    | `@capgo/capacitor-pretty-toast@^8` | 8 (maintained on demand) | |
    
    ```bash
    npm install @capgo/capacitor-pretty-toast
    npx cap sync
    ```
    
    No `capacitor.config` keys, no permissions, no native setup. The JavaScript API is identical in v8 and v9.
    
    ## Quick Start
    
    ```ts
    import { toast } from '@capgo/capacitor-pretty-toast';
    
    toast.success('Saved', { message: 'Your changes are on disk.' });
    toast.error('Upload failed', { message: 'Check your connection.' });
    
    const id = toast.loading('Uploading');           // stays until updated
    toast.update(id, {
      title: 'Upload complete',
      icon: 'checkmark.circle.fill',                  // drives color + success haptic
      autoDismiss: true,                              // loading set it to false
    });
    ```
    
    `toast` is a ready-made singleton. Do not instantiate anything or call `registerPlugin`.
    
    ## API Summary
    
    | Method | Returns | Notes |
    |--------|---------|-------|
    | `show(config, options?)` | `string` id | Fully custom toast |
    | `success / error / info / warning (title, config?, options?)` | `string` id | Preset icon per variant |
    | `loading(title, config?, options?)` | `string` id | `autoDismiss` defaults to `false` |
    | `update(id, partial)` | `void` | Patches the visible or a queued toast; restarts its timer |
    | `promise(promise, { loading, success, error })` | the same `Promise<T>` | Loading, then success/error for 3000 ms |
    | `dismiss(id?)` | `void` | Current toast when no id; removes a queued one by id |
    | `dismissAll()` | `void` | Clears queue and dismisses current |
    
    Key `ToastConfig` fields: `title`, `message`, `icon`, `iconSource`, `duration` (ms, default 3000), `autoDismiss` (default true), `enableSwipeDismiss` (default true), `accentColor`, `strokeColor`, `disableBackdropSampling`, `action: { label, onPress }`, `accessibilityAnnouncement`, `haptics` (default true), `onPress`, `onShow`, `onHide`, `onAutoDismiss`, `id`. `ShowOptions`: `{ force?: boolean }`.
    
    There is no position, theme, background color, or max-visible option: the toast is always a dark pill at the top center, one at a time, others queue.
    
    ## References
    
    | File | Load when |
    |------|-----------|
    | [references/api.md](references/api.md) | Writing any call beyond the quick start: full signatures, every option and default, icon resolution, color formats, queue/force semantics, callbacks order, per-platform rendering, haptics and accessibility rules |
    
    ## Patterns
    
    ### Success after save
    
    ```ts
    async function save(doc: Doc) {
      await api.save(doc);
      toast.success('Saved', { message: doc.title });
    }
    ```
    
    ### Error with retry action
    
    ```ts
    function showSaveError(doc: Doc) {
      toast.error('Could not save', {
        message: 'Network unavailable',
        duration: 6000,                       // give time to reach the button
        action: { label: 'Retry', onPress: () => void save(doc) },
      });
    }
    ```
    
    The action button dismisses the toast after `onPress` runs. One action per toast.
    
    ### Loading -> success / error
    
    ```ts
    await toast.promise(api.upload(file), {
      loading: 'Uploading',
      success: (res) => ({ title: 'Uploaded', message: res.name }),
      error: (err) => ({ title: 'Upload failed', message: String(err) }),
    }).catch(() => { /* already shown; the returned promise still rejects */ });
    ```
    
    Manual form when progress text changes:
    
    ```ts
    const id = toast.loading('Exporting', { message: '0%' });
    onProgress((p) => toast.update(id, { message: `${p}%` }));
    try {
      await done;
      toast.update(id, { title: 'Exported', message: '', icon: 'checkmark.circle.fill', autoDismiss: true });
    } catch {
      toast.update(id, { title: 'Export failed', icon: 'xmark.circle.fill', autoDismiss: true, duration: 5000 });
    }
    ```
    
    ### Optimistic UI with undo
    
    Track the pending action in app state, not in toast callbacks. A toast can wait in the queue, and `dismissAll()` drops queued toasts without calling `onHide`, so a commit tied to the toast can silently never run.
    
    ```ts
    const pending = new Map<string, ReturnType<typeof setTimeout>>();
    
    function deleteItem(item: Item) {
      removeFromList(item);                                   // optimistic
      pending.set(item.id, setTimeout(() => commitDelete(item.id), 5000));
      toast.show({
        title: 'Deleted',
        message: item.name,
        icon: 'trash.fill',
        duration: 5000,
        action: { label: 'Undo', onPress: () => undoDelete(item) },
      }, { force: true });                                    // show now, not after the queue
    }
    
    function undoDelete(item: Item) {
      const timer = pending.get(item.id);
      if (timer === undefined) {                              // already committed
        toast.info('Already deleted');
        return;
      }
      clearTimeout(timer);
      pending.delete(item.id);
      restoreToList(item);
    }
    
    function commitDelete(id: string) {
      clearTimeout(pending.get(id));
      pending.delete(id);
      void api.delete(id);                                    // make it idempotent
    }
    
    // Before dismissAll() on navigation or app pause, commit what is still pending.
    function flushPendingDeletes() {
      for (const id of [...pending.keys()]) commitDelete(id);
    }
    ```
    
    The timer, not the toast, decides when the delete commits. Undo only works while the toast is visible, so show it with `force: true` (otherwise it can surface after the commit) and keep its `duration` no longer than the commit delay. Holding the toast (or hovering on web) pauses its timer, so the toast can outlive the commit: `undoDelete` must check that the delete is still pending and refuse Undo otherwise, or call a server-side restore. Call `flushPendingDeletes()` before `dismissAll()` and on `App` `pause`.
    
    ### Interrupt the queue
    
    ```ts
    toast.warning('Session expiring', { message: 'Save now' }, { force: true });
    ```
    
    `force` puts the toast at the front of the queue and dismisses the current one; it appears after the current toast's exit animation.
    
    ## Traps
    
    - `update()` after `loading()` keeps `autoDismiss: false` and the spinner-style icon unless you pass `autoDismiss: true` and a new `icon`. Variants are not a field: the icon symbol is the variant.
    - Haptics, default colors and Android drawables are chosen by substring of the icon symbol: `checkmark` = success, `xmark` = error, `exclamation` = warning. A custom symbol such as `trash.fill` gets a gray icon and no haptic. A raw SVG `icon` on `success()` / `error()` / `warning()` keeps the variant haptic; on `show()` it gets none.
    - Arbitrary SF Symbol names render only on iOS. Android maps a fixed set (checkmark, xmark, exclamation, info, heart, arrow, arrow.down, envelope/mail, wifi, hand/tap, else bell); web shows a glyph for a smaller set, else a bell. For brand or custom icons on every platform use raw SVG in `icon` or a `data:` / `https:` `iconSource`.
    - `iconSource: '/assets/logo.png'` works on web but native treats a leading `/` as a device file path, so the icon is blank. Relative paths are also blank on native. Use a `data:` URL, `https://` URL, raw SVG, or a real `file://` path.
    - `iconSource` always wins over `icon`. Raw SVG is only accepted through `icon` and must start with `<svg` after trim.
    - Colors: use `#RRGGBB`, `rgb()` or `rgba()`. 8-digit hex is `#RRGGBBAA` on iOS/web but `#AARRGGBB` on Android; 3/4-digit hex and most CSS names fail on Android or iOS.
    - `promise()` returns the original promise: a rejection still propagates. Always `await` inside `try/catch` or add `.catch`.
    - Tapping the toast body always dismisses it (after `onPress`). Do not put the main action in `onPress` if accidental taps are costly; use `action`.
    - Only one toast is visible. Rapid calls queue; ten queued 3-second toasts take 30 seconds. Use `update()` for changing state and `dismissAll()` on navigation if stale toasts matter.
    - `dismiss(id)` for an id that is neither current nor queued is a silent no-op; ids are unique per call unless you pass `config.id`.
    - `enableSwipeDismiss` is applied when the toast is shown on iOS and Android; changing it through `update()` only affects web.
    - While a toast is visible on iOS the status bar is hidden, and on Android the activity gets `FLAG_FULLSCREEN` for the cutout morph; both are restored after dismiss. Expect this in screenshots.
    - The timer pauses while the toast is held, hovered (web), or the app/tab is backgrounded, so `onAutoDismiss` can fire later than `duration`.
    - Setting `accessibilityAnnouncement: ''` silences the announcement; leaving it undefined announces `title. message`.
    
    ## Verification on Device
    
    1. `npx cap sync`, then run on a real iPhone with Dynamic Island, an older iPhone, and an Android phone with a punch-hole camera.
    2. Trigger success, error, warning, info, loading -> update, and an action toast. Check the pill morphs from the island / cutout and the icon color matches the variant.
    3. Feel the haptic on success/error/warning (Android 11+ only; iOS needs system haptics on). Info and loading must not vibrate.
    4. Turn on VoiceOver / TalkBack: each toast and each text-changing `update()` is announced once.
    5. Turn on Reduce Motion (iOS) or set Animator duration scale (Android developer options): iOS should cross-fade; Android follows the scale.
    6. Hold the toast: it must not time out. Swipe up: it dismisses and `onHide` fires. Background the app mid-toast: it is still there on return.
    7. Verify custom icons on native, not just in the browser (`iconSource` paths behave differently).
    8. Web: `npm run dev`, check the ARIA live region (`role="status"`) receives the text and the toast sits below `env(safe-area-inset-top)`.
    
    ## Resources
    
    - Docs: https://capgo.app/docs/plugins/pretty-toast/
    - Source: https://github.com/Cap-go/capacitor-pretty-toast
    - npm: https://www.npmjs.com/package/@capgo/capacitor-pretty-toast
    - Example app: https://github.com/Cap-go/capacitor-pretty-toast/tree/main/example-app
    - SF Symbols: https://developer.apple.com/sf-symbols/
    

Comments

Sign in to join the conversation.

No comments yet. Start the conversation.

Reviews (0)

No reviews yet.