forked from jhugman/uniffi-bindgen-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create-react-native-library@latest: Modify turbo-modules generation (j…
…hugman#131) Fixes jhugman#107 Now working with `[email protected]` This adds kotlin detection and uses Kotlin if needed, or stays with Java: this adds two Kotlin files and an alternative `build.gradle` file. It also adds more checks to the test-turbo-modules.sh script, tightening up podspec and Objective C files. Finally we add documentation to getting-started.md and contributing-turbo-modules.md.
- Loading branch information
Showing
11 changed files
with
489 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{%- let android = self.config.project.android.clone() %} | ||
{%- let name = self.config.project.module_cpp() %} | ||
{%- let module_class_name = name|fmt("{}Module") -%} | ||
// Generated by uniffi-bindgen-react-native | ||
package {{ android.package_name() }} | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.annotations.ReactModule | ||
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder | ||
|
||
@ReactModule(name = {{ module_class_name }}.NAME) | ||
class {{ module_class_name }}(reactContext: ReactApplicationContext) : | ||
{{ self.config.project.codegen_filename() }}Spec(reactContext) { | ||
|
||
override fun getName(): String { | ||
return NAME | ||
} | ||
|
||
// Two native methods implemented in cpp-adapter.cpp, and ultimately | ||
// {{ self.config.project.cpp_filename() }}.cpp | ||
|
||
external fun nativeInstallRustCrate(runtimePointer: Long, callInvoker: CallInvokerHolder): Boolean | ||
external fun nativeCleanupRustCrate(runtimePointer: Long): Boolean | ||
|
||
override fun installRustCrate(): Boolean { | ||
val context = this.reactApplicationContext | ||
return nativeInstallRustCrate( | ||
context.javaScriptContextHolder!!.get(), | ||
context.jsCallInvokerHolder!! | ||
) | ||
} | ||
|
||
override fun cleanupRustCrate(): Boolean { | ||
return nativeCleanupRustCrate( | ||
this.reactApplicationContext.javaScriptContextHolder!!.get() | ||
) | ||
} | ||
|
||
companion object { | ||
const val NAME = "{{ name }}" | ||
|
||
init { | ||
System.loadLibrary("{{ self.config.project.cpp_filename() }}") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{%- let name = self.config.project.module_cpp() %} | ||
{%- let package_class_name = name|fmt("{}Package") %} | ||
{%- let module_class_name = name|fmt("{}Module") -%} | ||
// Generated by uniffi-bindgen-react-native | ||
package {{ self.config.project.android.package_name() }} | ||
|
||
import com.facebook.react.TurboReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.model.ReactModuleInfo | ||
import com.facebook.react.module.model.ReactModuleInfoProvider | ||
import java.util.HashMap | ||
|
||
class {{ package_class_name }} : TurboReactPackage() { | ||
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { | ||
return if (name == {{ module_class_name }}.NAME) { | ||
{{ module_class_name }}(reactContext) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { | ||
return ReactModuleInfoProvider { | ||
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap() | ||
moduleInfos[{{ module_class_name }}.NAME] = ReactModuleInfo( | ||
{{ module_class_name }}.NAME, | ||
{{ module_class_name }}.NAME, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
false, // isCxxModule | ||
true // isTurboModule | ||
) | ||
moduleInfos | ||
} | ||
} | ||
} |
Oops, something went wrong.