|
| 1 | +# Brownie Getting Started |
| 2 | + |
| 3 | +## Discoverability triggers |
| 4 | + |
| 5 | +- "install @callstack/brownie" |
| 6 | +- "set up Brownie in brownfield app" |
| 7 | +- "first Brownie store setup" |
| 8 | +- "how to start Brownie on iOS or Android" |
| 9 | + |
| 10 | +## Scope |
| 11 | + |
| 12 | +In scope: |
| 13 | +- Prerequisites and initial installation. |
| 14 | +- First store definition and app entry import. |
| 15 | +- Platform handoff sequence for iOS and Android setup. |
| 16 | +- First-pass verification that state sync works. |
| 17 | + |
| 18 | +Out of scope: |
| 19 | +- Deep schema modeling details and codegen internals. For that, read [`store-definition-and-codegen.md`](store-definition-and-codegen.md) in this folder. |
| 20 | +- Advanced JS runtime patterns and low-level TypeScript APIs. For that, read [`typescript-usage.md`](typescript-usage.md) in this folder. |
| 21 | +- Platform-specific deep dives. For Android details, read [`android-usage.md`](android-usage.md). For iOS details, read [`swift-and-xcframework.md`](swift-and-xcframework.md) in this folder. |
| 22 | + |
| 23 | +## Procedure |
| 24 | + |
| 25 | +1. Confirm prerequisites |
| 26 | + - React Native brownfield setup is already complete. |
| 27 | + - `@callstack/react-native-brownfield` is installed. |
| 28 | + - Native host app(s) exist for iOS and/or Android. |
| 29 | + |
| 30 | +2. Install Brownie in the React Native app |
| 31 | + - Run `npm install @callstack/brownie`. |
| 32 | + |
| 33 | +3. Define the first store |
| 34 | + - Create a file ending in `.brownie.ts`. |
| 35 | + - Declare an interface extending `BrownieStore`. |
| 36 | + - Add module augmentation for `BrownieStores`. |
| 37 | + |
| 38 | +4. Ensure augmentation is loaded |
| 39 | + - Import the `.brownie.ts` file from the app entry (`App.tsx` or `index.js`). |
| 40 | + |
| 41 | +5. Add first TypeScript usage |
| 42 | + - Use `useStore('StoreName', selector)` in a component. |
| 43 | + - Perform one update via object or callback updater. |
| 44 | + |
| 45 | +6. Platform handoff |
| 46 | + - iOS path: |
| 47 | + 1. Run `npx brownfield package:ios --scheme YourScheme --configuration Release`. |
| 48 | + 2. Confirm package output contains your module XCFramework plus `Brownie.xcframework`, `ReactBrownfield.xcframework`, and Hermes (`hermesvm.xcframework` or `hermes.xcframework`). |
| 49 | + 3. Embed generated frameworks as `Embed & Sign`. |
| 50 | + 4. Register the store in app startup. |
| 51 | + - Android path: |
| 52 | + 1. Configure `brownie` settings in `package.json` (`kotlin`, `kotlinPackageName`). |
| 53 | + 2. Ensure Gson dependency exists in brownfield module or app. |
| 54 | + 3. Run `npx brownfield package:android --module-name :YourModuleName --variant release`. |
| 55 | + 4. Run `npx brownfield publish:android --module-name :YourModuleName`. |
| 56 | + 5. Register store during startup with `registerStoreIfNeeded`. |
| 57 | + - Note: both `package:ios` and `package:android` run Brownie codegen as part of packaging. |
| 58 | + |
| 59 | +7. Verify sync |
| 60 | + - Update state from React Native and confirm native UI observes updates. |
| 61 | + - Update from native and confirm React Native reflects changes. |
| 62 | + - If one side is stale after schema edits, rerun packaging/codegen and rebuild host apps. |
| 63 | + - Android runtime gate: |
| 64 | + - If launch fails with `ClassNotFoundException: com.google.gson.Gson`, add `implementation("com.google.code.gson:gson:<version>")` to brownfield module or host app and rebuild. |
| 65 | + |
| 66 | +## Quick reference |
| 67 | + |
| 68 | +- Install: `npm install @callstack/brownie` |
| 69 | +- Store file pattern: `*.brownie.ts` |
| 70 | +- Codegen/build entry points: |
| 71 | + - `npx brownfield codegen` |
| 72 | + - `npx brownfield package:ios --scheme YourScheme --configuration Release` |
| 73 | + - `npx brownfield package:android --module-name :YourModuleName --variant release` |
| 74 | + - `npx brownfield publish:android --module-name :YourModuleName` |
| 75 | +- iOS packaging outputs (CLI docs): |
| 76 | + - `ios/.brownfield/package/build/` |
| 77 | +- Error cues this guide handles first: |
| 78 | + - Store file exists but typed APIs are missing |
| 79 | + - Native setup done but store not registered at startup |
| 80 | + - First state update does not appear on one side |
0 commit comments