From 7c169ec854acdc1a0ef3d998c5cfe98f589193da Mon Sep 17 00:00:00 2001 From: Alan Hughes Date: Thu, 24 Mar 2022 14:15:14 +0000 Subject: [PATCH 1/8] integration-with-android-fragment --- website/core/TabsConstants.js | 3 + .../integration-with-android-fragment.md | 173 +++++++++--------- 2 files changed, 91 insertions(+), 85 deletions(-) diff --git a/website/core/TabsConstants.js b/website/core/TabsConstants.js index 8aa29583a02..0aaf12d0760 100644 --- a/website/core/TabsConstants.js +++ b/website/core/TabsConstants.js @@ -23,7 +23,10 @@ const androidLanguages = [ {label: 'Java', value: 'java'}, {label: 'Kotlin', value: 'kotlin'}, ]; +<<<<<<< HEAD +======= +>>>>>>> integration-with-android-fragment const defaultAndroidLanguage = 'java'; const guides = [ diff --git a/website/versioned_docs/version-0.67/integration-with-android-fragment.md b/website/versioned_docs/version-0.67/integration-with-android-fragment.md index 0a5b9677dd0..3e6a5a1f560 100644 --- a/website/versioned_docs/version-0.67/integration-with-android-fragment.md +++ b/website/versioned_docs/version-0.67/integration-with-android-fragment.md @@ -39,28 +39,6 @@ public class MyReactApplication extends Application implements ReactApplication Override the required methods `getUseDeveloperSupport`, `getPackages` and `getReactNativeHost`: - - -```kotlin -class MyReactApplication : Application(), ReactApplication { - override fun onCreate() { - super.onCreate() - SoLoader.init(this, false) - } - private val reactNativeHost = - object : ReactNativeHost(this) { - override fun getUseDeveloperSupport() = BuildConfig.DEBUG - override fun getPackages(): List { - val packages = PackageList(this).getPackages().toMutableList() - // Packages that cannot be autolinked yet can be added manually here - return packages - } - } - override fun getReactNativeHost(): ReactNativeHost = reactNativeHost -} -``` - - ```java @@ -92,24 +70,34 @@ public class MyReactApplication extends Application implements ReactApplication ``` - - -If you are using Android Studio, use Alt + Enter to add all missing imports in your class. Alternatively these are the required imports to include manually: - - ```kotlin -import android.app.Application +class MyReactApplication: Application(), ReactApplication { -import com.facebook.react.PackageList -import com.facebook.react.ReactApplication -import com.facebook.react.ReactNativeHost -import com.facebook.react.ReactPackage -import com.facebook.soloader.SoLoader + override fun onCreate() { + super.onCreate() + SoLoader.init(this, false) + } + + private val reactNativeHost = object: ReactNativeHost(this) { + + override fun getUseDeveloperSupport() = BuildConfig.DEBUG + + override fun getPackages() = PackageList(this).getPackages() + } + + override fun getReactNativeHost() = reactNativeHost + +} ``` + + +If you are using Android Studio, use Alt + Enter to add all missing imports in your class. Alternatively these are the required imports to include manually: + + ```java @@ -124,6 +112,20 @@ import com.facebook.soloader.SoLoader; import java.util.List; ``` + + + +```kotlin +import android.app.Application + +import com.facebook.react.PackageList +import com.facebook.react.ReactApplication +import com.facebook.react.ReactNativeHost +import com.facebook.react.ReactPackage +import com.facebook.soloader.SoLoader + +``` + @@ -164,13 +166,6 @@ Now in your Activity class e.g. `MainActivity.java` you need to add an OnClickLi Add the button field to the top of your Activity: - - -```kotlin -private lateinit var button: Button -``` - - ```java @@ -178,34 +173,18 @@ private Button mButton; ``` - - -Update your Activity's onCreate method as follows: - - ```kotlin -override fun onCreate(savedInstanceState: Bundle) { - super.onCreate(savedInstanceState) - setContentView(R.layout.main_activity) - - button = findViewById