zakariaf/reactnative-skills/audio-and-haptics-feedback
Claude Code and agent skill by zakariaf/reactnative-skills
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Builds SFX and haptics behind ports. Use when adding or tuning sounds, SFX, music or haptics, or sound ignores the silent switch, stops the user's music or a pulse fails on Android. Not for settings (settings-and-preferences).
Install
npx vskill@latest install zakariaf/reactnative-skills/audio-and-haptics-feedbackSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as zakariaf/reactnative-skills/audio-and-haptics-feedback.
Audio and haptics feedback
Every sound an Expo app plays as feedback is synthesised from a literal recipe and played through one ambient AudioContext behind AudioPort; every pulse is a cue from a fixed table played through HapticsPort on iOS and Android, gated by the user's preference and throttled. This skill builds the ports, the cue tables, the banks, and the two checkers that prove them.
Rules that must hold
- One engine each, behind ports. Only
src/services/audio/audio-api-audio-adapter.tsimports
react-native-audio-api and only src/services/haptics/expo-haptics-adapter.ts imports expo-haptics; nothing imports react-native-sound or react-native-haptic-feedback, the feedback layer imports no media player, and Vibration never appears in the feedback layer or a view (elsewhere only with // vibration-exempt: <reason>). Tests use createFakeAudio()/createFakeHaptics(). Why: one file changes on a bump, two engines fight over the session, and tests run without native code.
- Pin react-native-audio-api exactly and override all five plugin defaults (`iosBackgroundMode:
false, androidPermissions: [], androidForegroundService: false, disableFFmpeg: true, disableStaticExternalLibs: true) through AUDIO_API_PLUGIN in app.config.ts; a new version goes through "Before any bump" and is recorded in contracts/audio-feedback.json`. Why: the library is pre-1.0, and the defaults add background audio, Android foreground-service permissions and build-time downloads.
- **One AudioContext, created in the adapter after
setAudioSessionOptions({ iosCategory: 'ambient' }),
and no audio focus on Android** (observeAudioInterruptions(true) only under Platform.OS === 'ios'). Why: ambient respects the silent switch and mixes with the user's music; on Android that call requests AUDIOFOCUS_GAIN, which fades out and mutes the user's music.
- Every sound is a literal `SoundRecipe` that passes `recipeProblems` (finite, peak 0.05-0.9, first
sample < 0.05, last < 0.01, later layers fade in over at least 1 ms, 10-1500 ms, music up to 30 s); the app's synth renders byte-identically to the checker's port. No streaming and no URL audio in the feedback layer; every recorded audio file in the repo is listed with its licence and source in the contract (bundledSounds for feedback, otherAudio for a notification sound or a feature's media). Why: no clicks, no clipping, no licences to chase, previews that are exactly what the device plays.
- Banks and ids: kebab-case nouns for what happened;
ui.is reserved forUI_SOUNDS; each feature
or game bank lives in <owner>/sounds/<owner>-sounds.ts as <OWNER>_SOUNDS, is tested, and is composed once in the root layout with composeSoundBank (which throws on a clash). Every cue names an id of its owner's bank and every sfx id is cued. Why: a typo is silence in production, a clash silently replaces another sound.
- Keep the voice policy: three category gains (
sfxanduifollow sound effects,music
follows music), volume², 50 ms ramps, at most 8 overlapping voices, the same sound at most once per 30 ms (or its minIntervalMs, at most 1000), voices as intervals on the audio clock, released by cancelPending. Why: even loudness, no clicks, no pile-ups, no sound lost after a fast action.
- **Music is off by default, never
activelyReclaimSession, and every music control is hidden when
hasMusic(bank) is false.** Why: the library cannot tell whether the user's own audio plays, so the app never plays over it unasked.
- Feedback fires from events on JS: a feature's cue table played by its model (
playCue), a canvas
track cue scheduled on the audio clock, a UI moment (playUiFeedback), or drained sim events; never from a view's own handler, a sim, a 'worklet' module or per frame, and each event in one place only; views (src/ui, a feature's screen or components) never call audio.play, playCue or playUiFeedback. Why: sync with the animation, and the UI thread never touches a port.
- Mount `useAudioLifecycle` once, in the root layout; the context runs only while the app is active
and nothing full-screen plays; iOS interruptions suspend it and resume it only if the lifecycle still wants it running (with a direction gate, mount it and load the bank behind the gate); await audio.dispose() before every JS reload, or await an injected beforeReload hook that the caller wires to () => services.audio.dispose(), or say why with // audio-dispose-exempt: <reason>. Why: no sound in the background or over a video, and the native engine closes before the bundle reloads.
- Haptics follow the cue table on both platforms (iOS feedback generators; Android
performAndroidHapticsAsync constants, an API 30 table and a legacy one), only while the user's preference is on, at least 40 ms apart, each call ending in .catch(() => undefined) inside the adapter; isSupported is false on iPad. Views use only selection (switches, pickers). Why: bursts feel like a buzz, a newer Android constant rejects on older phones, and buttons should not buzz.
- The app-wide moments go through `UI_FEEDBACK` (by default
toggle,success,error; the
table is the app's), each moment it keeps played from a model; buttons are silent by default, and an app that adds a tap moment renders <PressFeedbackProvider playsSound onPress={...}> that plays it (the canonical press surface then sets android_disableSound itself; no synced file is edited). Why: one forgotten handler is a silent switch, and Android would play its own click on top of the tap.
- Add no microphone purpose string up front; only if an App Store upload reports ITMS-90683, set
iosMicrophonePermission (localised, with a comment naming ITMS-90683). Why: feedback never records, and an unused purpose string invites review questions.
- A green gate proves a sound is clean, not right. Render the WAV previews, list the listening and
the feel on a real iPhone and Android phone for a human, and never block on the answer; test builds prove requests with the recording decorators. Why: an agent cannot hear and simulators have no haptic engine.
Workflow
- Pick the job. A new feedback layer: steps 2-6. Sounds for a feature or game: steps 7-9. Tuning a
sound: steps 8-9. Bumping the library: step 10. Always finish with step 11.
- Read references/audio-engine.md (library, plugin, port, adapter,
session and focus, lifecycle, music, wiring, testing) and references/haptics.md (cue table on both platforms, throttle, devices).
- Copy the templates at the paths their first line names (tests included):
templates/src/services/audio/
(with synth/), templates/src/services/haptics/, templates/src/services/feedback/, templates/src/services/test-hooks/recording-feedback.ts (test builds only), templates/src/config/audio-plugin.ts, templates/__mocks__/react-native-audio-api.ts, templates/contracts/audio-feedback.json (+ schema). src/hooks/use-is-app-active.ts, src/ui/press-feedback-context.tsx and src/core/rng/sfc32.ts belong to other skills; copy them only if the app lacks them. A haptics-only app copies haptics/ alone; the checker then notes that the audio rules do not apply.
- Install:
npx expo install expo-hapticsandnpm install --save-exact react-native-audio-api@0.13.6
(dependency-management records both in its policy). Add AUDIO_API_PLUGIN to app.config.ts plugins; check that .gitignore ignores reports/.
- Wire the composition root (the lines are in audio-engine.md, "Wiring"):
audioandhapticsin
Services, createDeviceServices and createTestServices; the haptics preference read at call time (settings-and-preferences owns it). In the root layout, services.audio.load(composeSoundBank(...)) in the startup initializer and useAudioLifecycle(...) once; imitate examples/root-layout-wiring.tsx. Make every reload path dispose first.
- Wire the moments (references/feedback-moments.md):
playUiFeedback(services, 'toggle') in switch handlers (the canonical one: the settings model's onToggled), 'success'/'error' where a requested action ends. Tap sounds only if the app wants them (the opt-in there).
- Plan the sounds. Read references/sound-design.md. Write the event →
sound → haptic table: most events get nothing, three to six sounds per feature, the most repeated the quietest, loud and long only for rare moments.
- Write the bank and the cue table test-first. Copy
templates/src/features/__FEATURE__/(bank,
cue table, their tests), replace __FEATURE__, __FEATURE_PASCAL__, __FEATURE_SOUNDS__ and __FEATURE_FEEDBACK__, write one literal recipe per sound, play each row from the model with playCue (or put it on the canvas track), add the bank to composeSoundBank, run npx prettier --write src/features/<feature> on the copied files, and run npx jest src/features/<feature> --ci --selectProjects unit until green (paths before the flag).
- Render and hand over the listening:
node ${CLAUDE_SKILL_DIR}/scripts/check-sound-banks.mjs . --wav-dir reports/sfx,
fix every FAIL, then list the listening as in examples/listening-checklist.md. Carry on; when a human answers, tune one number at a time and re-render.
- Bumping react-native-audio-api: follow "Before any bump" in audio-engine.md (release notes,
plugin defaults, mock, focus code, adapter tests, a smoke test on a named iOS simulator and Android emulator, a listening check), then set audioApiVersion in contracts/audio-feedback.json with the pin.
- Run the checks until both print
RESULT: PASS:node ${CLAUDE_SKILL_DIR}/scripts/check-sound-banks.mjs .
then node ${CLAUDE_SKILL_DIR}/scripts/check-audio-haptics.mjs .. Each FAIL names the file, the rule and the fix. Then npx jest src/services src/features/<feature> --ci --selectProjects unit android.
Definition of done
- [ ] The audio, haptics and feedback services, the config plugin and the root mock exist as in
templates/, and their tests pass in the unit and android Jest projects.
- [ ]
react-native-audio-apiis pinned to the contract'saudioApiVersion(default 0.13.6),
expo-haptics has the SDK's ~ range, AUDIO_API_PLUGIN is in app.config.ts, and there is no microphone purpose string without ITMS-90683.
- [ ] Every feature or game with sounds has a tested literal bank composed in the root layout, and a
cue table (or track cues) that names only its ids.
- [ ] Music is off by default and its controls are hidden without music; the haptics row is hidden when
isSupported is false (settings-and-preferences builds the rows).
- [ ]
useAudioLifecycleis mounted once; every reload disposes the engine or carries an exemption reason. - [ ] Every
UI_FEEDBACKmoment is played from a model; tap sounds only as the documented opt-in. - [ ] The WAV previews are rendered and the listening on an iPhone and an Android phone is listed for a
human (not blocking).
- [ ]
node ${CLAUDE_SKILL_DIR}/scripts/check-sound-banks.mjs .printsRESULT: PASS. - [ ]
node ${CLAUDE_SKILL_DIR}/scripts/check-audio-haptics.mjs .printsRESULT: PASS(a haptics-only
app prints the note audio rules not applicable: ...; an app with no feedback layer prints NOT APPLICABLE)
Anti-patterns
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/audio-and-haptics-feedback/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/zakariaf/reactnative-skills/audio-and-haptics-feedback)