@preeternal/react-native-godot 0.0.0-stage → 0.2.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 (109) hide show
  1. package/LICENSE +22 -0
  2. package/Package.swift +106 -0
  3. package/README.md +590 -2
  4. package/android/build.gradle +291 -0
  5. package/android/consumer-rules.pro +20 -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 +78 -0
  9. package/android/src/main/cpp/GodotModule.cpp +764 -0
  10. package/android/src/main/cpp/OnLoad.cpp +66 -0
  11. package/android/src/main/cpp/libgodot_android.h +73 -0
  12. package/android/src/main/cpp/libgodot_jni.cpp +658 -0
  13. package/android/src/main/cpp/libgodot_jni.h +116 -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/RTNGodotIO.kt +123 -0
  20. package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotView.kt +92 -0
  21. package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotViewManager.kt +34 -0
  22. package/android/src/main/java/com/preeternal/reactnativegodot/RTNLibGodot.kt +215 -0
  23. package/android/src/main/res/layout/downloading_expansion.xml +165 -0
  24. package/android/src/main/res/layout/godot_app_layout.xml +5 -0
  25. package/android/src/main/res/layout/snackbar.xml +27 -0
  26. package/android/src/main/res/layout/status_bar_ongoing_event_progress_bar.xml +108 -0
  27. package/android/src/main/res/mipmap/icon.png +0 -0
  28. package/android/src/main/res/mipmap/icon_background.png +0 -0
  29. package/android/src/main/res/mipmap/icon_foreground.png +0 -0
  30. package/android/src/main/res/mipmap/icon_monochrome.png +0 -0
  31. package/android/src/main/res/mipmap-anydpi-v26/icon.xml +8 -0
  32. package/android/src/main/res/mipmap-anydpi-v26/themed_icon.xml +11 -0
  33. package/android/src/main/res/mipmap-hdpi/icon.png +0 -0
  34. package/android/src/main/res/mipmap-hdpi/icon_background.png +0 -0
  35. package/android/src/main/res/mipmap-hdpi/icon_foreground.png +0 -0
  36. package/android/src/main/res/mipmap-hdpi/icon_monochrome.png +0 -0
  37. package/android/src/main/res/mipmap-mdpi/icon.png +0 -0
  38. package/android/src/main/res/mipmap-mdpi/icon_background.png +0 -0
  39. package/android/src/main/res/mipmap-mdpi/icon_foreground.png +0 -0
  40. package/android/src/main/res/mipmap-mdpi/icon_monochrome.png +0 -0
  41. package/android/src/main/res/mipmap-xhdpi/icon.png +0 -0
  42. package/android/src/main/res/mipmap-xhdpi/icon_background.png +0 -0
  43. package/android/src/main/res/mipmap-xhdpi/icon_foreground.png +0 -0
  44. package/android/src/main/res/mipmap-xhdpi/icon_monochrome.png +0 -0
  45. package/android/src/main/res/mipmap-xxhdpi/icon.png +0 -0
  46. package/android/src/main/res/mipmap-xxhdpi/icon_background.png +0 -0
  47. package/android/src/main/res/mipmap-xxhdpi/icon_foreground.png +0 -0
  48. package/android/src/main/res/mipmap-xxhdpi/icon_monochrome.png +0 -0
  49. package/android/src/main/res/mipmap-xxxhdpi/icon.png +0 -0
  50. package/android/src/main/res/mipmap-xxxhdpi/icon_background.png +0 -0
  51. package/android/src/main/res/mipmap-xxxhdpi/icon_foreground.png +0 -0
  52. package/android/src/main/res/mipmap-xxxhdpi/icon_monochrome.png +0 -0
  53. package/android/src/main/res/values/dimens.xml +9 -0
  54. package/android/src/main/res/values/strings.xml +61 -0
  55. package/android/src/main/res/values/styles.xml +25 -0
  56. package/android/src/main/res/values-fa/strings.xml +14 -0
  57. package/android/src/main/res/values-ko/strings.xml +54 -0
  58. package/android/src/main/res/xml/godot_provider_paths.xml +15 -0
  59. package/android/src/test/java/com/preeternal/reactnativegodot/NativeGodotModulePackageTest.kt +26 -0
  60. package/app.plugin.js +169 -0
  61. package/cpp/AppleRendererPolicy.h +95 -0
  62. package/cpp/GodotModule.h +126 -0
  63. package/cpp/LibGodotABI.h +52 -0
  64. package/cpp/NativeGodotModule.cpp +825 -0
  65. package/cpp/NativeGodotModule.h +45 -0
  66. package/cpp/godot-log.h +64 -0
  67. package/ios/GodotModule.mm +695 -0
  68. package/ios/NativeGodotModuleProvider.h +35 -0
  69. package/ios/NativeGodotModuleProvider.mm +42 -0
  70. package/ios/RTNGodotView.h +42 -0
  71. package/ios/RTNGodotView.mm +671 -0
  72. package/ios/log.mm +38 -0
  73. package/lib/module/NativeNativeGodotModule.js +59 -0
  74. package/lib/module/NativeNativeGodotModule.js.map +1 -0
  75. package/lib/module/RTNGodotView.js +6 -0
  76. package/lib/module/RTNGodotView.js.map +1 -0
  77. package/lib/module/RTNGodotView.native.js +5 -0
  78. package/lib/module/RTNGodotView.native.js.map +1 -0
  79. package/lib/module/RTNGodotViewNativeComponent.ts +37 -0
  80. package/lib/module/index.js +30 -0
  81. package/lib/module/index.js.map +1 -0
  82. package/lib/module/package.json +1 -0
  83. package/lib/typescript/package.json +1 -0
  84. package/lib/typescript/src/NativeNativeGodotModule.d.ts +26 -0
  85. package/lib/typescript/src/NativeNativeGodotModule.d.ts.map +1 -0
  86. package/lib/typescript/src/RTNGodotView.d.ts +7 -0
  87. package/lib/typescript/src/RTNGodotView.d.ts.map +1 -0
  88. package/lib/typescript/src/RTNGodotView.native.d.ts +3 -0
  89. package/lib/typescript/src/RTNGodotView.native.d.ts.map +1 -0
  90. package/lib/typescript/src/RTNGodotViewNativeComponent.d.ts +11 -0
  91. package/lib/typescript/src/RTNGodotViewNativeComponent.d.ts.map +1 -0
  92. package/lib/typescript/src/index.d.ts +6 -0
  93. package/lib/typescript/src/index.d.ts.map +1 -0
  94. package/package.json +282 -4
  95. package/prebuilt-utils.rb +46 -0
  96. package/react-native-godot.podspec +41 -0
  97. package/react-native.config.js +16 -0
  98. package/scripts/check-16kb.sh +136 -0
  99. package/scripts/check-packaged-artifacts.sh +156 -0
  100. package/scripts/ci/verify-ios-simulator.py +48 -0
  101. package/scripts/ci/verify-prebuilt-install.cjs +41 -0
  102. package/scripts/download-prebuilt.js +283 -0
  103. package/scripts/prebuilt-config.js +80 -0
  104. package/scripts/spm-autolinking-plugin.js +87 -0
  105. package/src/NativeNativeGodotModule.ts +90 -0
  106. package/src/RTNGodotView.native.tsx +2 -0
  107. package/src/RTNGodotView.tsx +12 -0
  108. package/src/RTNGodotViewNativeComponent.ts +37 -0
  109. package/src/index.tsx +28 -0
package/README.md CHANGED
@@ -1,3 +1,591 @@
1
- # Temporary Holding Version
1
+ # @preeternal/react-native-godot
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/@preeternal/react-native-godot.svg)](https://www.npmjs.com/package/@preeternal/react-native-godot)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@preeternal/react-native-godot.svg)](https://www.npmjs.com/package/@preeternal/react-native-godot)
5
+ [![Patreon](https://img.shields.io/endpoint?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%2F%3Fusername%3Dpreeternal%26type%3Dpatrons)](https://www.patreon.com/preeternal)
6
+
7
+ Bring interactive Godot scenes into your React Native app on Android and iOS.
8
+ Build animated 3D previews, product viewers, interactive diagrams or small games
9
+ alongside your existing screens and navigation.
10
+
11
+ Author scenes and animations in Godot, then control them from TypeScript or
12
+ JavaScript. React Native handles the app UI; Godot renders inside a native view.
13
+
14
+ ## Features
15
+
16
+ - Embed the main Godot window and named subwindows in React Native screens.
17
+ - Start, stop and restart the engine with different Godot projects.
18
+ - Pause and resume a running instance.
19
+ - Access Godot objects, methods, properties, signals and Callables from JavaScript.
20
+ - Run Godot and its JavaScript worklets on a dedicated thread.
21
+ - Choose OpenGL Compatibility, Metal on iOS devices, or Vulkan on Android.
22
+ - Use audio playback by default and opt into microphone capture when needed.
23
+
24
+ ## Versions
25
+
26
+ | Library release | Godot version | Source branch |
27
+ | ------------------------------ | ------------- | ------------------------------------------------------------------------------ |
28
+ | `0.1.0` — previous release | 4.5.1 | [`godot-4.5`](https://github.com/Preeternal/react-native-godot/tree/godot-4.5) |
29
+ | `0.2.0` — this README | 4.7.2 | [`godot-4.7`](https://github.com/Preeternal/react-native-godot/tree/godot-4.7) |
30
+
31
+ The 4.7 line is the current development focus. The `godot-4.5` branch is kept
32
+ for possible fixes to the previous line; backports are considered as needed.
33
+
34
+ ## Compatibility
35
+
36
+ | Requirement | Supported configuration |
37
+ | ------------ | ------------------------------------------------------------------- |
38
+ | React Native | New Architecture |
39
+ | Worklets | Version satisfying this package's [peer dependencies](package.json) |
40
+ | iOS | 15.0 or newer |
41
+ | Android | Android 10 / API 29 or newer; `arm64-v8a` and `armeabi-v7a` |
42
+ | Expo | Development Builds; Expo Go cannot load this native module |
43
+
44
+ The library includes a pinned engine; you do not need to build Godot yourself.
45
+ This branch uses
46
+ [LibGodot `4.7.2.preeternal.2`](https://github.com/Preeternal/libgodot/releases/tag/4.7.2.preeternal.2),
47
+ based on Godot 4.7.2. Export your Godot content with a compatible editor.
48
+
49
+ ## Installation
50
+
51
+ Install the library and its Worklets dependency:
52
+
53
+ ```sh
54
+ yarn add @preeternal/react-native-godot react-native-worklets
55
+ ```
56
+
57
+ Or with npm:
58
+
59
+ ```sh
60
+ npm install @preeternal/react-native-godot react-native-worklets
61
+ ```
62
+
63
+ React Native autolinks the native module. Installation downloads the pinned
64
+ LibGodot binaries from GitHub and verifies archive checksums. Allow the package's
65
+ install script if your package manager requires script approval.
66
+
67
+ If the automatic download did not run or failed, retry it from your app directory:
68
+
69
+ ```sh
70
+ node node_modules/@preeternal/react-native-godot/scripts/download-prebuilt.js
71
+ ```
72
+
73
+ This downloads missing engine packages and verifies their checksums. Then retry
74
+ your native dependency installation or build.
75
+
76
+ Add the Worklets plugin last in your application's Babel plugins:
77
+
78
+ ```js
79
+ module.exports = {
80
+ presets: ['module:@react-native/babel-preset'],
81
+ plugins: ['react-native-worklets/plugin'],
82
+ };
83
+ ```
84
+
85
+ In an Expo app, keep the `babel-preset-expo` preset.
86
+
87
+ ### iOS: CocoaPods (default)
88
+
89
+ From your app directory:
90
+
91
+ ```sh
92
+ cd ios
93
+ bundle exec pod install
94
+ cd ..
95
+ ```
96
+
97
+ Rebuild the native app after installation.
98
+
99
+ ### iOS: Swift Package Manager (React Native 0.87+)
100
+
101
+ SwiftPM is an experimental, opt-in alternative to CocoaPods. Every native
102
+ dependency, including Worklets, must provide a compatible SwiftPM manifest.
103
+
104
+ To migrate your app once:
105
+
106
+ ```sh
107
+ cd ios
108
+ npx react-native spm --deintegrate
109
+ ```
110
+
111
+ After a fresh clone or a dependency change, generate the SwiftPM workspace
112
+ from your app's `ios` directory:
113
+
114
+ ```sh
115
+ npx react-native spm
116
+ ```
117
+
118
+ Use React Native's generated workspace; this library's manifest depends on
119
+ React Native's generated headers and codegen products.
120
+
121
+ ### Android
122
+
123
+ In a Community CLI app, set `minSdkVersion` to at least `29` in
124
+ `android/build.gradle`:
125
+
126
+ ```groovy
127
+ buildscript {
128
+ ext {
129
+ minSdkVersion = 29
130
+ }
131
+ }
132
+ ```
133
+
134
+ Keep your other existing build settings. Set the supported architectures in
135
+ `android/gradle.properties`:
136
+
137
+ ```properties
138
+ reactNativeArchitectures=armeabi-v7a,arm64-v8a
139
+ ```
140
+
141
+ Use an ARM device or ARM emulator. The bundled engine does not contain x86 or
142
+ x86_64 binaries. The library registers its bundled Maven repository automatically.
143
+
144
+ ### Expo Development Builds
145
+
146
+ Register the config plugin in `app.json` or `app.config.js`:
147
+
148
+ ```json
149
+ {
150
+ "expo": {
151
+ "plugins": [
152
+ [
153
+ "@preeternal/react-native-godot",
154
+ {
155
+ "iosPacks": ["./assets/main.pck"]
156
+ }
157
+ ]
158
+ ]
159
+ }
160
+ }
161
+ ```
162
+
163
+ `iosPacks` is optional. It lists PCK files to add to the iOS app bundle.
164
+ The plugin configures Android's minimum SDK, ARM architectures, Maven repository
165
+ and Godot asset retention. Run `npx expo prebuild` after changing this
166
+ configuration, then rebuild your Development Build.
167
+
168
+ ## Add your Godot project
169
+
170
+ Export your Godot project as content (PCK or ZIP), rather than as a standalone
171
+ application.
172
+
173
+ - **Android:** extract the exported ZIP into
174
+ `android/app/src/main/assets/main/`, including its hidden `.godot` directory.
175
+ Start the engine with `--path /main`.
176
+ - **iOS:** add `main.pck` to your Xcode app target's Copy Bundle Resources,
177
+ or list it in the Expo plugin's `iosPacks`. Start the engine with
178
+ `--main-pack` and its absolute path in the app bundle.
179
+
180
+ For unpacked Android exports, preserve hidden Godot resources in your app's
181
+ `android/app/build.gradle`:
182
+
183
+ ```groovy
184
+ android {
185
+ androidResources {
186
+ ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"
187
+ }
188
+ }
189
+ ```
190
+
191
+ Expo apps receive this setting from the config plugin. Without it, exported
192
+ scenes and imported resources under `.godot` may be missing from the APK.
193
+
194
+ You can also load content from an accessible directory or pack downloaded to
195
+ the app's private storage. Pass its path to `createInstance`.
196
+
197
+ ## Usage
198
+
199
+ The following example uses `MainBundlePath` to locate the iOS pack. Install
200
+ this helper if your app does not already have another way to find the bundle:
201
+
202
+ ```sh
203
+ yarn add @dr.pogodin/react-native-fs
204
+ ```
205
+
206
+ Install its native dependencies before rebuilding on iOS.
207
+
208
+ ```tsx
209
+ import { Button, Platform, View } from 'react-native';
210
+ import { MainBundlePath } from '@dr.pogodin/react-native-fs';
211
+ import {
212
+ RTNGodot,
213
+ RTNGodotView,
214
+ runOnGodotThread,
215
+ } from '@preeternal/react-native-godot';
216
+
217
+ function startGodot() {
218
+ const args =
219
+ Platform.OS === 'android'
220
+ ? [
221
+ '--path',
222
+ '/main',
223
+ '--rendering-driver',
224
+ 'opengl3',
225
+ '--rendering-method',
226
+ 'gl_compatibility',
227
+ ]
228
+ : ['--main-pack', `${MainBundlePath}/main.pck`];
229
+ args.push('--display-driver', 'embedded');
230
+
231
+ return runOnGodotThread(() => {
232
+ 'worklet';
233
+ if (RTNGodot.getInstance() == null) {
234
+ if (RTNGodot.createInstance(args) == null) {
235
+ throw new Error('Godot failed to start. Check the native logs.');
236
+ }
237
+ }
238
+ });
239
+ }
240
+
241
+ function stopGodot() {
242
+ return runOnGodotThread(() => {
243
+ 'worklet';
244
+ RTNGodot.destroyInstance();
245
+ });
246
+ }
247
+
248
+ export default function App() {
249
+ return (
250
+ <View style={{ flex: 1 }}>
251
+ <Button
252
+ title="Start"
253
+ onPress={() => {
254
+ startGodot().catch(console.error);
255
+ }}
256
+ />
257
+ <Button
258
+ title="Stop"
259
+ onPress={() => {
260
+ stopGodot().catch(console.error);
261
+ }}
262
+ />
263
+ <RTNGodotView style={{ flex: 1 }} />
264
+ </View>
265
+ );
266
+ }
267
+ ```
268
+
269
+ Start is explicit. `RTNGodotView` displays the engine's main window when
270
+ `windowName` is omitted. Give the view a nonzero size. The `embedded` display
271
+ driver is required.
272
+
273
+ Only one engine instance runs at a time. After stopping it, start a new instance
274
+ with the same arguments or a different project. Stop the engine when your app
275
+ no longer needs it; removing a view is not a request to destroy the engine.
276
+
277
+ ### Pause and resume
278
+
279
+ Call these on the main JavaScript thread:
280
+
281
+ ```typescript
282
+ RTNGodot.pause();
283
+ RTNGodot.resume();
284
+ const paused = RTNGodot.is_paused();
285
+ ```
286
+
287
+ Pausing keeps the instance alive.
288
+ For previews shown across several screens, reuse the instance and pause it
289
+ when it is idle instead of loading the project on every navigation. Release
290
+ scene references and signal handlers when their consumer goes away.
291
+
292
+ ### Named windows
293
+
294
+ Create a Godot subwindow with the matching name, then embed it in another view:
295
+
296
+ ```tsx
297
+ <RTNGodotView style={{ flex: 1 }} windowName="subwindow" />
298
+ ```
299
+
300
+ The [example app](example/README.md) demonstrates this with React Navigation.
301
+
302
+ ## Platform notes
303
+
304
+ ### Choosing a renderer
305
+
306
+ OpenGL Compatibility is a useful starting point for embedded previews and broad
307
+ device coverage. Metal and Vulkan make Godot's Mobile renderer available for
308
+ scenes that need its rendering features. Choose for your scene and target
309
+ hardware: a newer graphics API does not automatically make a simple preview
310
+ faster. See Godot's [renderer comparison](https://docs.godotengine.org/en/stable/tutorials/rendering/renderers.html).
311
+
312
+ | Target | Driver / rendering method | When to use it |
313
+ | ------------- | ------------------------------ | --------------------------------------------------------- |
314
+ | Android | `opengl3` / `gl_compatibility` | Starting point; used by the example |
315
+ | Android | `vulkan` / `mobile` | Optional; validate on your target GPUs |
316
+ | iPhone/iPad | `metal` / `mobile` | Native bridge default when renderer arguments are omitted |
317
+ | iPhone/iPad | `opengl3` / `gl_compatibility` | Explicit Compatibility option |
318
+ | iOS Simulator | `opengl3` / `gl_compatibility` | Only packaged option; selected automatically |
319
+
320
+ Pass the driver and method together in the arguments to `createInstance`,
321
+ alongside your content path and `--display-driver embedded`:
322
+
323
+ ```typescript
324
+ // OpenGL Compatibility on Android or iOS, including Simulator:
325
+ const rendererArgs = [
326
+ '--rendering-driver',
327
+ 'opengl3',
328
+ '--rendering-method',
329
+ 'gl_compatibility',
330
+ ];
331
+
332
+ // Metal / Mobile on a physical iPhone or iPad:
333
+ const metalArgs = [
334
+ '--rendering-driver',
335
+ 'metal',
336
+ '--rendering-method',
337
+ 'mobile',
338
+ ];
339
+
340
+ // Vulkan / Mobile on a compatible Android device:
341
+ const vulkanArgs = [
342
+ '--rendering-driver',
343
+ 'vulkan',
344
+ '--rendering-method',
345
+ 'mobile',
346
+ ];
347
+ ```
348
+
349
+ Select the renderer before starting the engine. The bridge does not implement
350
+ an automatic retry with a different renderer after startup failure. A
351
+ JavaScript error handler cannot recover from a native crash. If you expose a
352
+ renderer preference, keep a way to reset it before the next engine startup.
353
+
354
+ Practical things to check before shipping:
355
+
356
+ - **Lighting and materials:** Compatibility and Mobile can produce different
357
+ lighting, shadows and shader results. Tune the scene for each renderer you
358
+ offer, especially when matching a 3D background to the surrounding app UI.
359
+ - **Android Vulkan:** black background regions, composition artifacts and slow
360
+ first display have been observed on some devices with embedded content.
361
+ Treat Vulkan as an opt-in path and test both inline and fullscreen views;
362
+ the Android version alone does not establish GPU/driver compatibility.
363
+ - **First display:** loading a scene and preparing shaders can cost more than
364
+ showing it again. Compare Release builds on real devices, measuring both
365
+ first use and reuse. Creating an instance offscreen does not guarantee that
366
+ every shader has been prepared. See Godot's [shader compilation guidance](https://docs.godotengine.org/en/stable/tutorials/performance/pipeline_compilations.html).
367
+ - **Simulator:** the package supports ARM64 on Apple silicon, uses OpenGL and
368
+ contains no Metal backend. Explicit Metal requests are rejected before
369
+ engine creation. Device Metal may perform better, but Simulator frame rates
370
+ and visuals do not predict device results; check the actual device.
371
+
372
+ ### Android input
373
+
374
+ The embedded Android view currently forwards touch input. Godot's virtual
375
+ keyboard, hardware keyboard, mouse, gamepad and sensor input, and standalone
376
+ Godot Android plugins are not connected to this embedded path. Use React Native
377
+ controls for interactions requiring those features.
378
+
379
+ ## Audio and microphone
380
+
381
+ **Audio playback is enabled. Microphone capture is excluded from the default
382
+ build.** No configuration is needed for projects that only play sound.
383
+
384
+ Apple can require `NSMicrophoneUsageDescription` when a bundled SDK references
385
+ protected microphone APIs, even if your app never records audio. The default
386
+ LibGodot build removes capture code and its iOS microphone permission API
387
+ references at compile time. Muting audio or disabling input at runtime cannot
388
+ remove those references. See Apple's [protected resource requirements](https://developer.apple.com/documentation/uikit/requesting-access-to-protected-resources).
389
+ Other SDKs in your app may still require their own purpose strings.
390
+
391
+ ### Enable microphone capture
392
+
393
+ Add this top-level setting to **your app's** `package.json`:
394
+
395
+ ```json
396
+ {
397
+ "reactNativeGodot": {
398
+ "microphone": true
399
+ }
400
+ }
401
+ ```
402
+
403
+ Then download the selected binaries from your app directory:
404
+
405
+ ```sh
406
+ node node_modules/@preeternal/react-native-godot/scripts/download-prebuilt.js
407
+ ```
408
+
409
+ Refresh iOS native dependencies (`bundle exec pod install` in `ios`, or
410
+ `npx react-native spm` for SwiftPM), then rebuild the native app. Expo apps use
411
+ the same `package.json` setting and also need a new native build.
412
+
413
+ This selects recording-capable LibGodot `4.7.2.preeternal.1` instead of the
414
+ default `4.7.2.preeternal.2`, with matching bindings. Both use Godot 4.7.2.
415
+ Set `microphone` to `false` or remove it, then repeat these steps to return to
416
+ the default. This is a native build choice; JavaScript reload cannot change it.
417
+
418
+ Configure `NSMicrophoneUsageDescription` on iOS, `RECORD_AUDIO` and runtime
419
+ permission handling on Android, and `audio/driver/enable_input=true` in your
420
+ Godot project. Re-export after changing Godot settings. The library does not
421
+ request microphone permission for you.
422
+
423
+ ### Silent previews and background music
424
+
425
+ For visual-only content, select the `Dummy` audio driver in `project.godot`,
426
+ then re-export and rebuild your app:
427
+
428
+ ```ini
429
+ [audio]
430
+
431
+ driver/driver="Dummy"
432
+ driver/enable_input=false
433
+ ```
434
+
435
+ This disables Godot audio output and input, avoiding its use of the platform
436
+ audio driver when the preview needs no sound. Setting the master volume to
437
+ zero still leaves that driver active. Check music from another app alongside
438
+ your app's own audio session settings. See [Godot's audio driver setting](https://docs.godotengine.org/en/stable/classes/class_projectsettings.html#class-projectsettings-property-audio-driver-driver).
439
+
440
+ ## Godot API
441
+
442
+ Use `runOnGodotThread` for engine calls and scene-tree access. It returns a
443
+ Promise, so handle errors in your calling code. Obtain the API inside the
444
+ worklet after starting the engine:
445
+
446
+ ```typescript
447
+ await runOnGodotThread(() => {
448
+ 'worklet';
449
+ if (RTNGodot.getInstance() == null) return;
450
+
451
+ const Godot = RTNGodot.API();
452
+ const vector = Godot.Vector2();
453
+ vector.x = 1;
454
+ vector.y = 2;
455
+
456
+ const sceneTree = Godot.Engine.get_main_loop();
457
+ if (!sceneTree) return;
458
+
459
+ const root = sceneTree.get_root();
460
+ const player = root.find_child('Player', true, false);
461
+ if (player) {
462
+ player.set_position(vector);
463
+ }
464
+ });
465
+ ```
466
+
467
+ Singletons are properties such as `Godot.Engine`. Constructors, properties
468
+ and methods follow the Godot API exposed by the bundled engine.
469
+
470
+ ### Signals
471
+
472
+ Connect JavaScript functions to Godot signals from a worklet:
473
+
474
+ ```typescript
475
+ await runOnGodotThread(() => {
476
+ 'worklet';
477
+ if (RTNGodot.getInstance() == null) return;
478
+
479
+ const Godot = RTNGodot.API();
480
+ const sceneTree = Godot.Engine.get_main_loop();
481
+ if (!sceneTree) return;
482
+
483
+ const button = sceneTree.get_root().find_child('Button', true, false);
484
+ if (button) {
485
+ button.pressed.connect(function () {
486
+ console.log('Button pressed');
487
+ });
488
+ }
489
+ });
490
+ ```
491
+
492
+ Callbacks execute in the Godot runtime. Disconnect signal handlers when your
493
+ application no longer needs them.
494
+
495
+ ### Callables
496
+
497
+ Godot methods accepting a `Callable` can receive JavaScript functions.
498
+ For example, attach this GDScript to a node named `RNInterface`:
499
+
500
+ ```gdscript
501
+ extends Node
502
+
503
+ func test_callable(callback: Callable) -> void:
504
+ callback.call("Hello from Godot")
505
+ ```
506
+
507
+ Call it from the Godot thread:
508
+
509
+ ```typescript
510
+ await runOnGodotThread(() => {
511
+ 'worklet';
512
+ if (RTNGodot.getInstance() == null) return;
513
+
514
+ const sceneTree = RTNGodot.API().Engine.get_main_loop();
515
+ if (!sceneTree) return;
516
+
517
+ const node = sceneTree.get_root().find_child('RNInterface', true, false);
518
+ if (node) {
519
+ node.test_callable(function (message: string) {
520
+ console.log(message);
521
+ });
522
+ }
523
+ });
524
+ ```
525
+
526
+ ### Threading and object lifetime
527
+
528
+ Godot runs on a thread separate from the native UI and React Native JavaScript
529
+ threads. `runOnGodotThread` schedules a Worklets function on that thread.
530
+
531
+ Godot object references belong to the JavaScript runtime where they were
532
+ obtained. Keep API access and object manipulation inside Godot worklets; do not
533
+ pass Godot objects between the main JavaScript runtime and the Godot runtime.
534
+ After `destroyInstance`, discard references to the previous instance's objects.
535
+
536
+ ## Upgrading from 4.5
537
+
538
+ The 4.7 line keeps the `RTNGodot`, `RTNGodotView` and `runOnGodotThread` entry
539
+ points. Upgrade the library, its native engine packages and your exported Godot
540
+ content together:
541
+
542
+ 1. Re-export PCK/ZIP content with Godot 4.7.2. Include the re-exported `.godot`
543
+ resources on Android; replace bundled packs and version any downloaded
544
+ content caches so an old export is not reused accidentally.
545
+ 2. Refresh native dependencies and rebuild the app. The library installs its
546
+ matching engine and bindings automatically; keep custom 4.5 binaries out
547
+ of a 4.7 installation. A JavaScript reload is insufficient.
548
+ 3. Review renderer arguments. An iOS device now defaults to Metal/Mobile;
549
+ choose `opengl3` / `gl_compatibility` explicitly to retain Compatibility.
550
+ Check lighting, shaders and the first visible frame on real devices.
551
+ 4. If your app records audio, [enable microphone capture](#enable-microphone-capture)
552
+ and configure permissions. Playback-only apps can use the default build.
553
+ 5. Check Start → Stop → Start, pause/resume, navigation, resize and any named
554
+ windows used by your app. Drop old Godot object references after Stop.
555
+
556
+ For an app staying on 4.5, keep its library release and exported content
557
+ together. The `godot-4.5` branch remains separate from the 4.7 line.
558
+ See the [release notes](CHANGELOG.md) for the changes in this migration.
559
+
560
+ ## Examples
561
+
562
+ See the [example app and its setup instructions](example/README.md) for two
563
+ Godot projects, lifecycle controls and a named subwindow.
564
+
565
+ ## Contributing
566
+
567
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, checks,
568
+ custom engine builds, debugging and release tooling.
569
+
570
+ Issues and pull requests are welcome in the
571
+ [GitHub repository](https://github.com/Preeternal/react-native-godot).
572
+ See the [code of conduct](CODE_OF_CONDUCT.md).
573
+
574
+ ## Upstream / credits
575
+
576
+ This maintained fork builds on the native bridge, platform integration and
577
+ LibGodot integration developed by [Migeran](https://migeran.com).
578
+ [Born](https://born.com) deserves credit for the original
579
+ [React Native adaptation](https://github.com/borndotcom/react-native-godot)
580
+ and early product integration.
581
+
582
+ The fork adds the Godot 4.7 integration, renderer selection, native lifecycle
583
+ and surface handling fixes, and installation tooling described in the
584
+ [release notes](CHANGELOG.md). It is used in an actively developed app;
585
+ maintenance follows practical integration needs and available time.
586
+
587
+ ## License
588
+
589
+ MIT. See [LICENSE](LICENSE) for details.
590
+
591
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob).