Skip to content

Commit 0d7ebde

Browse files
Add Java docs
1 parent 25bdce6 commit 0d7ebde

File tree

4 files changed

+199
-8
lines changed

4 files changed

+199
-8
lines changed

android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeBrownfield.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ class ReactNativeBrownfield private constructor(val reactNativeHost: ReactNative
1919
val shared: ReactNativeBrownfield get() = instance
2020

2121
@JvmStatic
22-
fun initialize(rnHost: ReactNativeHost, application: Application) {
22+
fun initialize(application: Application, rnHost: ReactNativeHost) {
2323
if(!initialized.getAndSet(true)) {
2424
instance = ReactNativeBrownfield(rnHost)
2525
SoLoader.init(application.applicationContext,false)
2626
}
2727
}
2828

2929
@JvmStatic
30-
fun initialize(options: HashMap<String, Any>, application: Application) {
30+
fun initialize(application: Application, options: HashMap<String, Any>) {
3131
val rnHost = object : ReactNativeHost(application) {
3232
override fun getUseDeveloperSupport(): Boolean {
3333
return options["useDeveloperSupport"] as? Boolean ?: BuildConfig.DEBUG
@@ -43,14 +43,14 @@ class ReactNativeBrownfield private constructor(val reactNativeHost: ReactNative
4343
}
4444
}
4545

46-
initialize(rnHost, application)
46+
initialize(application, rnHost)
4747
}
4848

4949
@JvmStatic
50-
fun initialize(packages: List<ReactPackage>, application: Application) {
50+
fun initialize(application: Application, packages: List<ReactPackage>) {
5151
val options = hashMapOf("packages" to packages, "mainModuleName" to "index")
5252

53-
initialize(options, application)
53+
initialize(application, options)
5454
}
5555
}
5656

docs/JAVA.md

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
## Objective-C
2+
3+
React Native Brownfield provides first-class support for Java.
4+
5+
### Linking
6+
7+
The library is meant to work with [auto linking](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md). In case you can't use this feature, please check out the following options:
8+
9+
<details>
10+
<summary>react-native link</summary>
11+
Run the following command in your terminal:
12+
13+
```bash
14+
react-native link @callstack/react-native-brownfield
15+
```
16+
</details>
17+
18+
<details>
19+
<summary>Manually link the library on Android</summary>
20+
21+
#### `android/settings.gradle`
22+
```groovy
23+
include ':react-native-brownfield'
24+
project(':react-native-brownfield').projectDir = new File(rootProject.projectDir, '../node_modules/@callstack/react-native-brownfield/android')
25+
```
26+
27+
#### `android/app/build.gradle`
28+
```groovy
29+
dependencies {
30+
...
31+
implementation project(':react-native-brownfield')
32+
}
33+
```
34+
35+
#### `android/app/src/main/.../MainApplication.java`
36+
On top, where imports are:
37+
38+
```java
39+
import com.callstack.reactnativebrownfield.ReactNativeBrownfieldPackage;
40+
```
41+
42+
Add the `ReactNativeBrownfieldPackage` class to your list of exported packages.
43+
44+
```java
45+
@Override
46+
protected List<ReactPackage> getPackages() {
47+
return Arrays.asList(
48+
new MainReactPackage(),
49+
new ReactNativeBrownfieldPackage()
50+
);
51+
}
52+
```
53+
</details>
54+
55+
### API Reference
56+
57+
#### ReactNativeBrownfield
58+
59+
You can import the object from:
60+
61+
```java
62+
import com.callstack.reactnativebrownfield.ReactNativeBrownfield;
63+
```
64+
65+
---
66+
67+
**Statics:**
68+
69+
`initialize`
70+
71+
A function used to initialize a React Native Brownfield singleton. Keep in mind that it **doesn't** load React Native bundle.
72+
73+
Params:
74+
75+
| Param | Required | Type | Description |
76+
| ----------------------- | -------- | -------------------- | ------------------------------------------------------- |
77+
| application | Yes | Application | Main application. |
78+
| rnHost | No* | ReactNativeHost | A instance of [ReactNativeHost](https://bit.ly/2ZnwgnA). |
79+
| packages | No* | List<ReactPackage> | List of your React Native Native modules. |
80+
| options | No* | HashMap<String, Any> | Map of initial options. __Options listed below.__ |
81+
82+
> * - Those fields aren't itself required, but at least one of them is. See examples below.
83+
84+
Available options:
85+
- useDeveloperSupport: Boolean - Flag to use dev support.
86+
- packages: List<ReactPackage> - List of your React Native Native modules.
87+
- mainModuleName: String - Path to react native entry file.
88+
89+
Examples:
90+
91+
```java
92+
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
93+
@Override
94+
public boolean getUseDeveloperSupport() {
95+
return BuildConfig.DEBUG;
96+
}
97+
98+
@Override
99+
protected List<ReactPackage> getPackages() {
100+
@SuppressWarnings("UnnecessaryLocalVariable")
101+
List<ReactPackage> packages = new PackageList(this).getPackages();
102+
// Packages that cannot be autolinked yet can be added manually here, for example:
103+
// packages.add(new MyReactNativePackage());
104+
return packages;
105+
}
106+
107+
@Override
108+
protected String getJSMainModuleName() {
109+
return "index";
110+
}
111+
};
112+
113+
ReactNativeBrownfield.initialize(this, mReactNativeHost);
114+
```
115+
116+
```java
117+
List<ReactPackage> packages = new PackageList(this).getPackages();
118+
119+
ReactNativeBrownfield.initialize(this, packages);
120+
```
121+
122+
```java
123+
List<ReactPackage> packages = new PackageList(this).getPackages();
124+
HashMap<String, Object> options = new HashMap<>();
125+
options.put("packages", packages);
126+
options.put("mainModuleName", "example/index");
127+
128+
ReactNativeBrownfield.initialize(this, options);
129+
```
130+
131+
---
132+
133+
`getShared`
134+
135+
A singleton that keeps an instance of ReactNativeBrownfield object.
136+
137+
Examples:
138+
139+
```java
140+
ReactNativeBrownfield.getShared()
141+
```
142+
143+
---
144+
145+
**Properties:**
146+
147+
| Property | Type | Default | Description |
148+
| -------------------- | --------- | -------------- | -------------------------------------------------- |
149+
| bridge | RCTBridge | nil | Launch options, typically passed from AppDelegate. |
150+
| entryFile | NSString | index | Path to JavaScript root. |
151+
| fallbackResource | NSString | nil | Path to bundle fallback resource. |
152+
| bundlePath | NSString | main.jsbundle | Path to bundle fallback resource. |
153+
154+
---
155+
156+
**Methods:**
157+
158+
`startReactNative`
159+
160+
Starts React Native, produces an instance of a bridge. You can use it to initialize React Native in your app.
161+
162+
Params:
163+
164+
| Param | Required | Type | Description |
165+
| ----------------------- | -------- | ------------- | ----------------------------------------------------- |
166+
| startReactNative | No | Lambda | Callback invoked after JS bundle is fully loaded. |
167+
168+
Examples:
169+
170+
```java
171+
ReactNativeBrownfield.getShared().startReactNative();
172+
```
173+
174+
```java
175+
ReactNativeBrownfield.getShared().startReactNative(init -> {
176+
Log.d("loaded", "React Native loaded");
177+
});
178+
```
179+
180+
---
181+
182+
### Linking
183+
184+
You can find an example app [here](../example/java).
185+
186+

docs/OBJECTIVE_C.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Objective-C
22

3-
React Native brownfield provides first-class support for Objective-C.
3+
React Native Brownfield provides first-class support for Objective-C.
44

55
### Linking
66

@@ -16,6 +16,7 @@ Run the following command in your terminal:
1616
</details>
1717

1818
<details>
19+
<summary>CocoaPods</summary>
1920
Add the following line to your `Podfile`:
2021

2122
```ruby
@@ -51,10 +52,14 @@ You can import the object from:
5152

5253
---
5354

54-
**`shared` instance**
55+
**Statics:**
56+
57+
`shared`
5558

5659
A singleton that keeps an instance of ReactNativeBrownfield object.
5760

61+
Examples:
62+
5863
```objc
5964
[ReactNativeBrownfield shared]
6065
```

example/java/app/src/main/java/com/callstack/nativeexample/MainApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void onCreate() {
2020
options.put("packages", packages);
2121
options.put("mainModuleName", "example/index");
2222

23-
ReactNativeBrownfield.initialize(options, this);
23+
ReactNativeBrownfield.initialize(this, options);
2424
ReactNativeBrownfield.getShared().startReactNative(init -> {
2525
Log.d("test", "test");
2626
});

0 commit comments

Comments
 (0)