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

fix(android): fix Fabric cannot be enabled on 0.72 #1389

Merged
merged 2 commits into from
Apr 13, 2023
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
14 changes: 11 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -311,27 +311,35 @@ android {
debug.java.srcDirs += "src/flipper/java"
}

// TODO: Remove this block when we drop support for 0.67.
// TODO: Remove this block when we drop support for 0.67
if (project.ext.react.enableFabric) {
main.java.srcDirs += "src/fabric/java"
} else {
main.java.srcDirs += "src/no-fabric/java"
}

// TODO: Remove this block when we drop support for 0.65.
// TODO: Remove this block when we drop support for 0.65
if (enableNewArchitecture) {
main.java.srcDirs += "src/turbomodule/java"
} else {
main.java.srcDirs += "src/no-turbomodule/java"
}

// TODO: Remove this block when we drop support for 0.67.
// TODO: Remove this block when we drop support for 0.67
// https://github.com/facebook/react-native/commit/ce74aa4ed335d4c36ce722d47937b582045e05c4
if (reactNativeVersion > 0 && reactNativeVersion < 6800) {
main.java.srcDirs += "src/reactinstanceeventlistener-pre-0.68/java"
} else {
main.java.srcDirs += "src/reactinstanceeventlistener-0.68/java"
}

// TODO: Remove this block when we drop support for 0.72
// https://github.com/facebook/react-native/commit/e5dd9cdc6688e63e75a7e0bebf380be1a9a5fe2b
if (reactNativeVersion > 0 && reactNativeVersion < 7200) {
main.java.srcDirs += "src/reactactivitydelegate-pre-0.72/java"
} else {
main.java.srcDirs += "src/reactactivitydelegate-0.72/java"
}
}

splits {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,14 @@ import android.view.MenuItem
import androidx.fragment.app.Fragment
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.ReactRootView
import com.microsoft.reacttestapp.BuildConfig

class ComponentActivity : ReactActivity() {

private inner class ComponentActivityDelegate(
activity: ReactActivity,
mainComponentName: String?
) : ReactActivityDelegate(activity, mainComponentName) {
override fun getLaunchOptions(): Bundle? {
return intent.extras?.getBundle(COMPONENT_INITIAL_PROPERTIES)
}

override fun createRootView(): ReactRootView {
val rootView = super.createRootView()
rootView.setIsFabric(BuildConfig.ReactTestApp_useFabric)
return rootView
}
}

companion object {
private const val COMPONENT_NAME = "extra:componentName"
private const val COMPONENT_DISPLAY_NAME = "extra:componentDisplayName"
private const val COMPONENT_INITIAL_PROPERTIES = "extra:componentInitialProperties"
const val COMPONENT_INITIAL_PROPERTIES = "extra:componentInitialProperties"

fun newIntent(activity: Activity, component: ComponentViewModel): Intent {
return Intent(activity, ComponentActivity::class.java).apply {
Expand All @@ -44,6 +28,8 @@ class ComponentActivity : ReactActivity() {
}
}

// ReactActivity overrides

override fun createReactActivityDelegate(): ReactActivityDelegate {
return ComponentActivityDelegate(this, mainComponentName)
}
Expand Down Expand Up @@ -74,13 +60,7 @@ class ComponentActivity : ReactActivity() {
} ?: loadApp(componentName)
}

private fun findClass(name: String): Class<*>? {
return try {
Class.forName(name)
} catch (e: ClassNotFoundException) {
null
}
}
// Activity overrides

override fun getSystemService(name: String): Any? {
if (name == "service:reactNativeHostService") {
Expand All @@ -99,4 +79,14 @@ class ComponentActivity : ReactActivity() {

return super.onOptionsItemSelected(item)
}

// Private

private fun findClass(name: String): Class<*>? {
return try {
Class.forName(name)
} catch (e: ClassNotFoundException) {
null
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.microsoft.reacttestapp.component

import android.os.Bundle
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.ReactRootView
import com.microsoft.reacttestapp.BuildConfig

class ComponentActivityDelegate(
activity: ReactActivity,
mainComponentName: String?
) : ReactActivityDelegate(activity, mainComponentName) {
override fun getLaunchOptions(): Bundle? {
return plainActivity.intent.extras?.getBundle(
ComponentActivity.COMPONENT_INITIAL_PROPERTIES
)
}

override fun createRootView(): ReactRootView {
val rootView = super.createRootView()
rootView.setIsFabric(BuildConfig.ReactTestApp_useFabric)
return rootView
}

override fun createRootView(bundle: Bundle?): ReactRootView {
val rootView = super.createRootView(bundle)
rootView.setIsFabric(BuildConfig.ReactTestApp_useFabric)
return rootView
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.microsoft.reacttestapp.component

import android.os.Bundle
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.ReactRootView
import com.microsoft.reacttestapp.BuildConfig

class ComponentActivityDelegate(
activity: ReactActivity,
mainComponentName: String?
) : ReactActivityDelegate(activity, mainComponentName) {
override fun getLaunchOptions(): Bundle? {
return plainActivity.intent.extras?.getBundle(
ComponentActivity.COMPONENT_INITIAL_PROPERTIES
)
}

override fun createRootView(): ReactRootView {
val rootView = super.createRootView()
rootView.setIsFabric(BuildConfig.ReactTestApp_useFabric)
return rootView
}
}
2 changes: 2 additions & 0 deletions test/pack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ describe("npm pack", () => {
"android/app/src/no-fabric/java/com/microsoft/reacttestapp/fabric/FabricJSIModulePackage.kt",
"android/app/src/no-turbomodule/java/com/microsoft/reacttestapp/compat/ReactNativeHostCompat.kt",
"android/app/src/no-turbomodule/java/com/microsoft/reacttestapp/fabric/ComponentsRegistry.kt",
"android/app/src/reactactivitydelegate-0.72/java/com/microsoft/reacttestapp/component/ComponentActivityDelegate.kt",
"android/app/src/reactactivitydelegate-pre-0.72/java/com/microsoft/reacttestapp/component/ComponentActivityDelegate.kt",
"android/app/src/reactinstanceeventlistener-0.68/java/com/microsoft/reacttestapp/compat/ReactInstanceEventListener.kt",
"android/app/src/reactinstanceeventlistener-pre-0.68/java/com/microsoft/reacttestapp/compat/ReactInstanceEventListener.kt",
"android/app/src/turbomodule/java/com/microsoft/reacttestapp/compat/ReactNativeHostCompat.kt",
Expand Down