Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update kotlin integration with Existing Apps and Fragment #4204

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hurali97
Copy link

Description:

While following the docs for integrating React Native within a Kotlin App, the docs appeared to be outdated as the build configurations described in the docs were failing. The same case was with the Kotlin integration code snippets.

This might have happened due to the docs for brownfield integration not being up-to-date with latest RN versions.

Hence, I have created this PR after figuring out the build configurations that worked and the updated code snippets. I took some help from build gradle files from react-native repo in order to use the correct build configurations.

@@ -238,6 +230,8 @@ protected void onCreate(Bundle savedInstanceState) {

In the code above `Fragment reactNativeFragment = new ReactFragment.Builder()` creates the ReactFragment and `getSupportFragmentManager().beginTransaction().add()` adds the Fragment to the Frame Layout.

We have to implement the `DefaultHardwareBackBtnHandler` interface and override the `invokeDefaultOnBackPressed` method. This is necessary to allow react-native handle the back button press event.

Copy link
Author

@hurali97 hurali97 Aug 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the my understanding from react-native repo here, I have added this information. If this seems in correct, feel free to provide the correct one and I will update this PR.

I had to implement DefaultHardwareBackBtnHandler otherwise the app would crash.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the crash? I don't think this is strictly necessary

Copy link

netlify bot commented Aug 31, 2024

Deploy Preview for react-native ready!

Name Link
🔨 Latest commit c7ed54f
🔍 Latest deploy log https://app.netlify.com/sites/react-native/deploys/66d336f6b030070008ec24f0
😎 Deploy Preview https://deploy-preview-4204--react-native.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +113 to 117
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
+ id("com.facebook.react")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although using the plugins{} block is reccomended by Gradle, in this page we want to suggest a setup that is as close as possible the the existing template so by using the apply: syntax

Comment on lines +130 to +140
Those dependencies are available on `mavenCentral()` so make sure you have it defined in your `repositories{}` block in your `settings.gradle` file.

```diff
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral() // This is required, you'll probably have it already
}
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary IMHO

@@ -238,6 +230,8 @@ protected void onCreate(Bundle savedInstanceState) {

In the code above `Fragment reactNativeFragment = new ReactFragment.Builder()` creates the ReactFragment and `getSupportFragmentManager().beginTransaction().add()` adds the Fragment to the Frame Layout.

We have to implement the `DefaultHardwareBackBtnHandler` interface and override the `invokeDefaultOnBackPressed` method. This is necessary to allow react-native handle the back button press event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the crash? I don't think this is strictly necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants