Skip to content

Commit 02cea18

Browse files
thymikeeCopilot
andauthored
docs: rework README with examples and better readability (#121)
* docs: rework README * wording * add tip with ebook * Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * remove thread * Update README.md --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0067365 commit 02cea18

File tree

1 file changed

+148
-34
lines changed

1 file changed

+148
-34
lines changed

README.md

Lines changed: 148 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</a>
44

55
<p align="center">
6-
Set of helpers to make your brownfield integration smooth and easy.
6+
A set of helpers to make your brownfield integration smooth and easy.
77
</p>
88

99
---
@@ -21,86 +21,199 @@
2121

2222
## Features
2323

24-
- **Easily integrate** React Native with existing native app
24+
- **Easily integrate** React Native with an existing native app
2525
- Start React Native with **one method** and invoke code as soon as it's loaded
26-
- Compatible with **both old and new React Native architecture**!
26+
- Compatible with **both legacy and new React Native architecture**!
2727
- Reuse the same instance of React Native between different components
2828
- Use predefined **native building blocks** - crafted for React Native
2929
- Disable and enable **native gestures and hardware buttons** from JavaScript
30-
- Works well with **any native navigation** pattern, as well as every React Native JavaScript based navigation
30+
- Works well with **any native navigation** pattern, as well as any React Native JavaScript-based navigation
3131
- Compatible with all native languages **Objective-C**, **Swift**, **Java** and **Kotlin**
3232
- Supports UIKit and SwiftUI on iOS and Fragments and Jetpack Compose on Android
3333

34-
3534
## Installation
3635

36+
The React Native Brownfield library is intended to be installed in a React Native app that is later consumed as a framework artifact by your native iOS or Android app.
37+
38+
In your React Native project run:
39+
3740
```sh
3841
npm install @callstack/react-native-brownfield
3942
```
4043

41-
or
44+
## Usage
4245

43-
```sh
44-
yarn add @callstack/react-native-brownfield
46+
<a href="https://www.callstack.com/ebooks/incremental-react-native-adoption-in-native-apps?utm_campaign=brownfield&utm_source=github&utm_medium=referral&utm_content=react-native-brownfield" align="center">
47+
<img alt="Download a free copy of Incremental React Native adoption in native apps ebook" src="https://github.com/user-attachments/assets/ba42bb29-1e7a-4683-80c5-2602afb1a7e6">
48+
</a>
49+
50+
### Packaging React Native app as a framework
51+
52+
First, we need to package our React Native app as an XCFramework or Fat-AAR.
53+
54+
#### With RNEF
55+
56+
Follow [Integrating with Native Apps](https://www.rnef.dev/docs/brownfield/intro) steps in RNEF docs and run:
57+
58+
- `rnef package:ios` for iOS
59+
- `rnef package:aar` for Android
60+
61+
#### With custom scripts
62+
63+
Instead of using RNEF, you can create your own custom packaging scripts. Here are base versions for iOS and Android that you'll need to adjust for your project-specific setup:
64+
65+
- [Example iOS script](https://github.com/callstackincubator/modern-brownfield-ref/blob/main/scripts/build-xcframework.sh)
66+
- [Example Android script](https://github.com/callstackincubator/modern-brownfield-ref/blob/main/scripts/build-aar.sh)
67+
68+
### Native iOS app
69+
70+
In your native iOS app, initialize React Native and display it where you like. For example, to display React Native views in SwiftUI, use the provided `ReactNativeView` component:
71+
72+
```swift
73+
import SwiftUI
74+
import ReactBrownfield # exposed by RN app framework
75+
76+
@main
77+
struct MyApp: App {
78+
init() {
79+
ReactNativeBrownfield.shared.startReactNative {
80+
print("React Native bundle loaded")
81+
}
82+
}
83+
84+
var body: some Scene {
85+
WindowGroup {
86+
ContentView()
87+
}
88+
}
89+
}
90+
91+
struct ContentView: View {
92+
var body: some View {
93+
NavigationView {
94+
VStack {
95+
Text("Welcome to the Native App")
96+
.padding()
97+
98+
NavigationLink("Push React Native Screen") {
99+
ReactNativeView(moduleName: "ReactNative")
100+
.navigationBarHidden(true)
101+
}
102+
}
103+
}
104+
}
105+
}
45106
```
46107

47-
## Enabling New Architecture
108+
For more detailed instructions and API for iOS, see docs for:
109+
110+
- [Objective C](docs/OBJECTIVE_C.md)
111+
- [Swift](docs/SWIFT.md)
112+
113+
### Native Android app
48114

49-
### Android
50-
Add the following to your `android/gradle.properties`:
115+
In your native Android app, create a new `RNAppFragment.kt`:
51116

117+
```kt
118+
119+
import android.os.Bundle
120+
import android.view.LayoutInflater
121+
import android.view.View
122+
import android.view.ViewGroup
123+
import androidx.fragment.app.Fragment
124+
import com.callstack.rnbrownfield.RNViewFactory # exposed by RN app framework
125+
126+
class RNAppFragment : Fragment() {
127+
override fun onCreateView(
128+
inflater: LayoutInflater,
129+
container: ViewGroup?,
130+
savedInstanceState: Bundle?,
131+
): View? =
132+
this.context?.let {
133+
RNViewFactory.createFrameLayout(it)
134+
}
135+
}
52136
```
53-
# Enable new architecture
54-
newArchEnabled=true
137+
138+
Add a button to your `activity_main.xml`:
139+
140+
```xml
141+
<Button
142+
android:id="@+id/show_rn_app_btn"
143+
android:layout_width="wrap_content"
144+
android:layout_height="wrap_content"
145+
android:text="Show RN App"
146+
app:layout_constraintBottom_toBottomOf="parent"
147+
app:layout_constraintEnd_toEndOf="parent"
148+
app:layout_constraintStart_toStartOf="parent"
149+
app:layout_constraintTop_toTopOf="parent" />
55150
```
56151

57-
### iOS
58-
Install cocoapods with the flag:
152+
Add a fragment container:
59153

60-
```
61-
RCT_NEW_ARCH_ENABLED=1 pod install
154+
```xml
155+
<FrameLayout
156+
android:id="@+id/fragmentContainer"
157+
android:layout_width="match_parent"
158+
android:layout_height="match_parent" />
62159
```
63160

64-
> [!NOTE]
65-
> New Architecture is enabled by default from React Native 0.76
161+
Update your `MainActivity` to initialize React Native and show the fragment:
66162

67-
## Usage
163+
```kt
164+
class MainActivity : AppCompatActivity() {
165+
private lateinit var showRNAppBtn: Button
166+
167+
override fun onCreate(savedInstanceState: Bundle?) {
168+
super.onCreate(savedInstanceState)
169+
ReactNativeHostManager.shared.initialize(this.application)
170+
171+
showRNAppBtn = findViewById(R.id.show_rn_app_btn)
172+
showRNAppBtn.setOnClickListener {
173+
supportFragmentManager
174+
.beginTransaction()
175+
.replace(R.id.fragmentContainer, RNAppFragment())
176+
.commit()
177+
}
178+
}
179+
180+
}
181+
```
68182

69-
React Native Brownfield library works with all major native programming languages. Majority of its API is exposed on the native side. Click on the logo to choose the one that interests you:
183+
For more detailed instructions and API for Android, see docs for:
70184

71-
| [<img src="https://user-images.githubusercontent.com/7837457/63374769-cafd1e80-c38a-11e9-9724-e797a199ebab.png" width="100px;" alt="Objective-C"/><br /><sub><b>Objective-C</b></sub>](docs/OBJECTIVE_C.md) | [<img src="https://user-images.githubusercontent.com/7837457/63374778-ce90a580-c38a-11e9-8f37-72a9a5b9a52f.png" width="100px;" alt="Swift"/><br /><sub><b>Swift</b></sub>](docs/SWIFT.md) | [<img src="https://user-images.githubusercontent.com/7837457/63374794-d2bcc300-c38a-11e9-9a7f-d538563b75db.png" width="100px;" alt="Java"/><br /><sub><b>Java</b></sub>](docs/JAVA.md) | [<img src="https://user-images.githubusercontent.com/7837457/63374783-d0f2ff80-c38a-11e9-9790-041cad53b259.png" width="100px;" alt="Kotlin"/><br /><sub><b>Kotlin</b></sub>](docs/KOTLIN.md) |
72-
| :---: | :---: | :---: | :---: |
185+
- [Java](docs/JAVA.md)
186+
- [Kotlin](docs/KOTLIN.md)
73187

74188
### JavaScript Module
75189

76-
Besides native components, we are exposing JavaScript functions to control the behavior of those components.
190+
Besides native components, we are exposing JavaScript functions to control the behavior of those components from React Native app.
77191

78-
To use the module, simply import it:
192+
To use the module, import it:
79193

80194
```js
81195
import ReactNativeBrownfield from '@callstack/react-native-brownfield';
82196
```
83197

84-
### JavaScript API Reference:
198+
and use the available methods:
85199

86-
**setNativeBackGestureAndButtonEnabled(enabled: boolean)**
200+
#### setNativeBackGestureAndButtonEnabled(enabled: boolean)
87201

88-
A method used to toggle iOS native back gesture and Android hardware back button.
202+
A method used to toggle iOS native back gesture and Android hardware back button.
89203

90-
```js
204+
```ts
91205
ReactNativeBrownfield.setNativeBackGestureAndButtonEnabled(true);
92206
```
93207

94-
**popToNative(animated[iOS only]: boolean)**
208+
#### popToNative(animated[iOS only]: boolean)
95209

96-
A method to pop to native screen used to push React Native experience.
210+
A method to pop to native screen used to push React Native experience.
97211

98-
```js
212+
```ts
99213
ReactNativeBrownfield.popToNative(true);
100214
```
101215

102-
> NOTE: Those methods works only with native components provided by this library.
103-
216+
> **Note:** These methods work only with native components provided by this library.
104217
105218
## Made with ❤️ at Callstack
106219

@@ -122,6 +235,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
122235
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
123236

124237
<!-- badges -->
238+
125239
[build-badge]: https://img.shields.io/circleci/build/github/callstack/react-native-brownfield/master.svg?style=flat-square
126240
[build]: https://circleci.com/gh/callstack/react-native-brownfield
127241
[version-badge]: https://img.shields.io/npm/v/@callstack/react-native-brownfield.svg?style=flat-square

0 commit comments

Comments
 (0)