Command palette

@yasinsensoy/native

React Native · Components

Countdown

Countdown or count-up (same API as web): sale end, "resend in 60 s", call duration.

12 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Code

import { Countdown } from "@yasinsensoy/native";

<Countdown to="2026-12-31T23:59:59+03:00" variant="boxes" urgent={60000} onComplete={() => done()} />

Events

  1. Events appear here when you interact with the preview.

Campaign card

Until the November sale ends

Resend code (a component instead of useCountdown)

until you can resend

Import

import { Countdown, unitLabel, formatCountdown, useCountdown } from "@yasinsensoy/native";

Countdown

component

Countdown or count-up (same API as web): sale end, "resend in 60 s", call duration. Variants clock, text, boxes; unit names in the device language (Intl; where Hermes lacks it, a fallback table giving the same text).

  • Re-renders only when the smallest visible unit changes; pauses in the background and resumes from the real clock when brought to the front.
  • urgent turns it red with a pulse in the final moments. Digits have equal widths (tabular-nums); text does not shift when numbers change.
  • Screen reader: "timer" role, announced once when it finishes.
Countdown({ variant: variantProp, effect, size, tone, urgent, labels, completed, placeholder: _placeholder, label, tooltip, style, styles, testID, ...options }: CountdownProps): ReactNode

Examples

<Countdown to="2026-12-31T23:59:59+03:00" variant="boxes" />
<Countdown duration={60_000} units={["minutes", "seconds"]} onComplete={enableResend} />
<Countdown from={startedAt} variant="text" labels="short" />

unitLabel

function

Only the unit name, by language and number ("gün", "days", "day"). Uses Intl; no translation needed.

unitLabel(value: number, unit: CountdownUnit, locale: string, display?: "long" | "short" | "narrow"): string

Turns a duration into readable text: "2 days 3 hours 4 minutes". Zero units are skipped (the smallest unit is written when all are zero).

formatCountdown(parts: CountdownParts, units: readonly CountdownUnit[], locale: string, display?: "long" | "short" | "narrow"): string

useCountdown

function

Countdown or count-up hook (same API as web): for drawing your own UI.

  • Efficient: wakes up not every second but when the smallest visible unit changes (once a minute if only minutes are shown).
  • Background: the timer stops when the app goes to the background and is recomputed from the real clock when it comes to the front; no drift.
useCountdown(options: UseCountdownOptions): UseCountdownResult

Examples

const { minutes, seconds, done, reset } = useCountdown({ duration: 60_000 });
return done
  ? <Button onPress={() => { resend(); reset(); }}>Resend</Button>
  : <Text>{minutes}:{String(seconds).padStart(2, "0")}</Text>;

Countdown variant (same as web).

  • clock: digital clock: 2 days 03:04:05, 12:30.
  • text: readable text: "2 days 3 hours 4 minutes".
  • boxes: each unit in its own box with its name below (campaigns, events).
type CountdownVariant = "clock" | "text" | "boxes"

Styles of the inner parts of Countdown (the counterpart of classNames on web).

NameTypeDescription
unit?StyleProp<ViewStyle>Unit box (boxes) or unit group.
value?StyleProp<TextStyle>Number.
label?StyleProp<TextStyle>Unit name.
separator?StyleProp<TextStyle>Separator (:).

Props of the Countdown component.

NameTypeDefaultDescription
variant?CountdownVariant | (string & {})"clock"Variant: a built-in one or a name added with appearance.variants.countdown. Defaults to UIProvider appearance.defaults.countdown.variant.
effect?EffectPropEffect or effects (e.g. "shine"). In the boxes variant applied to each unit box, otherwise to the counter itself.
size?"sm" | "md" | "lg""md"Size.
tone?Tone"neutral"Color of the boxes in the boxes variant.
urgent?numberLooks "urgent" once the remaining time drops below this (ms): red with a light pulse (no pulse with reduced motion). Works when counting down.
labels?"long" | "short" | "narrow" | false"long"Unit names: full ("long"), short ("short") or shortest.
completed?ReactNodeContent shown when finished (e.g. "The sale has started!"). If omitted zeros are shown.
placeholder?ReactNodeFor an API shared with web; on native the numbers are ready on the first render.
label?stringScreen reader name (e.g. "Time left until the sale ends"). The counter is not announced every second; it is announced once when it finishes.
tooltip?TooltipPropTooltip on long press. See TooltipProp.
style?StyleProp<ViewStyle>Container style.
styles?CountdownStylesStyles of the inner parts.
testID?stringTest id.
to?CountdownDateTarget moment: counts down to this moment.
duration?numberDuration (ms): counts down to this long after the first render (e.g. "resend in 60 s").
from?CountdownDateStart moment: counts up the time elapsed since this moment (e.g. call duration).
units?readonly CountdownUnit[] | "auto""auto"Units shown, from largest to smallest. "auto": based on the remaining time (days if there are days, otherwise hours…).
precise?booleanfalseMillisecond precision (updates every frame).
paused?booleanPaused.
onComplete?() => voidCalled once when the countdown finishes.
onTick?(parts: CountdownParts) => voidCalled whenever the visible value changes.

Date: Date, an ISO string ("2026-12-31T23:59:59+03:00") or milliseconds.

type CountdownDate = Date | string | number

Units that can be shown, largest to smallest.

type CountdownUnit = "days" | "hours" | "minutes" | "seconds"

The remaining (or elapsed) time split into units.

NameTypeDescription
totalnumberTotal time (ms); 0 when a countdown ends.
daysnumberDays. Added to hours when days are not shown.
hoursnumberHours.
minutesnumberMinutes.
secondsnumberSeconds.
millisecondsnumberMilliseconds (0–999).

Options of useCountdown (same as web).

NameTypeDefaultDescription
to?CountdownDateTarget moment: counts down to this moment.
duration?numberDuration (ms): counts down to this long after the first render (e.g. "resend in 60 s").
from?CountdownDateStart moment: counts up the time elapsed since this moment (e.g. call duration).
units?readonly CountdownUnit[] | "auto""auto"Units shown, from largest to smallest. "auto": based on the remaining time (days if there are days, otherwise hours…).
precise?booleanfalseMillisecond precision (updates every frame).
paused?booleanPaused.
onComplete?() => voidCalled once when the countdown finishes.
onTick?(parts: CountdownParts) => voidCalled whenever the visible value changes.

Result of useCountdown.

Extends: CountdownParts

NameTypeDescription
donebooleanWhether the countdown has finished.
runningbooleanWhether it is counting (not paused and not finished).
readybooleanWhether the value is ready (always true on native; same field as web).
unitsreadonly CountdownUnit[]Units shown.
direction"down" | "up"Direction: down with to/duration, up with from.
pause() => voidPauses.
resume() => voidResumes.
reset(duration?: number) => voidStarts over; in duration mode a new duration can be given.