## Implementation workflow

Work like an experienced React Native engineer: discover the host app first, research only what you need, decide runtime and navigation fit early, then integrate with minimal disruption. Follow phases in order.

**Success:** the block is reachable and runs correctly in the user's app on their preferred **mobile** runtime (or a clearly explained necessary alternative). Browser/web is never success.

**Default goal:** integrate the reference faithfully — research sources, bring over real implementation (not a toy rewrite), adapt to this project's conventions, preserve composition/layout/behavior unless **Your instructions** say otherwise.

**Orientation:** read the block title first.

**Universality:** these rules apply to any block and any RN project. Do not assume a demo lab, multi-block registry, Expo Router, or Expo Go unless discovery shows that is what the user has.

**Session host reuse:** If this conversation already recorded a host summary for this project (kind, stack, navigation, package manager, Phase 6 runtime A/B/C), **reuse it**. Briefly acknowledge the reused host, then continue — do **not** re-probe `package.json`, navigation layout, or runtime. Re-run discovery only when: no prior host summary exists in this conversation; the user switched projects/workspace; the user said the stack/runtime/navigation changed; or prior notes are incomplete/ambiguous for a decision you need now.

### Phase 0 — Environment gate
This is a React Native block (not a web component / chat-only tutorial).
1. Need filesystem + terminal in the user's project. If pasted into a web chat without that, **stop** and tell them to open an IDE/coding agent with project access and paste again.
2. Confirm Expo or bare React Native (not Next.js/web/Flutter/native-only/unrelated). When reusing a prior host summary, a brief confirmation that the workspace is still that RN project is enough — do not re-walk the tree.
3. If not RN, **stop** (beginner-friendly): say what you found, recommend `npx create-expo-app@latest my-app`, then reopen that app in an agent and paste again.
4. Do not create Expo inside an unrelated repo unless **Your instructions** say so. If the user asks and you can, create it and continue from Phase 1.
5. **Never verify in a browser.** Do not open a browser tab, Cursor Simple Browser, `expo start --web`, `npm run web`, or any web export to "test" this block — not as a fallback when iOS/Android/Simulator/Xcode/Android Studio fails. React Native UI, native modules, and gestures are not validated on web. If the chosen device/simulator cannot launch, say so and ask the user how to proceed (fix toolchain, use the other mobile platform, physical device, or pause) — **never** switch to web.

### Phase 1 — Discover the host app
**Skip if reusing** a prior host summary from this conversation (see Session host reuse). Otherwise discover:
1. **Project kind:** Expo (managed/prebuild) vs bare RN (`expo`, `app.json`/`app.config`, `android/`/`ios/`).
2. **Stack conventions:** `package.json`, folder layout, styling (StyleSheet / NativeWind / Tamagui / etc.), TypeScript, path aliases.
3. **Navigation (required):** identify how screens are mounted today:
   - **Expo Router** — `expo-router` dependency, `app/` file routes, `_layout` files, `Link`/`router`/`useRouter`/`useLocalSearchParams`.
   - **React Navigation** — `@react-navigation/*`, navigators in JS/TS (`createNativeStackNavigator`, tabs, drawers), screen `name`/`component` registration, `navigation.navigate`.
   - **Other / hybrid / none** — custom routers, single-screen apps, or mixed setups. Note the primary pattern the user actually ships.
4. Note package manager and how the app is usually started (Expo Go, dev client, bare `react-native run-*`).

### Phase 2 — Inventory sources (do not fetch yet)
List block GitHub/docs and linked UI kit/collection/package URLs from context. Sources may be GitHub-only, docs-only, or both. Proceed when enough exists to implement confidently.

### Phase 3 — Research the block (selective)
1. **GitHub:** fetch the entry, then resolve relative imports (`../`, siblings, local `components/`). Thin entries (`App.tsx` wrappers) → keep following until the real UI lives; do not stop at the shell.
2. **Docs:** install steps, API, examples. No GitHub → reconstruct from docs/collection/package sources when sufficient. Web/MDX samples (DOM, CSS, svg markup) → plan an RN port (`react-native-svg`, Reanimated, StyleSheet, etc.) that keeps behavior.
3. **Block navigation assumptions:** note whether the reference depends on Expo Router file routes, React Navigation APIs (`useNavigation`, stack headers, shared-element navigators, etc.), deep links, or is navigation-agnostic UI.
4. **Platform:** if the block is iOS-only or Android-only and the user's target is the other, **stop** with a clear why and a cross-platform alternative when known.
5. Insufficient sources → **stop** and report gaps. Do not invent a lookalike.

### Phase 4 — Navigation fit (before writing code)
Compare Phase 1 (host) with Phase 3 (block).

1. **Prefer the host:** mount and route the block using the user's navigation solution. Adapt wrappers, screen registration, params, and headers to match how this app already opens screens.
2. **Adapt when possible:** replace Expo Router-only APIs with React Navigation equivalents (or the reverse), extract the visual/interaction core into a screen component the host can register, and keep shared-transition / param wiring if the host can express it.
3. **Hard stop when not possible:** if the block's value depends on a navigation stack the host does not use and there is no faithful adaptation (e.g. Expo Router–only layouts/shared transitions that cannot be expressed in the user's React Navigation tree, or the reverse), **stop**. Tell the user clearly:
   - which navigation solution the block requires,
   - which solution their app uses,
   - that the block cannot be integrated as-is unless they change the app's navigation (or accept a reduced non-equivalent version — only offer that if they explicitly ask).
4. Do not silently add a second competing navigator "just to make the demo run" unless **Your instructions** request it.

### Phase 5 — Linked taxonomies (on demand)
For linked UI kits/collections/packages: note docs, optional sitemap, GitHub, directory, optional llms. Fetch a small sitemap only to locate pages — never crawl every URL. llms is optional. Fetch only install + pages you actually need. Never ingest whole doc sites, full sitemap lists, or entire `llms.txt` files.

### Phase 6 — Classify dependencies, then install
Decide the host runtime first, then classify deps and install. Do this **before** wiring UI so later errors are not misread as code bugs.

#### Step 0 — UI kit gate (only when the block context says a UI kit "needs app-wide setup")
Such a kit is the base component library an app is built on (shared theme, tokens, providers, styling setup), not a single component. A kit marked "needs no app-wide setup" has no gate: install the block like any other, through the kit's CLI when its docs offer one. Using the Phase 1 host summary, check whether the project already uses the setup kit (its packages in `package.json`, its config, providers, or generated component folder).
- **Already set up:** build the block on the existing kit setup. Do not reinstall or reconfigure it.
- **Not set up:** **STOP before installing anything.** In 2–3 short sentences tell the user that this block is built on the named kit, that it becomes the base layer of their app (packages, providers, styling config), and what setting it up adds. Link the kit's setup guide (or docs) from the context. Ask whether they understand and want to proceed with the kit setup. Continue only after they confirm, and follow that guide. If they decline, rebuild the block with the project's existing components instead and say what changed.

#### Step 1 — Identify the current host runtime (exactly one)
Reuse the prior Phase 6 runtime classification when the session host reuse rule applies. Otherwise, from Phase 1, pick **one**:
1. **Bare React Native** — no `expo` app runtime / not running via Expo Go or `expo-dev-client` (typical `react-native` CLI app with owned `android/`/`ios/`).
2. **Expo development build** — project already uses `expo-dev-client` / a custom dev client binary (not Expo Go).
3. **Expo Go** — user runs the project through the Expo Go app.

#### Step 2 — Classify block dependencies (by host)
**If bare RN:** bucket as pure JS/TS vs libraries with native code. **Do not** fetch the Expo Go allowlist or push Expo Go substitutes. If a dep is Expo-only (`expo-*` that expects the Expo runtime / config plugins / CNG), either add the minimum bare-RN Expo modules setup the library documents, use a non-Expo alternative that preserves behavior, or **stop** and say the block needs Expo.

**If Expo development build:** no Expo Go gate. Treat native deps as normal installs into the existing native binary (rebuild later). Prefer `npx expo install` for SDK-compatible versions.

**If Expo Go:**
1. Resolve Expo SDK major from `expo` in `package.json` (e.g. `~57.0.8` → `57`). Confirm the device's Expo Go targets the same major.
2. Fetch the Expo Go third-party allowlist (minor/patch always `0` in the URL):

```sh
curl -sL "https://docs.expo.dev/versions/vMAJOR.0.0/sdk/third-party-overview.md" \
  | awk '/Pages in this section:/,/Full documentation tree/' \
  | grep -oE '\[[^]]+\]\([^)]+\)' \
  | sed 's/\[\([^]]*\)\].*/\1/' \
  | grep -v '^Overview$' \
  | grep -v '^llms.txt$'
```

3. Mark each dep **Expo Go–compatible** only if: pure JS/TS, or `expo`/`expo-*` that ships with the SDK, or its name is on that allowlist. Anything else with native code (e.g. `react-native-teleport`) is **not** Expo Go–compatible.
4. Substitutes (e.g. `expo-video` vs `react-native-video`) only when they preserve features and keep you on Expo Go. Do not silently drop functionality.
5. **Version rule (Expo Go, only packages this block adds):** for allowlisted third-party and `expo`/`expo-*` deps **you are installing for this block**, use `npx expo install <those-pkgs>` so their versions match what Expo pins for this SDK (what `expo-doctor` expects for those packages). Do **not** install the block repo's exact version ranges for those packages. Do **not** upgrade, downgrade, or "fix" other existing app dependencies to satisfy `expo-doctor` — that is the user's choice, not part of this integration.

#### Step 3 — Install
- **Expo Go (Path C1 candidates):** install only the block's needed allowlisted/`expo-*` packages with `npx expo install <pkg>…` (batch the ones you are adding). Pure JS packages with no Expo pin → normal package manager. After that install, you may run `npx expo-doctor` **only to check the packages you just added** — if doctor flags one of those, re-run `npx expo install` for **that package only**. Ignore doctor complaints about unrelated existing deps; do not churn the rest of `package.json`.
- **Expo development build:** prefer `npx expo install` for SDK-related packages **this block adds**; other new native deps per their docs, then rebuild in Phase 7. Same rule: do not mass-align the whole project.
- **Bare RN:** project package manager + library docs (no `expo install` / allowlist).
- Do not run pods/prebuild/`expo run:*` yet unless Phase 7 says this host already owns a native binary and needs a rebuild after install.

Note when a block reference version differs from what `expo install` resolved for a package **you added** — report that after implementation (Phase 9).

### Phase 7 — Runtime path (follow in order — do not skip)
Use the host from Phase 6 Step 1. **Prefer staying on the current runtime.**

#### Path A — Bare RN → stay
1. Stay on bare RN. Never switch to Expo Go or invent a development-build fork "for convenience."
2. After native deps: `pod install` (iOS) as needed → `npx react-native run-ios` / `run-android` (or project scripts). JS-only → `npx react-native start --reset-cache`.
3. Link/build errors usually mean rebuild/pods/Gradle — fix real install steps; do not invent unrelated native patches.
4. Report: host = bare RN; which native deps required a rebuild.

#### Path B — Expo development build → stay
1. Stay on the existing development build. No Expo Go compatibility check; no "switch runtime" confirmation.
2. After native deps/config/SDK changes: `npx expo prebuild --clean` if needed, then `npx expo run:ios` / `run:android`. JS-only → `npx expo start -c` (or `--dev-client`).
3. Report: host = Expo development build; which deps required a rebuild.

#### Path C — Expo Go
**C1 — All deps Expo Go–compatible → stay**
Stay on Expo Go. The packages **this block added** stay on `npx expo install` versions. Do not rewrite the rest of the app's dependency tree. Verify with `npx expo start -c`. Do not create a development build.

**C2 — Any dep is not Expo Go–compatible → STOP (ask before switching)**
Do **not** install `expo-dev-client` or run `expo run:*` until the user explicitly agrees. Message must be short and beginner-friendly:

- **Why (1–2 sentences):** name the blocking package(s) and say Expo Go cannot load them, so this block needs a **development build** (your own app binary with those native modules).
- **Docs:** https://docs.expo.dev/develop/development-builds/introduction/
- **Are you ready?** local development builds need a native toolchain:
  - **iOS** — macOS + Xcode (+ Simulator): https://docs.expo.dev/workflow/ios-simulator/
  - **Android** — Android Studio (+ Emulator): https://docs.expo.dev/workflow/android-studio-emulator/
- Ask: proceed with a development build, and for which platform (iOS or Android)? If the toolchain is missing, say so and link the setup guide — installing Xcode / Android Studio is the prerequisite.
- If they **decline** or are not ready: do **not** switch runtimes; offer a reachable screen with an honest in-app notice naming the blocking native dependency.

**Never hand-patch native code to silence Expo Go errors** ("native module not found", "requires a development build", "Unimplemented component", missing Fabric/TurboModule). Those mean wrong runtime — go through C2, do not edit Podfile/pods/Gradle/`AppDelegate`/generated native files or write shims.

**Only after the user confirms C2**, switch with the local workflow (https://docs.expo.dev/develop/development-builds/introduction/):
1. `npx expo install expo-dev-client`
2. `npx expo run:ios` or `npx expo run:android` for the platform they chose (`prebuild` runs automatically; add `--device` for a physical device)
3. Then `npx expo start` (targets the dev build; `--dev-client` if needed)
4. Later native dep/config/SDK changes → `npx expo prebuild --clean` then re-run; JS-only → restart the server

Report: which dependency forced the switch, and which platform the user chose.

### Phase 8 — Implement
1. Place files per host conventions (existing screen, new registered screen, or shared component folder). Create only the navigation wiring Phase 4 approved.
2. Bring over reference files (or docs examples) plus supporting imports/hooks/styles/assets. Missing local binaries → use stable remote or other packager-friendly assets; do not block on unavailable demo binaries.
3. **Routing hygiene:** with Expo Router, only route entries belong under the routes tree — put helpers in non-route folders (`src/`, private `_lib/`, etc.). With React Navigation, keep screens registered explicitly; avoid orphan route files the host never mounts.
4. Adapt imports, aliases, theme tokens, and naming to the repo. Replace web-only or experimental CSS APIs with RN equivalents (`LinearGradient`, Skia, images, etc.). Replace placeholder icons in docs with real icon sets available to the project (e.g. `@expo/vector-icons` or the app's existing icon library).
5. Preserve the block's composition, layout, and behavior — no stripped demos unless **Your instructions** ask for a reduced version.
6. Make it reachable through the host's normal navigation. Do not delete or rewrite unrelated screens/routes the user already has unless **Your instructions** require that.
7. On **Expo Go**: do not edit native projects (Podfile, pods, Gradle, `AppDelegate`, generated `android/`/`ios/`) to force a module into Expo Go — that is Path C2. On **bare RN** or an **Expo development build**: normal install/link/pods/rebuild for new native deps is expected; still avoid unrelated hand-written native hacks.

### Phase 9 — Verify
1. **Triage errors before fixing.**
   - Real code/type/bundler bugs → fix them.
   - On **Expo Go**: "native module not found", "requires a development build", "Unimplemented component", missing Fabric/TurboModule → Phase 7 Path **C2** (**STOP and confirm**). Do **not** patch native files or write shims.
   - On **bare RN** or **Expo development build**: missing native module after install usually means pods/Gradle/rebuild or a missed install step — fix that path, not Expo Go workarounds.
2. Fix genuine type and bundler errors.
3. Keep the chosen runtime:
   - Path A (bare) → `npx react-native run-ios` / `run-android` after native changes; JS-only → `npx react-native start --reset-cache`
   - Path B or confirmed C2 (development build) → `npx expo run:ios` / `run:android` when a native rebuild is required; otherwise `npx expo start -c` (or `--dev-client`). If `expo run:*` starts Metro without `-c`, stop that Metro and continue with `npx expo start -c`.
   - Path C1 (Expo Go) → `npx expo start -c`
4. Always clear cache on JS restart.
5. Smoke-test on a **real mobile runtime only** (iOS Simulator, Android Emulator, or a physical device via Expo Go / development build / bare run) until the block is visible and interactive via the host navigation path. **Never** use a browser tab or web bundler as verification — including when Xcode, Simulator, or `expo run:ios` is blocked or broken. If mobile launch fails, stop and report the blocker; ask the user whether to try the other mobile platform, fix the toolchain, or pause.
6. **Version note for packages this block installed on Expo Go (Path C1):**
   - Scope = **only** the dependencies added/changed for this block. Never run a project-wide version realignment from `expo-doctor`.
   - If you use `npx expo-doctor`, act only on issues for those block packages (re-`npx expo install <that-pkg>`). Leave other doctor findings for the user.
   - If a block reference version differs from what was installed for a package you added, **tell the user after implementation**:
     - which package(s) (block version vs installed Expo-pinned version),
     - **why** (Expo Go needs the SDK-pinned version for that package; `npx expo install` / doctor for that package is the source of truth),
     - **what to do** (keep the installed pin while on Expo Go; only pursue a development build if they insist on the block's exact version — and warn that may still need care).
7. Report host path (A bare / B development build / C1 Expo Go / C2 switched), which dependency forced any change, any block-vs-Expo version diffs **for packages this block added**, navigation adaptations, and remaining platform caveats.

### Phase 10 — User instructions
If **Your instructions** are empty, skip. Otherwise apply them on top of the working integration.

Always begin with Phase 0 (environment gate). If a host summary is already known in this conversation, skip Phase 1 and continue from Phase 2; otherwise begin Phase 1.