Local notifications

From zakariaf/ReactNative-Skills · View interactive version

Local notifications is an AI agent skill from the GitHub repository zakariaf/ReactNative-Skills. Schedules on-device reminders with expo-notifications: rows as truth, one idempotent sync, DST-safe triggers, Android channels. Use when adding a reminder, snooze or local notification. Not for remote push (push-notifications).

How to use this skill

Skill file

Local notifications

Every on-device reminder in an Expo app is a database row; one idempotent sync turns the rows into

the OS's pending notifications (one-shot triggers at instants resolved per day through the local

zone, at most 50 nearest, on Android channels, with localized text), refills them on every return

to the foreground, and opens the row's current screen when one is tapped, on iOS and Android alike;

two checkers prove it on the app's own code.

Rules that must hold

  1. The database is the source of truth; the OS pending set is a cache. Reminders are rows

(Reminder, src/core/reminders/reminder.ts); nothing reads getAllScheduledNotificationsAsync

to decide what the person asked for. Why: iOS keeps only 64, OEM battery managers drop alarms, a

restore or reinstall empties the set; only rows survive all of it. (schedule-api, cancel-all)

  1. One idempotent sync is the only writer. createReminderSync (reminder-sync.ts): channels,

permission, rows, planReminders, reconcileReminders, cancel, schedule; runs never overlap

(single flight). Features write the row, then call sync.request(). Why: a second writer makes

the diff wrong for both and cannot be made idempotent. (sync-only-writer, reconcile-diff)

  1. expo-notifications lives only in adapters. The local adapter

(expo-local-notifications-adapter.ts) is the only file that schedules, lists or cancels; tests

drive it through jest.mock + jest.requireMock, never a value import (type-only imports are

erased and allowed). Why: Jest never touches native code, and one file owns every platform

difference. (sdk-import, schedule-api)

  1. A recurring time is a wall-clock minute plus a rule, resolved per day through the zone.

instantOfWallClock(day, minuteOfDay, zone.offsetAt); days by addDays on date keys; no

Date.now(), new Date( or + 86_400_000 in reminder code (time comes from ClockPort and

LocalZonePort). Why: a local day lasts 23, 24 or 25 hours; 09:00 stored as an instant is 08:00

all winter. (wall-clock, wall-clock-dst, plan-dst)

  1. Every notification is a one-shot DATE trigger on an explicit channel. No DAILY, WEEKLY,

CALENDAR, TIME_INTERVAL or repeats: true; channelId on every trigger. Why: a repeating trigger

cannot skip a done day, keeps one text for ever, and hides its next instant from the diff; without

a channel Android posts to an unnamed fallback channel. (repeating-trigger, trigger-channel)

  1. Identifiers encode reminder, instant and text, and the sync touches only its own.

reminder:<id>:<instant>:<hash of channel, title, body>; only REMINDER_ID_PREFIX identifiers are

cancelled; never cancelAllScheduledNotificationsAsync. Why: the same input must be an empty diff,

an edit must replace (iOS reports a pending date only as an interval), and other features'

notifications are not this sync's. (plan-idempotent, plan-edit, reconcile-diff, cancel-all)

  1. Plan the nearest 50 (never above 64), nothing in the past, and refill on every foreground.

maxPending default 50, IOS_PENDING_LIMIT 64, a 5-second lead (a pending occurrence inside it is

kept: imminentIds); useReminderSync runs on mount, on return to the foreground and on a

language change. Why: iOS silently drops everything past the 64 soonest, rejects a past date

(Android drops it silently), a sync in a reminder's last seconds must not cancel it, and a window

runs out unless refilled. (plan-max-pending, plan-past, reconcile-diff, sync-on-foreground)

  1. A bad row is rejected and recorded, never fatal; skip days and weekdays are honoured. Why: one

corrupt row must not silence every reminder, and "done for today" must hold. (plan-reject,

plan-skip)

  1. Notification text comes from t() at sync time, the t() the app shows. reminderTexts(t)

builds the channels and texts of a run from one t(), which useReminderSync(sync, t) hands over

(sync.request({ t })); the person's label goes in a *Text placeholder (bidi-isolated). Why: a

literal, or a template with words around its ${}, is never translated; the text hash in each

identifier re-plans every pending notification after a language switch; and a language read from

module state in a child's effect is still the old one. (literal-text)

  1. The permission is asked from a person's action, channels first. sync.enable() from "Remind

me": channels, then the prompt only while the OS still shows one, then a sync; blocked offers

the system Settings. Never in a layout, the root navigator, the entry or any effect (an effect

runs on mount). Why: iOS asks once, an app targeting Android 12L or lower gets no prompt before a

channel exists, and a launch prompt is refused more often. (permission-at-launch)

  1. Exactly one foreground handler. One setNotificationHandler call: the local adapter's, or

push-notifications' adapter's when push is adopted (the composition root then passes

installForegroundHandler: false to the local adapter). Why: on SDK 57 a notification that fires

while the app is open is not shown without it, and a second call silently replaces the first.

(foreground-handler)

  1. A tap carries only { kind: 'reminder', reminderId } and opens a typed route.

parseReminderTap treats data as untrusted; useReminderTaps reads the launch tap

(getLastNotificationResponse) and the listener, handles each identifier once, clears it, and the

app's openReminder reads the row's subject again and maps it to a typed href (missing → home);

no row stores a path. Why: a notification outlives routes and rows, a cold-start tap reaches no

listener, and a stored path needs an as Href cast. (plan-data, tap-parse, tap-handling)

  1. Android: inexact alarms by default, never USE_EXACT_ALARM. SCHEDULE_EXACT_ALARM only as a

deliberate opt-in with its denial handled. Why: Play allows USE_EXACT_ALARM only for alarm-clock,

timer and calendar apps; Android 14 denies the exact-alarm grant by default. (exact-alarm)

Workflow

  1. Read the reference for the task:

| Task | Read |

|---|---|

| a new reminder kind, the sync, the window, DST or travel, restore, "fired at the wrong time" | references/scheduling-model.md |

| an expo-notifications call, trigger, handler, permission or channel detail | references/expo-notifications-api.md |

| iOS vs Android delivery, the 64 limit, exact alarms, Doze, OEMs, lock-screen privacy | references/platform-behaviour.md |

| tapping a reminder, cold start, coexisting with push, action buttons | references/taps-and-routing.md |

| tests, rule zones, device probes | references/testing-and-devices.md |

| a checker failure, configuration, NOT APPLICABLE | references/checkers.md |

  1. Check the prerequisites. ClockPort with its fake and the composition root

(architecture-and-boundaries), Result (error-handling-typed-results), date-key.ts

(seeded-determinism-and-golden-vectors; a synced copy is in templates/src/core/dates/, copy it

only when the app lacks it), useIsAppActive (react-components-and-hooks), t() and the

catalogs (i18n-strings-and-catalogs). Install the SDK with npx expo install expo-notifications

and add its config plugin with an Android icon and color (expo-prebuild-and-config-plugins).

  1. Classify the SDK. Add "expo-notifications": "LocalNotificationsPort" to vendorSdks in

contracts/architecture.json and vendor('expo-notifications', 'LocalNotificationsPort') to the

ESLint VENDOR_SDK_PATHS (architecture-and-boundaries, typescript-and-lint-rules). When

push-notifications is adopted too, both adapters import the SDK, so the label names both ports:

"LocalNotificationsPort/PushPort" in both places.

  1. Store the rows. Add the reminder tables in a forward-only migration and a repository whose

loadActiveReminders() returns Reminder[] (recording malformed rows) and findReminder(id) the

row's subject ({ taskId }, null when gone), created in openDeviceData as reminders on

AppData over the one connection

(examples/migration-reminders.ts,

examples/sqlite-reminder-repository.ts;

persistence-and-migrations owns the format).

  1. Copy the templates to the paths their first lines name, each with its test:

templates/src/core/reminders/ (the pure planner), templates/src/services/local-zone/,

templates/src/services/local-notifications/ (port, adapter, fake, texts, sync, the root kit and

reminder-sync-context.tsx),

templates/src/hooks/ (sync and tap hooks), templates/test/reminders/ (rule zones, rows) and the

catalog keys in templates/src/i18n/catalogs/ (merge into the app's catalogs; translate every

locale).

  1. Register the root kit in app-startup-and-bootstrap's registry src/services/create-root-kits.ts

(examples/create-root-kits.ts), which startApp runs once after

the data layer opened: create the notification and zone adapters (if push-notifications is

adopted, pass installForegroundHandler: false to the local adapter, rule 11), the one

reminderSync over data.reminders.loadActiveReminders, and add

createLocalNotificationsKit({ notifications, sync, hrefForReminder }) to the list. The root files

stay unchanged; the registry never opens the database.

  1. What the kit mounts: its provider (ReminderSyncProvider, so models call

useReminderSyncService()) and its effects beside the root Stack, inside the navigator:

useReminderSync(sync, t) with the shown t() and useReminderTaps, whose taps navigate to

hrefForReminder(id): the row's subject read again (findReminder), as a typed href, or home.

  1. Wire the actions: the "Remind me" press asks through permissions-and-system-prompts'

usePermissionGate over permissions.access.notifications (bound to this port, or to push's

when push is adopted: one OS permission) and calls sync.enable() from onAllowed; every

reminder write calls sync.request() after it commits

(examples/use-task-reminder-model.ts). Add a

notifications entry to contracts/permissions.json (no purposeKey; explain and settings copy

keys; askedFrom = that model, whose sibling test names blocked and denied or declined; that

skill's asking-flow section 12), or check-permissions fails. Without that skill, the press calls

sync.enable() and blocked offers Linking.openSettings().

  1. Test first for any rule change, then run

npx jest src/core/reminders src/services/local-notifications src/services/local-zone src/hooks --ci --maxWorkers=2

and npm run typecheck.

  1. Run the checks from the repo root:

node ${CLAUDE_SKILL_DIR}/scripts/check-reminder-code.mjs . and

node ${CLAUDE_SKILL_DIR}/scripts/check-reminder-logic.mjs .; fix every FAIL line (file, rule

and fix are printed) and rerun until both print RESULT: PASS.

  1. Prove delivery on devices you named yourself: a reminder a minute ahead fires in the

background and in the foreground, a tap opens the task on a warm and a cold start, the Android

channel shows its name in Settings (references/testing-and-devices.md;

e2e-maestro for the flow).

Definition of done

write calls sync.request() after its commit.

translated names before the prompt and before scheduling.

text; only reminder: identifiers are ever cancelled.

restore and after enable(); one setNotificationHandler exists.

permissions-and-system-prompts is adopted, with its notifications contract entry), never

from an effect; a blocked state offers Settings.

(run by startApp) and provided once by the kit; the composition root opens no database.

gone); no reminder row stores a path.

an app without the SDK or without local reminders prints NOT APPLICABLE: ...).

APPLICABLE cases).

Anti-patterns

or the diff double-schedules. Write the row, sync.request().

the old language. Plan one-shots; the foreground sync refills.

every flight. Store minuteOfDay and the rule.

and text.

notifications and makes every sync a full rewrite. Let the diff cancel by identifier.

iOS. Show the rows.

yet. Ask from "Remind me".

untrusted. { kind: 'reminder', reminderId }, then read the row.

renamed route until someone taps. Store the subject (the task id) and map it to a typed href.

getLastNotificationResponse() too.

minutes, not hours.

Files in this skill

| File | What it is | Read/run when |

|---|---|---|

| references/scheduling-model.md | The three layers, rows, the plan and window, identifiers, the diff and sync, when it runs, DST and travel, product shapes, restore, decisions | Workflow step 1; any reminder change |

| references/expo-notifications-api.md | The SDK 57 calls, what DATE becomes per platform (verified in source), the pending set, handler, permissions, channels, taps, what is not used | Workflow step 1; an SDK question |

| references/platform-behaviour.md | iOS vs Android: the 64 limit, prompt, channels, exact and inexact alarms, reboot, Doze, OEMs, lock-screen privacy, pitfalls table | Workflow step 1; a delivery bug |

| references/taps-and-routing.md | The tap data contract, flow, cold start, push coexistence contract, action buttons, tests | Workflow steps 1 and 7 |

| references/testing-and-devices.md | What each test proves, Jest recipes (rule zones, fakes, automock, hooks), named-device probes, what only real devices prove | Workflow steps 9 and 11 |

| references/checkers.md | Every rule of both checkers, the module contract, configuration keys, NOT APPLICABLE cases, troubleshooting | Workflow step 10, and when a check fails |

| templates/src/core/reminders/ | reminder.ts, wall-clock.ts, plan-reminders.ts, reconcile-reminders.ts, reminder-tap.ts and their tests (pure) | Workflow step 5 |

| templates/src/services/local-notifications/ | The port (+test), the expo-notifications adapter (+test), the fake (+test), reminder-texts.ts (+test), reminder-sync.ts (+test), the root kit local-notifications-root-kit.tsx (+test) and reminder-sync-context.tsx (ReminderSyncProvider, useReminderSyncService, +test) | Workflow steps 5-7 |

| templates/src/services/local-zone/ | LocalZonePort, the system adapter, the fake, their tests | Workflow step 5 |

| templates/src/hooks/ | use-reminder-sync.ts, use-reminder-taps.ts and their tests | Workflow steps 5 and 7 |

| templates/test/reminders/ | rule-zone.ts (zones as data), reminder-rows.ts (rows and plan input for tests) | Workflow step 5 |

| templates/src/i18n/catalogs/ | en.json, ar.json: the channel and notification keys to merge into the app's catalogs | Workflow step 5 |

| templates/src/core/dates/ | date-key.ts and its test (synced from seeded-determinism-and-golden-vectors; do not edit here) | Workflow step 2, only when the app lacks it |

| examples/migration-reminders.ts | The reminder tables of a Tasks app | Workflow step 4 |

| examples/sqlite-reminder-repository.ts | loadActiveReminders (malformed rows recorded), findReminder (the subject), skipToday over the tables | Workflow step 4 |

| examples/create-root-kits.ts | The root-kit registry with the reminders kit: the two adapters (and the handler option for push), the one sync over data.reminders, hrefForReminder (subject to typed href); no database open | Workflow steps 6-7 |

| examples/use-task-reminder-model.ts | The "Remind me" model: the permission gate, enable() once allowed, request() after writes | Workflow step 8 |

| scripts/check-reminder-code.mjs | Static rules: SDK in adapters, one writer, triggers and channels, one handler, no launch prompt, localized text, no wall clock, no USE_EXACT_ALARM, hooks mounted, the root kit registered | Workflow step 10 |

| scripts/check-reminder-logic.mjs | Runs the app's pure reminder modules against DST, identifier, limit, lead, skip, reject, data, diff and tap vectors | Workflow step 10 |

| scripts/lib/reminder-paths.mjs | Folder resolution (remindersCoreDir, localNotificationsDir) and the applicability facts | Never by hand |

| scripts/lib/reminder-checks.mjs | The behaviour vectors and rule zones check-reminder-logic runs | When a behaviour rule changes |

| scripts/lib/app-modules.mjs | Imports the app's pure TypeScript with tsconfig aliases (synced from the library; do not edit here) | Never by hand |

| scripts/lib/source-scan.mjs | Shared source helpers (synced from the library; do not edit here) | Never by hand |

| scripts/check-lib.mjs | Shared checker library (synced from the library; do not edit here) | Never by hand |

| scripts/selftest.mjs | Proves both checkers pass the templates and catch every planted bug | After changing a checker, a rule or a template |

| assets/shared.json | The synced files this skill declares | When a synced file is added |

| tests/ | bases/app/ (a minimal app that mounts the hooks) and fixtures/<checker>/ overlay cases on it plus the templates: good/, one bad-* per rule, pass-* (NOT APPLICABLE, push-only, USE_EXACT_ALARM under blockedPermissions, installed skills, type-only SDK imports, push owning the handler), error-no-src | When adding a rule |

Related skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.