Resend button
A resend action with an absolute cooldown, rolling time and capped backoff.
npx @swipeui/cli add resend-buttonWhen to use it
- Offer another verification code after a cooldown.
- Keep availability accurate after leaving a screen by controlling availableAt.
When not to use it
- Enforce server rate limits or verify a code; the caller owns both.
- Run an ordinary action without a cooldown; use Button.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add resend-button- Adds
components/swipeui/ui/resend-button.tsx,components/swipeui/ui/use-resend-button.tsand 13 shared helpers. - Installs react-native-reanimated, uniwind, react-native-worklets, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { ResendButton } from '@/components/swipeui/ui/resend-button';
<ResendButton cooldown={30} backoff={2} maxCooldown={120} onResend={sendCode} />;Examples
otp, backoff. The app and public preview use the same content and variant names. Demo settings sit outside the component and outcome feedback stays on the action.
Settings
| Setting | Default | Behavior |
|---|---|---|
format | minutes:seconds | Custom countdown text; seconds are rounded up. |
labels | English labels | Independently override available, countdown prefix, pending, success and error text. |
countMotion | true | Roll countdown digits independently of label/arrival motion. |
availableAt | undefined | Controlled availability timestamp, milliseconds since epoch. |
onAvailableAtChange | undefined | Receives a fresh availability timestamp after accepted resends. |
cooldown | 30 | Initial cooldown, in seconds. Zero starts available. |
backoff | 1 | Cooldown multiplier after each successful resend. |
maxCooldown | 300 | Maximum cooldown, seconds. |
onResend | undefined | Work to send the code; may return a promise. |
onError | undefined | Reports a failed request. |
minPending | 450 | Minimum pending visibility, milliseconds. |
resetAfter | 1000 | Success label visibility before countdown, milliseconds. |
disabled | false | Prevents activation independently of the cooldown. |
haptics | true | Global feedback or independent press/success/error feedback. |
variant | plain | Shared Button surface; legacy aliases remain supported. |
tone | 'primary' for solid, tinted and plain; 'neutral' for outline and ghost | The colour family: primary, neutral, destructive or success. |
size | 'md' | The height: sm 36pt (with a 44pt touch target), md 44pt, lg 52pt. |
shape | 'preset' | preset follows your preset's control radius; pill is a capsule. |
block | false | Stretches the button to the full width of its container. |
leadingIcon | absent | Content before the label: a node, or a function that receives { color, size }. |
trailingIcon | absent | Content after the label: a node, or a function that receives { color, size }. |
trailingIconNudge | false | Slides the trailing icon a little forward while pressed, mirrored in right-to-left layouts. |
loadingLabel | absent | Label shown while loading; defaults to the children. |
loadingPlacement | 'start' | Where the spinner goes: start replaces the leading icon; center hides the label and holds the width. |
labelMorph | 'fade' | How a changed text label arrives: fade (the new label rises in as the old one fades), characters (only the changed letters roll in) or none. The width springs to fit either way. |
highlight | true | A faint rim of light along the top edge of solid buttons. |
glow | false | A soft shadow in the tone's colour under solid buttons. |
pressEffect | 'both' | Feedback while pressed: both scales and washes the surface, scale, wash or none. Text-only buttons dim their label instead of washing. |
disabledStyle | 'muted' | How a disabled button looks: muted mutes its fill and label; dim halves its opacity. |
palette | BUTTON_PALETTE | Colours that belong to the button's material rather than the theme (the top highlight). |
motion | the app's feel (smooth without a provider) | The app's motion feel, or a local override for the press, label and width springs. |
className | absent | Classes merged over the style. |
textClassName | absent | Classes for the label text. |
style | absent | Style escape hatch for the container. |
accessibilityLabel | current label | Optional spoken-name override. |
testID | undefined | Root identifier; parts append suffixes. |
haptics.press | true | Impact for an accepted resend. |
haptics.success | true | Success notification after sending the code. |
haptics.error | true | Error notification after a failed resend. |
Composition and behavior
Control availableAt and retain the timestamp outside the screen to survive unmounts. cooldown is in seconds; minPending and resetAfter are in milliseconds. A supplied onResend promise controls pending and outcome feedback.
Only available actions invoke onResend; duplicate requests stay locked through minimum pending visibility.
Success shows Code sent, requests a fresh deadline and multiplies the next cooldown by backoff up to maxCooldown. Failure keeps retry available.
The clock recomputes from Date.now and availableAt on every tick and foreground event, rather than decrementing local seconds.
API reference
Review gates
Founder app and existing pnpm-dev visual acceptance remains open. Native runtime, VoiceOver/TalkBack, haptics, motion, Dynamic Type, RTL and recordings remain pending founder-scheduled 7.9. Source, bundle and unit checks do not establish visual or native acceptance.
The two specimen boards are OTP and Backoff; both include the external failure switch. Backoff multiplies each successful resend cooldown by backoff, capped by maxCooldown: with 30 seconds and factor 2, the waits become 30 → 60 → 120 seconds. Demo clocks are shorter for review. Failed sends do not increase the cooldown.
Behavior and gestures
- Only available actions invoke onResend; duplicate requests stay locked through minimum pending visibility.
- Success shows Code sent, requests a fresh deadline and multiplies the next cooldown by backoff up to maxCooldown. Failure keeps retry available.
- The clock recomputes from Date.now and availableAt on every tick and foreground event, rather than decrementing local seconds.
Accessibility
- Named controls expose unavailable, busy and selected/progress state where applicable. Decorative layers are excluded from interaction.
- Meaningful outcome/availability announcements are distinct from clocks and decorative effects. Native VoiceOver/TalkBack, Dynamic Type, RTL and touch evidence remain pending for 7.9.
Motion
- Uses the
press,morph,numberandambientmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Every decorative duration/spring comes from the shared role helpers. Content clocks remain independent of motion feel.
- Reduce Motion retains readable outcome/progress feedback. Native motion/performance review remains pending.
Performance
- No new package, network service, telemetry or proprietary source.
- Async results and content timers clean up or invalidate after unmount; UI animation values stay on the UI thread.
Notes for AI
- Control availableAt and retain the timestamp outside the screen to survive unmounts. cooldown is in seconds; minPending and resetAfter are in milliseconds. A supplied onResend promise controls pending and outcome feedback.
- Founder app/web acceptance and all native runtime, accessibility, haptics, motion and recordings remain pending for 7.9.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.