@preeternal/react-native-godot 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +22 -0
  2. package/Package.swift +106 -0
  3. package/README.md +631 -2
  4. package/android/build.gradle +289 -0
  5. package/android/consumer-rules.pro +19 -0
  6. package/android/fix-prefab.gradle +54 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/cpp/CMakeLists.txt +74 -0
  9. package/android/src/main/cpp/GodotModule.cpp +718 -0
  10. package/android/src/main/cpp/OnLoad.cpp +66 -0
  11. package/android/src/main/cpp/libgodot_android.h +79 -0
  12. package/android/src/main/cpp/libgodot_jni.cpp +585 -0
  13. package/android/src/main/cpp/libgodot_jni.h +130 -0
  14. package/android/src/main/cpp/native_godot_module_jni.cpp +86 -0
  15. package/android/src/main/cpp/native_godot_module_jni.h +58 -0
  16. package/android/src/main/java/com/preeternal/reactnativegodot/NativeGodotModuleModule.kt +83 -0
  17. package/android/src/main/java/com/preeternal/reactnativegodot/NativeGodotModulePackage.kt +41 -0
  18. package/android/src/main/java/com/preeternal/reactnativegodot/NativeLibraryLoader.kt +5 -0
  19. package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotView.kt +81 -0
  20. package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotViewManager.kt +34 -0
  21. package/android/src/main/java/com/preeternal/reactnativegodot/RTNLibGodot.kt +350 -0
  22. package/android/src/main/res/layout/downloading_expansion.xml +165 -0
  23. package/android/src/main/res/layout/godot_app_layout.xml +5 -0
  24. package/android/src/main/res/layout/snackbar.xml +27 -0
  25. package/android/src/main/res/layout/status_bar_ongoing_event_progress_bar.xml +108 -0
  26. package/android/src/main/res/mipmap/icon.png +0 -0
  27. package/android/src/main/res/mipmap/icon_background.png +0 -0
  28. package/android/src/main/res/mipmap/icon_foreground.png +0 -0
  29. package/android/src/main/res/mipmap/icon_monochrome.png +0 -0
  30. package/android/src/main/res/mipmap-anydpi-v26/icon.xml +8 -0
  31. package/android/src/main/res/mipmap-anydpi-v26/themed_icon.xml +11 -0
  32. package/android/src/main/res/mipmap-hdpi/icon.png +0 -0
  33. package/android/src/main/res/mipmap-hdpi/icon_background.png +0 -0
  34. package/android/src/main/res/mipmap-hdpi/icon_foreground.png +0 -0
  35. package/android/src/main/res/mipmap-hdpi/icon_monochrome.png +0 -0
  36. package/android/src/main/res/mipmap-mdpi/icon.png +0 -0
  37. package/android/src/main/res/mipmap-mdpi/icon_background.png +0 -0
  38. package/android/src/main/res/mipmap-mdpi/icon_foreground.png +0 -0
  39. package/android/src/main/res/mipmap-mdpi/icon_monochrome.png +0 -0
  40. package/android/src/main/res/mipmap-xhdpi/icon.png +0 -0
  41. package/android/src/main/res/mipmap-xhdpi/icon_background.png +0 -0
  42. package/android/src/main/res/mipmap-xhdpi/icon_foreground.png +0 -0
  43. package/android/src/main/res/mipmap-xhdpi/icon_monochrome.png +0 -0
  44. package/android/src/main/res/mipmap-xxhdpi/icon.png +0 -0
  45. package/android/src/main/res/mipmap-xxhdpi/icon_background.png +0 -0
  46. package/android/src/main/res/mipmap-xxhdpi/icon_foreground.png +0 -0
  47. package/android/src/main/res/mipmap-xxhdpi/icon_monochrome.png +0 -0
  48. package/android/src/main/res/mipmap-xxxhdpi/icon.png +0 -0
  49. package/android/src/main/res/mipmap-xxxhdpi/icon_background.png +0 -0
  50. package/android/src/main/res/mipmap-xxxhdpi/icon_foreground.png +0 -0
  51. package/android/src/main/res/mipmap-xxxhdpi/icon_monochrome.png +0 -0
  52. package/android/src/main/res/values/dimens.xml +9 -0
  53. package/android/src/main/res/values/strings.xml +61 -0
  54. package/android/src/main/res/values/styles.xml +25 -0
  55. package/android/src/main/res/values-fa/strings.xml +14 -0
  56. package/android/src/main/res/values-ko/strings.xml +54 -0
  57. package/android/src/main/res/xml/godot_provider_paths.xml +15 -0
  58. package/android/src/test/java/com/preeternal/reactnativegodot/NativeGodotModulePackageTest.kt +26 -0
  59. package/app.plugin.js +173 -0
  60. package/cpp/GodotModule.h +103 -0
  61. package/cpp/NativeGodotModule.cpp +825 -0
  62. package/cpp/NativeGodotModule.h +45 -0
  63. package/cpp/godot-log.h +64 -0
  64. package/ios/GodotModule.mm +661 -0
  65. package/ios/NativeGodotModuleProvider.h +35 -0
  66. package/ios/NativeGodotModuleProvider.mm +42 -0
  67. package/ios/RTNGodotView.h +42 -0
  68. package/ios/RTNGodotView.mm +711 -0
  69. package/ios/log.mm +38 -0
  70. package/lib/module/NativeNativeGodotModule.js +59 -0
  71. package/lib/module/NativeNativeGodotModule.js.map +1 -0
  72. package/lib/module/RTNGodotView.js +6 -0
  73. package/lib/module/RTNGodotView.js.map +1 -0
  74. package/lib/module/RTNGodotView.native.js +5 -0
  75. package/lib/module/RTNGodotView.native.js.map +1 -0
  76. package/lib/module/RTNGodotViewNativeComponent.ts +37 -0
  77. package/lib/module/index.js +30 -0
  78. package/lib/module/index.js.map +1 -0
  79. package/lib/module/package.json +1 -0
  80. package/lib/typescript/package.json +1 -0
  81. package/lib/typescript/src/NativeNativeGodotModule.d.ts +26 -0
  82. package/lib/typescript/src/NativeNativeGodotModule.d.ts.map +1 -0
  83. package/lib/typescript/src/RTNGodotView.d.ts +7 -0
  84. package/lib/typescript/src/RTNGodotView.d.ts.map +1 -0
  85. package/lib/typescript/src/RTNGodotView.native.d.ts +3 -0
  86. package/lib/typescript/src/RTNGodotView.native.d.ts.map +1 -0
  87. package/lib/typescript/src/RTNGodotViewNativeComponent.d.ts +11 -0
  88. package/lib/typescript/src/RTNGodotViewNativeComponent.d.ts.map +1 -0
  89. package/lib/typescript/src/index.d.ts +6 -0
  90. package/lib/typescript/src/index.d.ts.map +1 -0
  91. package/package.json +262 -4
  92. package/prebuilt-utils.rb +36 -0
  93. package/react-native-godot.podspec +41 -0
  94. package/react-native.config.js +15 -0
  95. package/scripts/check-16kb.sh +136 -0
  96. package/scripts/check-packaged-artifacts.sh +154 -0
  97. package/scripts/ci/verify-prebuilt-install.cjs +39 -0
  98. package/scripts/download-prebuilt.js +274 -0
  99. package/src/NativeNativeGodotModule.ts +90 -0
  100. package/src/RTNGodotView.native.tsx +2 -0
  101. package/src/RTNGodotView.tsx +12 -0
  102. package/src/RTNGodotViewNativeComponent.ts +37 -0
  103. package/src/index.tsx +28 -0
@@ -0,0 +1,130 @@
1
+ /**************************************************************************/
2
+ /* libgodot_jni.h */
3
+ /**************************************************************************/
4
+ /* Copyright (c) 2024-2025 Slay GmbH */
5
+ /* */
6
+ /* Permission is hereby granted, free of charge, to any person obtaining */
7
+ /* a copy of this software and associated documentation files (the */
8
+ /* "Software"), to deal in the Software without restriction, including */
9
+ /* without limitation the rights to use, copy, modify, merge, publish, */
10
+ /* distribute, sublicense, and/or sell copies of the Software, and to */
11
+ /* permit persons to whom the Software is furnished to do so, subject to */
12
+ /* the following conditions: */
13
+ /* */
14
+ /* The above copyright notice and this permission notice shall be */
15
+ /* included in all copies or substantial portions of the Software. */
16
+ /* */
17
+ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
18
+ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
19
+ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
20
+ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
21
+ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
22
+ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
23
+ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
24
+ /**************************************************************************/
25
+
26
+ #pragma once
27
+
28
+ #include <jni.h>
29
+ #include <godot_cpp/variant/string.hpp>
30
+ #include <string>
31
+
32
+ struct ANativeWindow;
33
+
34
+ class LibGodot {
35
+ static inline JavaVM *java_vm = nullptr;
36
+ static inline jobject asset_manager = nullptr;
37
+ static inline jobject net_utils = nullptr;
38
+ static inline jobject dir_access_handler = nullptr;
39
+ static inline jobject file_access_handler = nullptr;
40
+ static inline jobject godot_io = nullptr;
41
+ static inline jobject godot_engine = nullptr;
42
+ static inline jobject class_loader = nullptr;
43
+ static inline jobject host_activity = nullptr;
44
+
45
+ public:
46
+ static jobject get_asset_manager() {
47
+ return asset_manager;
48
+ }
49
+ static jobject get_net_utils() {
50
+ return net_utils;
51
+ }
52
+ static jobject get_dir_access_handler() {
53
+ return dir_access_handler;
54
+ }
55
+ static jobject get_file_access_handler() {
56
+ return file_access_handler;
57
+ }
58
+
59
+ static jobject get_godot_io() {
60
+ return godot_io;
61
+ }
62
+
63
+ static jobject get_godot_engine() {
64
+ return godot_engine;
65
+ }
66
+
67
+ static jobject get_host_activity() {
68
+ return host_activity;
69
+ }
70
+
71
+ static jobject get_class_loader() {
72
+ return class_loader;
73
+ }
74
+
75
+ static ANativeWindow *get_main_surface();
76
+
77
+ static int get_main_width();
78
+
79
+ static int get_main_height();
80
+
81
+ static JNIEnv *get_jni_env();
82
+
83
+ static void set_java_vm(JavaVM *vm);
84
+
85
+ static void initialize(JNIEnv *env, jobject p_asset_manager, jobject p_net_utils, jobject p_dir_access_handler, jobject p_file_access_handler, jobject p_godot_io, jobject p_main_surface, jint p_width, jint p_height, jobject p_godot_engine, jobject p_host_activity, jobject p_class_loader);
86
+
87
+ static void cleanup(JNIEnv *env);
88
+
89
+ static void updateWindowNative(JNIEnv *env, jstring p_name, jobject p_surface, jint p_width, jint p_height);
90
+
91
+ static void removeWindowNative(JNIEnv *env, jstring p_name);
92
+
93
+ static void updateWindow(std::string windowName);
94
+
95
+ static void updateWindows();
96
+
97
+ static void registerWindowUpdateCallbackNative(JNIEnv *env, jstring name, jlong handle, jobject r);
98
+
99
+ static void unregisterWindowUpdateCallbackNative(jlong handle);
100
+ };
101
+
102
+ static inline godot::String jstring_to_string(jstring source, JNIEnv *env = nullptr) {
103
+ godot::String result;
104
+ if (source) {
105
+ if (!env) {
106
+ env = LibGodot::get_jni_env();
107
+ }
108
+ const char *const source_utf8 = env->GetStringUTFChars(source, nullptr);
109
+ if (source_utf8) {
110
+ result.parse_utf8(source_utf8);
111
+ env->ReleaseStringUTFChars(source, source_utf8);
112
+ }
113
+ }
114
+ return result;
115
+ }
116
+
117
+ static inline std::string jstring_to_std_string(jstring source, JNIEnv *env = nullptr) {
118
+ std::string result;
119
+ if (source) {
120
+ if (!env) {
121
+ env = LibGodot::get_jni_env();
122
+ }
123
+ const char *const source_utf8 = env->GetStringUTFChars(source, nullptr);
124
+ if (source_utf8) {
125
+ result = source_utf8;
126
+ env->ReleaseStringUTFChars(source, source_utf8);
127
+ }
128
+ }
129
+ return result;
130
+ }
@@ -0,0 +1,86 @@
1
+ /**************************************************************************/
2
+ /* native_godot_module_jni.cpp */
3
+ /**************************************************************************/
4
+ /* Copyright (c) 2024-2025 Slay GmbH */
5
+ /* */
6
+ /* Permission is hereby granted, free of charge, to any person obtaining */
7
+ /* a copy of this software and associated documentation files (the */
8
+ /* "Software"), to deal in the Software without restriction, including */
9
+ /* without limitation the rights to use, copy, modify, merge, publish, */
10
+ /* distribute, sublicense, and/or sell copies of the Software, and to */
11
+ /* permit persons to whom the Software is furnished to do so, subject to */
12
+ /* the following conditions: */
13
+ /* */
14
+ /* The above copyright notice and this permission notice shall be */
15
+ /* included in all copies or substantial portions of the Software. */
16
+ /* */
17
+ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
18
+ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
19
+ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
20
+ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
21
+ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
22
+ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
23
+ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
24
+ /**************************************************************************/
25
+
26
+ #include "native_godot_module_jni.h"
27
+ #include <NativeGodotModule.h>
28
+ #include "GodotModule.h"
29
+
30
+ #define LOG_TAG "NativeGodotModuleJNI"
31
+ #include "godot-log.h"
32
+
33
+ jni::local_ref<NativeGodotModuleJNI::jhybriddata> NativeGodotModuleJNI::initHybrid(
34
+ jni::alias_ref<jhybridobject> jThis,
35
+ jlong jsContext,
36
+ jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>
37
+ jsCallInvokerHolder) {
38
+ auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
39
+ return makeCxxInstance(
40
+ jThis,
41
+ (jsi::Runtime *)jsContext,
42
+ jsCallInvoker);
43
+ }
44
+
45
+ void NativeGodotModuleJNI::registerNatives() {
46
+ registerHybrid({
47
+ makeNativeMethod("initHybrid", NativeGodotModuleJNI::initHybrid),
48
+ makeNativeMethod("installTurboModule", NativeGodotModuleJNI::installTurboModule),
49
+ makeNativeMethod("setHostActive", NativeGodotModuleJNI::setHostActive),
50
+ });
51
+ }
52
+
53
+ void NativeGodotModuleJNI::setHostActive(jboolean active) {
54
+ GodotModule *module = GodotModule::get_singleton();
55
+ if (active) {
56
+ module->appResume();
57
+ } else {
58
+ module->appPause();
59
+ }
60
+ }
61
+
62
+ bool NativeGodotModuleJNI::installTurboModule() {
63
+ // A zero JavaScript context must never be reported as a successful install:
64
+ // doing so leaves global.RTNGodot undefined and merely moves the crash to
65
+ // the first API call. Fail cleanly instead of dereferencing a null runtime.
66
+ if (rnRuntime_ == nullptr) {
67
+ LOGE("JavaScript runtime is unavailable; cannot install NativeGodotModule.");
68
+ return false;
69
+ }
70
+
71
+ jsi::Runtime &rnRuntime = *rnRuntime_;
72
+ jsi::Value godotModule = createNativeGodotModule(rnRuntime, callInvoker_);
73
+ if (!godotModule.isObject()) {
74
+ LOGE("Could not install NativeGodotModule.");
75
+ return false;
76
+ }
77
+ return true;
78
+ }
79
+
80
+ NativeGodotModuleJNI::NativeGodotModuleJNI(
81
+ jni::alias_ref<NativeGodotModuleJNI::jhybridobject> jThis,
82
+ jsi::Runtime *rnRuntime,
83
+ const std::shared_ptr<facebook::react::CallInvoker> &jsCallInvoker) :
84
+ javaPart_(jni::make_global(jThis)),
85
+ rnRuntime_(rnRuntime),
86
+ callInvoker_(jsCallInvoker) {}
@@ -0,0 +1,58 @@
1
+ /**************************************************************************/
2
+ /* native_godot_module_jni.h */
3
+ /**************************************************************************/
4
+ /* Copyright (c) 2024-2025 Slay GmbH */
5
+ /* */
6
+ /* Permission is hereby granted, free of charge, to any person obtaining */
7
+ /* a copy of this software and associated documentation files (the */
8
+ /* "Software"), to deal in the Software without restriction, including */
9
+ /* without limitation the rights to use, copy, modify, merge, publish, */
10
+ /* distribute, sublicense, and/or sell copies of the Software, and to */
11
+ /* permit persons to whom the Software is furnished to do so, subject to */
12
+ /* the following conditions: */
13
+ /* */
14
+ /* The above copyright notice and this permission notice shall be */
15
+ /* included in all copies or substantial portions of the Software. */
16
+ /* */
17
+ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
18
+ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
19
+ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
20
+ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
21
+ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
22
+ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
23
+ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
24
+ /**************************************************************************/
25
+
26
+ #include <ReactCommon/CallInvokerHolder.h>
27
+ #include <fbjni/fbjni.h>
28
+ #include <jsi/jsi.h>
29
+
30
+ using namespace facebook;
31
+
32
+ class NativeGodotModuleJNI : public jni::HybridClass<NativeGodotModuleJNI> {
33
+ public:
34
+ static auto constexpr kJavaDescriptor =
35
+ "Lcom/preeternal/reactnativegodot/NativeGodotModuleModule;";
36
+ static jni::local_ref<jhybriddata> initHybrid(
37
+ jni::alias_ref<jhybridobject> jThis,
38
+ jlong jsContext,
39
+ jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>
40
+ jsCallInvokerHolder);
41
+
42
+ static void registerNatives();
43
+
44
+ ~NativeGodotModuleJNI() {}
45
+
46
+ private:
47
+ friend HybridBase;
48
+ jni::global_ref<NativeGodotModuleJNI::javaobject> javaPart_;
49
+ jsi::Runtime *rnRuntime_;
50
+ std::shared_ptr<facebook::react::CallInvoker> callInvoker_;
51
+ bool installTurboModule();
52
+ void setHostActive(jboolean active);
53
+
54
+ explicit NativeGodotModuleJNI(
55
+ jni::alias_ref<NativeGodotModuleJNI::jhybridobject> jThis,
56
+ jsi::Runtime *rnRuntime,
57
+ const std::shared_ptr<facebook::react::CallInvoker> &jsCallInvoker);
58
+ };
@@ -0,0 +1,83 @@
1
+ package com.preeternal.reactnativegodot
2
+
3
+ import com.facebook.jni.HybridData
4
+ import com.facebook.proguard.annotations.DoNotStrip
5
+ import com.facebook.react.bridge.LifecycleEventListener
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.bridge.ReactMethod
8
+ import com.facebook.react.bridge.UiThreadUtil
9
+ import com.facebook.react.common.LifecycleState
10
+ import com.facebook.react.common.annotations.FrameworkAPI
11
+ import com.facebook.react.module.annotations.ReactModule
12
+ import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
13
+ import kotlin.OptIn
14
+
15
+ @OptIn(FrameworkAPI::class)
16
+ @ReactModule(name = NativeGodotModuleModule.NAME)
17
+ class NativeGodotModuleModule(
18
+ reactContext: ReactApplicationContext,
19
+ ) : NativeNativeGodotModuleSpec(reactContext), LifecycleEventListener {
20
+ @DoNotStrip
21
+ @Suppress("unused")
22
+ private val mHybridData: HybridData
23
+ private var invalidated = false
24
+
25
+ init {
26
+ RTNLibGodot.getInstance().init(reactContext.currentActivity)
27
+
28
+ val callInvokerHolder = requireNotNull(reactContext.jsCallInvokerHolder) {
29
+ "The JavaScript call invoker is not available"
30
+ }
31
+ require(callInvokerHolder is CallInvokerHolderImpl) {
32
+ "Unsupported JavaScript call invoker implementation: ${callInvokerHolder::class.java.name}"
33
+ }
34
+
35
+ mHybridData = initHybrid(
36
+ requireNotNull(reactContext.javaScriptContextHolder).get(),
37
+ callInvokerHolder,
38
+ )
39
+ }
40
+
41
+ override fun initialize() {
42
+ super.initialize()
43
+ val context = reactApplicationContext
44
+ UiThreadUtil.runOnUiThread {
45
+ if (invalidated) return@runOnUiThread
46
+ setHostActive(context.lifecycleState == LifecycleState.RESUMED)
47
+ context.addLifecycleEventListener(this)
48
+ }
49
+ }
50
+
51
+ override fun invalidate() {
52
+ invalidated = true
53
+ UiThreadUtil.runOnUiThread {
54
+ reactApplicationContext.removeLifecycleEventListener(this)
55
+ setHostActive(false)
56
+ }
57
+ super.invalidate()
58
+ }
59
+
60
+ override fun onHostResume() {
61
+ if (!invalidated) setHostActive(true)
62
+ }
63
+
64
+ override fun onHostPause() {
65
+ if (!invalidated) setHostActive(false)
66
+ }
67
+
68
+ override fun onHostDestroy() = onHostPause()
69
+
70
+ private external fun setHostActive(active: Boolean)
71
+
72
+ private external fun initHybrid(
73
+ jsContext: Long,
74
+ jsCallInvokerHolder: CallInvokerHolderImpl,
75
+ ): HybridData
76
+
77
+ @ReactMethod(isBlockingSynchronousMethod = true)
78
+ override external fun installTurboModule(): Boolean
79
+
80
+ companion object {
81
+ const val NAME = NativeNativeGodotModuleSpec.NAME
82
+ }
83
+ }
@@ -0,0 +1,41 @@
1
+ package com.preeternal.reactnativegodot
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import com.facebook.react.uimanager.ViewManager
9
+
10
+ class NativeGodotModulePackage : BaseReactPackage() {
11
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
12
+ listOf(RTNGodotViewManager())
13
+
14
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? =
15
+ if (name == NativeGodotModuleModule.NAME) {
16
+ NativeGodotModuleModule(reactContext)
17
+ } else {
18
+ null
19
+ }
20
+
21
+ override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
22
+ mapOf(
23
+ NativeGodotModuleModule.NAME to ReactModuleInfo(
24
+ name = NativeGodotModuleModule.NAME,
25
+ className = NativeGodotModuleModule.NAME,
26
+ canOverrideExistingModule = false,
27
+ needsEagerInit = false,
28
+ isCxxModule = false,
29
+ isTurboModule = true,
30
+ ),
31
+ )
32
+ }
33
+
34
+ companion object {
35
+ init {
36
+ // Match the Java integration: load native dependencies when RN creates
37
+ // the package, before JavaScript requests the TurboModule.
38
+ NativeLibraryLoader.load("rtngodot")
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,5 @@
1
+ package com.preeternal.reactnativegodot
2
+
3
+ internal object NativeLibraryLoader {
4
+ var load: (String) -> Unit = System::loadLibrary
5
+ }
@@ -0,0 +1,81 @@
1
+ package com.preeternal.reactnativegodot
2
+
3
+ import android.annotation.SuppressLint
4
+ import android.content.Context
5
+ import android.util.Log
6
+ import android.view.MotionEvent
7
+ import android.view.SurfaceHolder
8
+ import android.view.SurfaceView
9
+ import android.view.ViewGroup
10
+ import org.godotengine.godot.input.GodotInputHandler
11
+
12
+ class RTNGodotView(context: Context) : SurfaceView(context), SurfaceHolder.Callback2 {
13
+ private val inputHandler: GodotInputHandler? = RTNLibGodot.getInstance().inputHandler
14
+ private var windowName = ""
15
+
16
+ init {
17
+ layoutParams = ViewGroup.LayoutParams(
18
+ ViewGroup.LayoutParams.MATCH_PARENT,
19
+ ViewGroup.LayoutParams.MATCH_PARENT,
20
+ )
21
+ holder.addCallback(this)
22
+ }
23
+
24
+ fun setWindowName(newWindowName: String?) {
25
+ windowName = newWindowName ?: ""
26
+ }
27
+
28
+ override fun surfaceRedrawNeeded(surfaceHolder: SurfaceHolder) {
29
+ Log.i(TAG, "surfaceRedrawNeeded: $windowName ${surfaceHolder.surface}")
30
+ }
31
+
32
+ override fun surfaceCreated(surfaceHolder: SurfaceHolder) {
33
+ Log.i(TAG, "surfaceCreated: $windowName ${surfaceHolder.surface}")
34
+ }
35
+
36
+ override fun surfaceChanged(
37
+ surfaceHolder: SurfaceHolder,
38
+ format: Int,
39
+ width: Int,
40
+ height: Int,
41
+ ) {
42
+ Log.i(TAG, "surfaceChanged: $windowName ${surfaceHolder.surface} $format $width $height")
43
+ RTNLibGodot.getInstance().updateWindow(windowName, surfaceControl, surfaceHolder, format, width, height)
44
+ }
45
+
46
+ override fun surfaceDestroyed(surfaceHolder: SurfaceHolder) {
47
+ Log.i(TAG, "surfaceRemoved: $windowName ${surfaceHolder.surface}")
48
+ RTNLibGodot.getInstance().removeWindow(windowName)
49
+ }
50
+
51
+ @SuppressLint("ClickableViewAccessibility")
52
+ override fun onTouchEvent(event: MotionEvent): Boolean {
53
+ super.onTouchEvent(event)
54
+ return inputHandler?.onTouchEvent(event) ?: false
55
+ }
56
+
57
+ override fun onGenericMotionEvent(event: MotionEvent): Boolean =
58
+ inputHandler?.onGenericMotionEvent(event) ?: false
59
+
60
+ override fun onCapturedPointerEvent(event: MotionEvent): Boolean =
61
+ inputHandler?.onGenericMotionEvent(event) ?: false
62
+
63
+ override fun requestPointerCapture() {
64
+ super.requestPointerCapture()
65
+ inputHandler?.onPointerCaptureChange(true)
66
+ }
67
+
68
+ override fun releasePointerCapture() {
69
+ super.releasePointerCapture()
70
+ inputHandler?.onPointerCaptureChange(false)
71
+ }
72
+
73
+ override fun onPointerCaptureChange(hasCapture: Boolean) {
74
+ super.onPointerCaptureChange(hasCapture)
75
+ inputHandler?.onPointerCaptureChange(hasCapture)
76
+ }
77
+
78
+ companion object {
79
+ private const val TAG = "RTNGodotView"
80
+ }
81
+ }
@@ -0,0 +1,34 @@
1
+ package com.preeternal.reactnativegodot
2
+
3
+ import com.facebook.react.module.annotations.ReactModule
4
+ import com.facebook.react.uimanager.SimpleViewManager
5
+ import com.facebook.react.uimanager.ThemedReactContext
6
+ import com.facebook.react.uimanager.ViewManagerDelegate
7
+ import com.facebook.react.uimanager.annotations.ReactProp
8
+ import com.facebook.react.viewmanagers.RTNGodotViewManagerDelegate
9
+ import com.facebook.react.viewmanagers.RTNGodotViewManagerInterface
10
+
11
+ @ReactModule(name = RTNGodotViewManager.NAME)
12
+ class RTNGodotViewManager : SimpleViewManager<RTNGodotView>(),
13
+ RTNGodotViewManagerInterface<RTNGodotView> {
14
+ private val delegate: ViewManagerDelegate<RTNGodotView> =
15
+ RTNGodotViewManagerDelegate(this)
16
+
17
+ override fun getDelegate(): ViewManagerDelegate<RTNGodotView> = delegate
18
+
19
+ override fun getName(): String = NAME
20
+
21
+ override fun createViewInstance(context: ThemedReactContext): RTNGodotView {
22
+ RTNLibGodot.getInstance().init(context.currentActivity)
23
+ return RTNGodotView(context)
24
+ }
25
+
26
+ @ReactProp(name = "windowName")
27
+ override fun setWindowName(view: RTNGodotView?, value: String?) {
28
+ view?.setWindowName(value)
29
+ }
30
+
31
+ companion object {
32
+ const val NAME = "RTNGodotView"
33
+ }
34
+ }