Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Rerun codegen if any of these change:
- Method return types

```bash
yarn brownfield:navigation-codegen
npx brownfield navigation:codegen
```

## Common errors
Expand Down
1 change: 0 additions & 1 deletion docs/docs/docs/api-reference/brownie/codegen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ The generated struct:
- Conforms to `BrownieStoreProtocol` with auto-generated `storeName`
- Uses mutable `var` properties


## How It Works

1. CLI recursively finds all `*.brownie.ts` files
Expand Down
11 changes: 7 additions & 4 deletions docs/docs/docs/api-reference/brownie/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ The CLI generates native types and builds everything into XCFrameworks:
npx brownfield package:ios --scheme YourScheme --configuration Release
```

This produces the following in `ios/.brownfield/package/`:
This produces the following in `ios/.brownfield/package/build/`:

- `YourScheme.xcframework` - Your React Native module
- `Brownie.xcframework` - Shared state library
- `ReactBrownfield.xcframework` - Brownfield integration
- `hermesvm.xcframework` - JavaScript engine (or `hermes.xcframework` for RN < 0.82.0)
- `ReactBrownfield.xcframework` - Brownfield integration
- `Brownie.xcframework` - Shared state library (only when using the Brownie package)
- `BrownfieldNavigation.xcframework` - Brownfield navigation integration (only when using the brownfield-navigation package)

The `ios/.brownfield/build/` directory contains the build cache.

:::info
The `package:ios` command automatically runs `brownfield codegen` to generate Swift types from your `.brownie.ts` files.
Expand All @@ -87,7 +90,7 @@ The `package:ios` command automatically runs `brownfield codegen` to generate Sw
## Step 5: Add Frameworks to Native App

1. Open your native Xcode project
2. Drag all XCFrameworks from `ios/.brownfield/package/` into your project
2. Drag all XCFrameworks from `ios/.brownfield/package/build/` into your project
3. In target settings → **General** → **Frameworks, Libraries, and Embedded Content**, set all to **Embed & Sign**

## Step 6: Register Store in Swift
Expand Down
26 changes: 19 additions & 7 deletions docs/docs/docs/api-reference/react-native-brownfield/java.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ ReactNativeBrownfield.getShared()

Creates a React Native view with a given module name. It automatically uses an instance of React Native created in `initialize` method. This is useful when embedding React Native views directly in your native layouts.

| Param | Required | Type | Description |
| ------------- | -------- | ------------------ | ---------------------------------------------------------- |
| context | Yes | `Context` | Android context to create the view |
| activity | No | `FragmentActivity` | Activity hosting the view, used for lifecycle management |
| moduleName | Yes | `String` | Name of React Native component registered to `AppRegistry` |
| launchOptions | No | `Bundle` | Initial properties to be passed to React Native component |
| Param | Required | Type | Description |
| ------------- | -------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| activity | No | `FragmentActivity` | Activity hosting the view, used for lifecycle management. Required for proper lifecycle; may be null only when passing a custom `reactDelegate`. |
| moduleName | Yes | `String` | Name of React Native component registered to `AppRegistry`. |
| launchOptions | No | `Bundle` | Initial properties to be passed to React Native component. |
| reactDelegate | No | `ReactDelegateWrapper` | Optional custom delegate. If passed, the `activity` argument is ignored. |

Returns: `FrameLayout` - A view containing the React Native component.

Expand All @@ -172,13 +172,25 @@ Returns: `FrameLayout` - A view containing the React Native component.
```java
// In a Fragment or Activity
FrameLayout reactView = ReactNativeBrownfield.getShared().createView(
context,
activity,
"ReactNative"
);
container.addView(reactView);
```

```java
// With initial properties
Bundle props = new Bundle();
props.putInt("score", 12);
FrameLayout reactView = ReactNativeBrownfield.getShared().createView(
activity,
"ReactNative",
null,
props
);
container.addView(reactView);
```

##### `postMessage`

Send a JSON string to the React Native JS layer. The message is delivered as a `brownfieldMessage` DeviceEventEmitter event and can be received using `ReactNativeBrownfield.onMessage()` on the JS side.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ ReactNativeBrownfield.setNativeBackGestureAndButtonEnabled(true);
A method to pop to native screen used to push React Native experience.

```ts
ReactNativeBrownfield.popToNative(animated: boolean);
ReactNativeBrownfield.popToNative(animated?: boolean);
```

**Parameters:**

| Param | Type | Description |
| -------- | --------- | -------------------------------------------- |
| animated | `boolean` | Whether to animate the transition (iOS only) |
| Param | Type | Description |
| -------- | --------- | ------------------------------------------------------------------------------------------------------ |
| animated | `boolean` | Optional. Whether to animate the transition (iOS only). Defaults to `false`, has no effect on Android. |

**Example:**

Expand Down
28 changes: 19 additions & 9 deletions docs/docs/docs/api-reference/react-native-brownfield/kotlin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ ReactNativeBrownfield.shared

Creates a React Native view with a given module name. It automatically uses an instance of React Native created in `initialize` method. This is useful when embedding React Native views directly in your native layouts or Jetpack Compose UI.

| Param | Required | Type | Description |
| ------------- | -------- | ------------------ | ---------------------------------------------------------- |
| context | Yes | `Context` | Android context to create the view |
| activity | No | `FragmentActivity` | Activity hosting the view, used for lifecycle management |
| moduleName | Yes | `String` | Name of React Native component registered to `AppRegistry` |
| launchOptions | No | `Bundle` | Initial properties to be passed to React Native component |
| Param | Required | Type | Description |
| ------------- | -------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| activity | No | `FragmentActivity` | Activity hosting the view, used for lifecycle management. Required for proper lifecycle; may be null only when using a custom `reactDelegate`. |
| moduleName | Yes | `String` | Name of React Native component registered to `AppRegistry`. |
| launchOptions | No | `Bundle` | Initial properties to be passed to React Native component. |
| reactDelegate | No | `ReactDelegateWrapper` | Optional custom delegate. If passed, the `activity` argument is ignored. |

Returns: `FrameLayout` - A view containing the React Native component.

Expand All @@ -151,18 +151,28 @@ Returns: `FrameLayout` - A view containing the React Native component.
```kotlin
// In a Fragment or Activity
val reactView = ReactNativeBrownfield.shared.createView(
context,
activity,
"ReactNative"
)
container.addView(reactView)
```

```kotlin
// With initial properties
val props = Bundle().apply { putInt("score", 12) }
val reactView = ReactNativeBrownfield.shared.createView(
activity,
"ReactNative",
launchOptions = props
)
container.addView(reactView)
```

```kotlin
// With Jetpack Compose
AndroidView(
factory = { context ->
ReactNativeBrownfield.shared.createView(context, fragmentActivity, "ReactNative")
factory = {
ReactNativeBrownfield.shared.createView(fragmentActivity, "ReactNative")
},
modifier = Modifier.fillMaxSize()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ A singleton that keeps an instance of `ReactNativeBrownfield` object.

#### Properties

| Property | Type | Default | Description |
| ------------------ | ---------- | --------------- | --------------------------------------------------------- |
| `entryFile` | `NSString` | `index` | Path to JavaScript root. |
| `fallbackResource` | `NSString` | `nil` | Path to bundle fallback resource. |
| `bundlePath` | `NSString` | `main.jsbundle` | Path to bundle fallback resource. |
| `bundle` | `NSBundle` | `Bundle.main` | Bundle instance to lookup the JavaScript bundle resource. |
| Property | Type | Default | Description |
| ------------------- | ------------------ | --------------- | ------------------------------------------------------------------------------ |
| `entryFile` | `NSString` | `index` | Path to JavaScript root. |
| `bundlePath` | `NSString` | `main.jsbundle` | Path to JavaScript bundle file. |
| `bundle` | `NSBundle` | `Bundle.main` | Bundle instance to lookup the JavaScript bundle resource. |
| `bundleURLOverride` | `NSURL *(^)(void)` | `nil` | Dynamic bundle URL provider. When set, overrides default bundle load behavior. |

---

Expand All @@ -43,10 +43,9 @@ A singleton that keeps an instance of `ReactNativeBrownfield` object.

Starts React Native, produces an instance of React Native. You can use it to initialize React Native in your app.

| Param | Required | Type | Description |
| ---------------- | -------- | --------------- | -------------------------------------------------- |
| `onBundleLoaded` | No | `void(^)(void)` | Callback invoked after JS bundle is fully loaded. |
| `launchOptions` | No | `NSDictionary` | Launch options, typically passed from AppDelegate. |
| Param | Required | Type | Description |
| ---------------- | -------- | --------------- | ------------------------------------------------- |
| `onBundleLoaded` | No | `void(^)(void)` | Callback invoked after JS bundle is fully loaded. |

**Examples:**

Expand All @@ -60,12 +59,6 @@ Starts React Native, produces an instance of React Native. You can use it to ini
}];
```

```objc
[[ReactNativeBrownfield shared] startReactNative:^(void){
NSLog(@"React Native started");
}, launchOptions];
```

##### `view`

Creates a React Native view for the specified module name.
Expand All @@ -82,6 +75,17 @@ Creates a React Native view for the specified module name.
UIView *view = [[ReactNativeBrownfield shared] viewWithModuleName:@"ReactNative" initialProps:@{@"score": @12}];
```

##### `application:didFinishLaunchingWithOptions:`

Mirrors the host runtime app delegate API. Call this from your `AppDelegate` if you need to forward launch options to the brownfield runtime (e.g. when using Expo).

| Param | Required | Type | Description |
| --------------- | -------- | ----------------- | -------------------------- |
| `application` | Yes | `UIApplication *` | The application instance. |
| `launchOptions` | No | `NSDictionary *` | Launch options dictionary. |

Returns: `BOOL` – return value is passed through from the runtime.

##### `postMessage`

Send a JSON string to the React Native JS layer. The message is delivered as a `brownfieldMessage` DeviceEventEmitter event.
Expand Down
38 changes: 26 additions & 12 deletions docs/docs/docs/api-reference/react-native-brownfield/swift.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ ReactNativeBrownfield.shared
| Property | Type | Default | Description |
| ------------------- | --------------- | --------------- | ---------------------------------------------------------------------------------------------- |
| `entryFile` | `String` | `index` | Path to JavaScript root. |
| `fallbackResource` | `String?` | `nil` | Path to bundle fallback resource. |
| `bundlePath` | `String` | `main.jsbundle` | Path to bundle fallback resource. |
| `bundlePath` | `String` | `main.jsbundle` | Path to JavaScript bundle file. |
| `bundle` | `Bundle` | `Bundle.main` | Bundle instance to lookup the JavaScript bundle resource. |
| `bundleURLOverride` | `(() -> URL?)?` | `nil` | Dynamic bundle URL provider called on every bundle load. When set, overrides default behavior. |

Expand All @@ -44,10 +43,9 @@ ReactNativeBrownfield.shared

Starts React Native. You can use it to initialize React Native in your app.

| Param | Required | Type | Description |
| ---------------- | -------- | --------------------- | -------------------------------------------------- |
| `onBundleLoaded` | No | `(() -> Void)?` | Callback invoked after JS bundle is fully loaded. |
| `launchOptions` | No | `[AnyHashable: Any]?` | Launch options, typically passed from AppDelegate. |
| Param | Required | Type | Description |
| ---------------- | -------- | --------------- | ------------------------------------------------- |
| `onBundleLoaded` | No | `(() -> Void)?` | Callback invoked after JS bundle is fully loaded. |

**Examples:**

Expand All @@ -61,12 +59,6 @@ ReactNativeBrownfield.shared.startReactNative(onBundleLoaded: {
})
```

```swift
ReactNativeBrownfield.shared.startReactNative(onBundleLoaded: {
print("React Native started")
}, launchOptions: launchOptions)
```

##### `view`

Creates a React Native view for the specified module name.
Expand Down Expand Up @@ -105,6 +97,28 @@ let json = try! JSONSerialization.data(withJSONObject: payload)
ReactNativeBrownfield.shared.postMessage(String(data: json, encoding: .utf8)!)
```

##### `application(_:didFinishLaunchingWithOptions:)`

Mirrors the host runtime app delegate API. Call this from your `AppDelegate` if you need to forward `application(_:didFinishLaunchingWithOptions:)` to the brownfield runtime (e.g. when using Expo).

| Param | Required | Type | Description |
| --------------- | -------- | ---------------------------------------- | -------------------------- |
| `application` | Yes | `UIApplication` | The application instance. |
| `launchOptions` | No | `[UIApplication.LaunchOptionsKey: Any]?` | Launch options dictionary. |

Returns: `Bool` – return value is passed through from the runtime.

**Example:**

```swift
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
return ReactNativeBrownfield.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
}
```

##### `onMessage`

Subscribe to messages sent from JavaScript via `ReactNativeBrownfield.postMessage()`. Returns an observer token that can be used to unsubscribe.
Expand Down
Loading
Loading