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
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"root": true,
"extends": ["@react-native", "prettier"],
"plugins": ["prettier"],
"ignorePatterns": ["node_modules/", "lib/"]
}
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
android:
name: Build Android App
runs-on: ubuntu-latest

env:
SKIP_YARN_COREPACK_CHECK: 0

Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
ios:
name: Build iOS App
runs-on: macos-latest

env:
SKIP_YARN_COREPACK_CHECK: 0

Expand Down Expand Up @@ -85,4 +85,4 @@ jobs:
- name: Build iOS App
run: |
cd example/swift
xcodebuild -workspace SwiftExample.xcworkspace -scheme SwiftExample -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16' build CODE_SIGNING_ALLOWED=NO
xcodebuild -workspace SwiftExample.xcworkspace -scheme SwiftExample -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16' build CODE_SIGNING_ALLOWED=NO
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Lint & Type Check

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
analyse:
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
lib
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"quoteProps": "consistent",
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
18 changes: 18 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://unpkg.com/release-it@19/schema/release-it.json",
"git": {
"commitMessage": "chore: release ${version}",
"tagName": "v${version}"
},
"npm": {
"publish": true
},
"github": {
"release": true
},
"plugins": {
"@release-it/conventional-changelog": {
"preset": "angular"
}
}
}
22 changes: 11 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ orientation.
Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
- The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities
Expand Down Expand Up @@ -70,4 +70,4 @@ members of the project's leadership.
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct/

[homepage]: https://www.contributor-covenant.org
[homepage]: https://www.contributor-covenant.org
26 changes: 26 additions & 0 deletions bob.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
source: 'src',
output: 'lib',
targets: [
[
'commonjs',
{
esm: true,
configFile: true,
},
],
[
'module',
{
esm: true,
configFile: true,
},
],
[
'typescript',
{
project: 'tsconfig.build.json',
},
],
],
};
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { extends: ['@commitlint/config-conventional'] };
23 changes: 11 additions & 12 deletions docs/GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ Here you can find the guidelines for standard brownfield approach and advanced u
As a golden rule of standard brownfield with react-native, your native App should never have to interact directly
with react-native APIs. There are various reasons that doing the opposite is discouraged.

- If you have different teams working on RN brownfield and the native App and you distribute your AAR/XCFramework to the native
team. They can use the APIs from those artifacts and interact with them. However, if the native team have to import a react native
API, say `PackageList` then the rule of brownfield is being violated. The native team have native developers and they should not need
to worry about and interact with react-native directly. All of the abstraction should be handled within your artifacts.
- If you have different teams working on RN brownfield and the native App and you distribute your AAR/XCFramework to the native
team. They can use the APIs from those artifacts and interact with them. However, if the native team have to import a react native
API, say `PackageList` then the rule of brownfield is being violated. The native team have native developers and they should not need
to worry about and interact with react-native directly. All of the abstraction should be handled within your artifacts.

- If your native App interacts with react-native directly then you could imagine how complicated the codebase would be. The native App
should follow and worry about their native APIs rather than interacting with react-native. If in future, some react-native APIs needs to
be changed or refactored, then the effort would be cumbersome. On the contrast, if your native App was interacting with your artifact only
then the native App need not to worry about what happens internally. This makes things simpler for the native App team.
should follow and worry about their native APIs rather than interacting with react-native. If in future, some react-native APIs needs to
be changed or refactored, then the effort would be cumbersome. On the contrast, if your native App was interacting with your artifact only
then the native App need not to worry about what happens internally. This makes things simpler for the native App team.

- If the native App team is using your artifact and any build, compile time or run time issue arises the stack trace would lead to your artifact
and making it simpler for the teams to focus on their area only. On the contrary, if the native App team would interact with react-native directly,
then any related issues would be time consuming for that team to figure out the root cause and then delegate to the team managing RN flows.
and making it simpler for the teams to focus on their area only. On the contrary, if the native App team would interact with react-native directly,
then any related issues would be time consuming for that team to figure out the root cause and then delegate to the team managing RN flows.

Building upon the above points, below is how your brownfield implementation should look like if you're using `react-native-brownfield`:

- In your brownfield android library or iOS xcframework, create a class following the facade pattern. The role of this class would be to encapsulate the
initialization of `react-native-brownfield` by not asking the native App to interact with `react-native` directly. Below is how it would look like:
initialization of `react-native-brownfield` by not asking the native App to interact with `react-native` directly. Below is how it would look like:

```kt
// Your artifact
Expand Down Expand Up @@ -64,7 +64,6 @@ ReactNativeHostManager.initialize(application)
As you can see the issue here is that now we are mixing the native App with react-native APIs, which is discouraged. If we stick to
the above approach then the native App is free of interacting with react-native directly.


### Advanced Use Cases:

If you built on top of the above approach, then you can rather easily scale it to incorporate advanced use cases. We will discuss here only one
Expand Down Expand Up @@ -130,4 +129,4 @@ fun sendEvent(event: String, handlerId: String) {
fun sendEvent(event: String, handlerId: String) {
eventHandlers[handlerId].invoke(event)
}
```
```
29 changes: 15 additions & 14 deletions docs/JAVA.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ React Native Brownfield provides first-class support for Java.

### Kotlin setup

Even though the library provides a first-class Java support, it's written in Kotlin. To compile the project with React Native Brownfield, we need to make sure that our project's `build.gradle` file contains the required Gradle plugin.
Even though the library provides a first-class Java support, it's written in Kotlin. To compile the project with React Native Brownfield, we need to make sure that our project's `build.gradle` file contains the required Gradle plugin.

```java
buildscript {
Expand Down Expand Up @@ -37,8 +37,8 @@ ReactNativeBrownfield.initialize(application, packages);
<hr/>
<br/>

> Note: Previously, you were required to implement `DefaultHardwareBackBtnListener` in your calling Activity. Now with > 1.1.0 you are not required to do that step.
If you're upgrading to the latest version then you can safely remove that interface implementation from your calling Activity.
> Note: Previously, you were required to implement `DefaultHardwareBackBtnListener` in your calling Activity. Now with > 1.1.0 you are not required to do that step.
> If you're upgrading to the latest version then you can safely remove that interface implementation from your calling Activity.

<hr/>

Expand All @@ -62,17 +62,18 @@ A function used to initialize a React Native Brownfield singleton. Keep in mind

Params:

| Param | Required | Type | Description |
| ---------------- | ------------ | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| application | Yes | `Application` | Main application. |
| reactHost | Exclusively* | `ReactHost` | An instance of [ReactHost](https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactHost.kt). |
| packages | Exclusively* | `List<ReactPackage>` | List of your React Native Native modules. |
| options | Exclusively* | `HashMap<String, Any>` | Map of initial options. __Options listed below.__ |
| onJSBundleLoaded | Exclusively* | `OnJSBundleLoaded` | Callback invoked after JS bundle is fully loaded. |
| Param | Required | Type | Description |
| ---------------- | ------------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| application | Yes | `Application` | Main application. |
| reactHost | Exclusively\* | `ReactHost` | An instance of [ReactHost](https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactHost.kt). |
| packages | Exclusively\* | `List<ReactPackage>` | List of your React Native Native modules. |
| options | Exclusively\* | `HashMap<String, Any>` | Map of initial options. **Options listed below.** |
| onJSBundleLoaded | Exclusively\* | `OnJSBundleLoaded` | Callback invoked after JS bundle is fully loaded. |

> * - From the marked fields, exactly one must be specified, excluding the others. See examples below.
> - - From the marked fields, exactly one must be specified, excluding the others. See examples below.

Available options:

- `useDeveloperSupport`: `Boolean` - Flag to use dev support.
- `packages`: `List<ReactPackage>` - List of your React Native Native modules.
- `mainModuleName`: `String` - Path to react native entry file (when loading from Metro).
Expand Down Expand Up @@ -144,7 +145,7 @@ ReactNativeBrownfield.initialize(this, options, initialized -> {

A singleton that keeps an instance of ReactNativeBrownfield object.

Examples:
Examples:

```java
ReactNativeBrownfield.getShared()
Expand Down Expand Up @@ -194,7 +195,7 @@ container.addView(reactView);

#### `ReactNativeFragment`

An fragment rendering `ReactRootView` with a given module name. It automatically uses an instance of a React Native created in `initialize` method. It works well with exposed JavaScript module. All the lifecycles are proxied to `ReactInstanceManager`. It's the simplest way to embed React Native into your navigation stack.
An fragment rendering `ReactRootView` with a given module name. It automatically uses an instance of a React Native created in `initialize` method. It works well with exposed JavaScript module. All the lifecycles are proxied to `ReactInstanceManager`. It's the simplest way to embed React Native into your navigation stack.

```java
import com.callstack.reactnativebrownfield.ReactNativeFragment;
Expand All @@ -215,7 +216,7 @@ Params:
| moduleName | Yes | `String` | Name of React Native component registered to `AppRegistry`. |
| initialProps | No | `Bundle` \|\| `HashMap<String, *>` \|\| `ReadableMap` | Initial properties to be passed to React Native component. |

Examples:
Examples:

```java
ReactNativeFragment.createReactNativeFragment("ReactNative");
Expand Down
Loading