Skip to content

Commit

Permalink
android new arch
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Trocki committed Jan 31, 2024
1 parent 84571c1 commit 4f04d38
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
8 changes: 6 additions & 2 deletions packages/repack/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def isNewArchitectureEnabled() {
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['RePack_' + name]
}
Expand All @@ -33,11 +37,11 @@ android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
buildToolsVersion getExtOrDefault('buildToolsVersion')
defaultConfig {
minSdkVersion 16
minSdkVersion 21
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
versionCode 1
versionName "1.0"

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ScriptManagerModule(reactContext: ReactApplicationContext) : ScriptManager
FileSystemScriptLoader(reactApplicationContext)

override fun getName(): String {
return "ScriptManager"
return NAME
}

private fun runInBackground(fn: () -> Unit) {
Expand Down Expand Up @@ -97,4 +97,8 @@ class ScriptManagerModule(reactContext: ReactApplicationContext) : ScriptManager
}
}
}

companion object {
const val NAME = "ScriptManager"
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
package com.callstack.repack

import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.TurboReactPackage
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager

import com.facebook.react.bridge.NativeModule
import com.facebook.react.module.model.ReactModuleInfoProvider
import com.facebook.react.module.model.ReactModuleInfo
import java.util.HashMap

class ScriptManagerPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
return listOf(ScriptManagerModule(reactContext))
class ScriptManagerPackage : TurboReactPackage() {
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
return if (name == ScriptManagerModule.NAME) {
ScriptManagerModule(reactContext)
} else {
null
}
}

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
return emptyList()
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
return ReactModuleInfoProvider {
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
moduleInfos[ScriptManagerModule.NAME] = ReactModuleInfo(
ScriptManagerModule.NAME,
ScriptManagerModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
)
moduleInfos
}
}
}
4 changes: 2 additions & 2 deletions packages/repack/android/src/newarch/ScriptManagerSpec.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.callstack.repack

import com.facebook.fbreact.specs.NativeScriptManagerSpec
import com.facebook.react.bridge.ReactApplicationContext

abstract class ScriptManagerSpec internal constructor(context: ReactApplicationContext) :
NativeRepackSpec(context) {
abstract class ScriptManagerSpec internal constructor(context: ReactApplicationContext): NativeScriptManagerSpec(context) {
}

0 comments on commit 4f04d38

Please sign in to comment.