@babylonjs/react-native 0.4.0-alpha.7 → 0.64.0-alpha.47
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.
- package/BabylonModule.d.ts +2 -0
- package/{BabylonModule.ts → BabylonModule.js} +9 -12
- package/BabylonModule.js.map +1 -0
- package/EngineHook.d.ts +3 -0
- package/EngineHook.js +179 -0
- package/EngineHook.js.map +1 -0
- package/EngineView.d.ts +13 -0
- package/EngineView.js +118 -0
- package/EngineView.js.map +1 -0
- package/FontFace.d.ts +12 -0
- package/FontFace.js +35 -0
- package/FontFace.js.map +1 -0
- package/NativeCapture.d.ts +14 -0
- package/NativeCapture.js +14 -0
- package/NativeCapture.js.map +1 -0
- package/README.md +8 -8
- package/ReactNativeEngine.d.ts +7 -0
- package/ReactNativeEngine.js +33 -0
- package/ReactNativeEngine.js.map +1 -0
- package/VersionValidation.d.ts +1 -0
- package/{VersionValidation.ts → VersionValidation.js} +3 -3
- package/VersionValidation.js.map +1 -0
- package/android/build.gradle +13 -1
- package/android/include/IXrContextARCore.h +10 -0
- package/android/src/main/java/com/babylonreactnative/BabylonModule.java +6 -4
- package/android/src/main/java/com/babylonreactnative/BabylonNativeInterop.java +20 -6
- package/android/src/main/java/com/babylonreactnative/EngineView.java +151 -8
- package/android/src/main/java/com/babylonreactnative/EngineViewManager.java +8 -0
- package/android/src/main/jniLibs/arm64-v8a/libBabylonNative.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libturbomodulejsijni.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libBabylonNative.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libturbomodulejsijni.so +0 -0
- package/android/src/main/jniLibs/x86/libBabylonNative.so +0 -0
- package/android/src/main/jniLibs/x86/libturbomodulejsijni.so +0 -0
- package/index.d.ts +4 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/ios/BabylonModule.mm +7 -0
- package/ios/BabylonNativeInterop.h +4 -0
- package/ios/BabylonNativeInterop.mm +37 -14
- package/ios/EngineViewManager.mm +41 -3
- package/ios/ReactNativeBabylon.xcodeproj/project.pbxproj +7609 -9451
- package/ios/include/IXrContextARKit.h +10 -0
- package/ios/libs/libBabylonNative.a +0 -0
- package/ios/libs/libCanvas.a +0 -0
- package/ios/libs/libGenericCodeGen.a +0 -0
- package/ios/libs/libGraphics.a +0 -0
- package/ios/libs/libJsRuntime.a +0 -0
- package/ios/libs/libMachineIndependent.a +0 -0
- package/ios/libs/libNativeCapture.a +0 -0
- package/ios/libs/libNativeEngine.a +0 -0
- package/ios/libs/libNativeInput.a +0 -0
- package/ios/libs/libNativeOptimizations.a +0 -0
- package/ios/libs/libNativeTracing.a +0 -0
- package/ios/libs/libNativeXr.a +0 -0
- package/ios/libs/libOGLCompiler.a +0 -0
- package/ios/libs/libOSDependent.a +0 -0
- package/ios/libs/libSPIRV.a +0 -0
- package/ios/libs/libUrlLib.a +0 -0
- package/ios/libs/libWindow.a +0 -0
- package/ios/libs/libXMLHttpRequest.a +0 -0
- package/ios/libs/libastc-codec.a +0 -0
- package/ios/libs/libastc.a +0 -0
- package/ios/libs/libbgfx.a +0 -0
- package/ios/libs/libbimg.a +0 -0
- package/ios/libs/libbx.a +0 -0
- package/ios/libs/libglslang.a +0 -0
- package/ios/libs/libnapi.a +0 -0
- package/ios/libs/libspirv-cross-core.a +0 -0
- package/ios/libs/libspirv-cross-glsl.a +0 -0
- package/ios/libs/libspirv-cross-msl.a +0 -0
- package/ios/libs/libtinyexr.a +0 -0
- package/ios/libs/libxr.a +0 -0
- package/package.json +53 -52
- package/shared/BabylonNative.h +30 -3
- package/shared/XrAnchorHelper.h +229 -0
- package/shared/XrContextHelper.h +179 -0
- package/EngineHook.ts +0 -103
- package/EngineView.tsx +0 -156
- package/ReactNativeEngine.ts +0 -69
- package/index.ts +0 -2
- package/ios/libs/libspirv-cross-hlsl.a +0 -0
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import { NativeModules } from 'react-native';
|
|
2
|
-
|
|
3
|
-
declare const global: {
|
|
4
|
-
nativeCallSyncHook: any;
|
|
5
|
-
};
|
|
6
2
|
const isRemoteDebuggingEnabled = !global.nativeCallSyncHook;
|
|
7
|
-
|
|
8
3
|
// This legacy React Native module is created by Babylon React Native, and is only used to bootstrap the JSI object creation.
|
|
9
4
|
// This will likely be removed when the BabylonNative global object is eventually converted to a TurboModule.
|
|
10
|
-
const BabylonModule
|
|
11
|
-
|
|
12
|
-
} = NativeModules.BabylonModule;
|
|
13
|
-
|
|
14
|
-
export async function ensureInitialized(): Promise<boolean> {
|
|
5
|
+
const BabylonModule = NativeModules.BabylonModule;
|
|
6
|
+
export async function ensureInitialized() {
|
|
15
7
|
if (isRemoteDebuggingEnabled) {
|
|
16
8
|
// When remote debugging is enabled, JavaScript runs on the debugging host machine, not on the device where the app is running.
|
|
17
9
|
// JSI (which Babylon Native uses heavily) can not work in this mode. In the future, this debugging mode will be phased out as it is incompatible with TurboModules for the same reason.
|
|
18
10
|
return false;
|
|
19
|
-
}
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
20
13
|
// This does the first stage of Babylon Native initialization, including creating the BabylonNative JSI object.
|
|
21
14
|
await BabylonModule.initialize();
|
|
22
15
|
return true;
|
|
23
16
|
}
|
|
24
|
-
}
|
|
17
|
+
}
|
|
18
|
+
export async function reset() {
|
|
19
|
+
return BabylonModule.resetView();
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=BabylonModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BabylonModule.js","sourceRoot":"","sources":["../../Modules/@babylonjs/react-native/BabylonModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAK7C,MAAM,wBAAwB,GAAG,CAAC,MAAM,CAAC,kBAAkB,CAAC;AAE5D,6HAA6H;AAC7H,6GAA6G;AAC7G,MAAM,aAAa,GAGf,aAAa,CAAC,aAAa,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACnC,IAAI,wBAAwB,EAAE;QAC1B,+HAA+H;QAC/H,wLAAwL;QACxL,OAAO,KAAK,CAAC;KAChB;SAAM;QACH,+GAA+G;QAC/G,MAAM,aAAa,CAAC,UAAU,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;KACf;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,KAAK;IACvB,OAAO,aAAa,CAAC,SAAS,EAAE,CAAC;AACrC,CAAC"}
|
package/EngineHook.d.ts
ADDED
package/EngineHook.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import { PERMISSIONS, check, request } from 'react-native-permissions';
|
|
4
|
+
import { WebXRSessionManager, WebXRExperienceHelper, Color4, Tools } from '@babylonjs/core';
|
|
5
|
+
import { ReactNativeEngine } from './ReactNativeEngine';
|
|
6
|
+
import './VersionValidation';
|
|
7
|
+
import * as base64 from 'base-64';
|
|
8
|
+
// These are errors that are normally thrown by WebXR's requestSession, so we should throw the same errors under similar circumstances so app code can be written the same for browser or native.
|
|
9
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/XRSystem/requestSession
|
|
10
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException#Error_names
|
|
11
|
+
var DOMError;
|
|
12
|
+
(function (DOMError) {
|
|
13
|
+
DOMError[DOMError["NotSupportedError"] = 9] = "NotSupportedError";
|
|
14
|
+
DOMError[DOMError["InvalidStateError"] = 11] = "InvalidStateError";
|
|
15
|
+
DOMError[DOMError["SecurityError"] = 18] = "SecurityError";
|
|
16
|
+
})(DOMError || (DOMError = {}));
|
|
17
|
+
class DOMException {
|
|
18
|
+
error;
|
|
19
|
+
constructor(error) {
|
|
20
|
+
this.error = error;
|
|
21
|
+
}
|
|
22
|
+
get code() { return this.error; }
|
|
23
|
+
get name() { return DOMError[this.error]; }
|
|
24
|
+
}
|
|
25
|
+
// Override the WebXRSessionManager.initializeSessionAsync to insert a camera permissions request. It would be cleaner to do this directly in the native XR implementation, but there are a couple problems with that:
|
|
26
|
+
// 1. React Native does not provide a way to hook into the permissions request result (at least on Android).
|
|
27
|
+
// 2. If it is done on the native side, then we need one implementation per platform.
|
|
28
|
+
{
|
|
29
|
+
const originalInitializeSessionAsync = WebXRSessionManager.prototype.initializeSessionAsync;
|
|
30
|
+
WebXRSessionManager.prototype.initializeSessionAsync = async function (...args) {
|
|
31
|
+
if (Platform.OS === "windows") {
|
|
32
|
+
// Launching into immersive mode on Windows HMDs doesn't require a runtime permission check.
|
|
33
|
+
// The Spatial Perception capability should be enabled in the project's Package.appxmanifest.
|
|
34
|
+
return originalInitializeSessionAsync.apply(this, args);
|
|
35
|
+
}
|
|
36
|
+
const cameraPermission = Platform.select({
|
|
37
|
+
android: PERMISSIONS.ANDROID.CAMERA,
|
|
38
|
+
ios: PERMISSIONS.IOS.CAMERA,
|
|
39
|
+
});
|
|
40
|
+
// Only Android, iOS and Windows are supported.
|
|
41
|
+
if (cameraPermission === undefined) {
|
|
42
|
+
throw new DOMException(DOMError.NotSupportedError);
|
|
43
|
+
}
|
|
44
|
+
// If the permission has not been granted yet, but also not been blocked, then request permission.
|
|
45
|
+
let permissionStatus = await check(cameraPermission);
|
|
46
|
+
if (permissionStatus == "denied") {
|
|
47
|
+
permissionStatus = await request(cameraPermission);
|
|
48
|
+
}
|
|
49
|
+
// If the permission has still not been granted, then throw an appropriate exception, otherwise continue with the actual XR session initialization.
|
|
50
|
+
switch (permissionStatus) {
|
|
51
|
+
case "unavailable":
|
|
52
|
+
throw new DOMException(DOMError.NotSupportedError);
|
|
53
|
+
case "denied":
|
|
54
|
+
case "blocked":
|
|
55
|
+
throw new DOMException(DOMError.SecurityError);
|
|
56
|
+
case "granted":
|
|
57
|
+
return originalInitializeSessionAsync.apply(this, args);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (Platform.OS === "android" || Platform.OS === "ios") {
|
|
62
|
+
const originalEnterXRAsync = WebXRExperienceHelper.prototype.enterXRAsync;
|
|
63
|
+
WebXRExperienceHelper.prototype.enterXRAsync = async function (...args) {
|
|
64
|
+
// TODO: https://github.com/BabylonJS/BabylonNative/issues/649
|
|
65
|
+
// Android/iOS require manually clearing the default frame buffer to prevent garbage from being rendered for a few frames during the XR transition
|
|
66
|
+
const sessionManager = await originalEnterXRAsync.apply(this, args);
|
|
67
|
+
const scene = sessionManager.scene;
|
|
68
|
+
const beforeRenderObserver = scene.onBeforeRenderObservable.add(() => {
|
|
69
|
+
scene.getEngine().unBindFramebuffer(undefined);
|
|
70
|
+
scene.getEngine().clear(scene.clearColor, true, false);
|
|
71
|
+
});
|
|
72
|
+
sessionManager.onXRSessionEnded.add(() => {
|
|
73
|
+
scene.onBeforeRenderObservable.remove(beforeRenderObserver);
|
|
74
|
+
});
|
|
75
|
+
return sessionManager;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
else if (Platform.OS === "windows") {
|
|
79
|
+
const originalEnterXRAsync = WebXRExperienceHelper.prototype.enterXRAsync;
|
|
80
|
+
WebXRExperienceHelper.prototype.enterXRAsync = async function (...args) {
|
|
81
|
+
// TODO: https://github.com/BabylonJS/BabylonNative/issues/577
|
|
82
|
+
// Windows HMDs require different rendering behaviors than default xr rendering for mobile devices
|
|
83
|
+
const sessionManager = await originalEnterXRAsync.apply(this, args);
|
|
84
|
+
sessionManager.scene.clearColor = new Color4(0, 0, 0, 0);
|
|
85
|
+
sessionManager.scene.autoClear = true;
|
|
86
|
+
return sessionManager;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
global.atob = base64.decode;
|
|
90
|
+
// Polyfill console.time and console.timeEnd if needed (as of React Native 0.64 these are not implemented).
|
|
91
|
+
if (!console.time) {
|
|
92
|
+
const consoleTimes = new Map();
|
|
93
|
+
console.time = (label = "default") => {
|
|
94
|
+
consoleTimes.set(label, performance.now());
|
|
95
|
+
};
|
|
96
|
+
console.timeEnd = (label = "default") => {
|
|
97
|
+
const end = performance.now();
|
|
98
|
+
const start = consoleTimes.get(label);
|
|
99
|
+
if (!!start) {
|
|
100
|
+
consoleTimes.delete(label);
|
|
101
|
+
console.log(`${label}: ${end - start} ms`);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
{
|
|
106
|
+
const setPerformanceLogLevel = Object.getOwnPropertyDescriptor(Tools, "PerformanceLogLevel")?.set;
|
|
107
|
+
if (!setPerformanceLogLevel) {
|
|
108
|
+
console.warn(`NativeTracing was not hooked into Babylon.js performance logging because the Tools.PerformanceLogLevel property does not exist.`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// Keep a map of trace region opaque pointers since Tools.EndPerformanceCounter just takes a counter name as an argument.
|
|
112
|
+
const traceRegions = new Map();
|
|
113
|
+
let currentLevel = Tools.PerformanceNoneLogLevel;
|
|
114
|
+
Object.defineProperty(Tools, "PerformanceLogLevel", {
|
|
115
|
+
set: (level) => {
|
|
116
|
+
// No-op if the log level isn't changing, otherwise we can end up with multiple wrapper layers repeating the same work.
|
|
117
|
+
if (level !== currentLevel) {
|
|
118
|
+
currentLevel = level;
|
|
119
|
+
// Invoke the original PerformanceLevel setter.
|
|
120
|
+
setPerformanceLogLevel(currentLevel);
|
|
121
|
+
if (currentLevel === Tools.PerformanceNoneLogLevel) {
|
|
122
|
+
_native.disablePerformanceLogging();
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
_native.enablePerformanceLogging();
|
|
126
|
+
// When Tools.PerformanceLogLevel is set, it assigns the Tools.StartPerformanceCounter and Tools.EndPerformanceCounter functions, so we need to assign
|
|
127
|
+
// these functions again in order to wrap them.
|
|
128
|
+
const originalStartPerformanceCounter = Tools.StartPerformanceCounter;
|
|
129
|
+
Tools.StartPerformanceCounter = (counterName, condition = true) => {
|
|
130
|
+
// Call into native before so the time it takes is not captured in the JS perf counter interval.
|
|
131
|
+
if (condition) {
|
|
132
|
+
if (traceRegions.has(counterName)) {
|
|
133
|
+
console.warn(`Performance counter '${counterName}' already exists.`);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
traceRegions.set(counterName, _native.startPerformanceCounter(counterName));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
originalStartPerformanceCounter(counterName, condition);
|
|
140
|
+
};
|
|
141
|
+
const originalEndPerformanceCounter = Tools.EndPerformanceCounter;
|
|
142
|
+
Tools.EndPerformanceCounter = (counterName, condition = true) => {
|
|
143
|
+
originalEndPerformanceCounter(counterName, condition);
|
|
144
|
+
// Call into native after so the time it takes is not captured in the JS perf counter interval.
|
|
145
|
+
if (condition) {
|
|
146
|
+
const traceRegion = traceRegions.get(counterName);
|
|
147
|
+
if (traceRegion) {
|
|
148
|
+
_native.endPerformanceCounter(traceRegion);
|
|
149
|
+
traceRegions.delete(counterName);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
console.warn(`Performance counter '${counterName}' does not exist.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export function useEngine() {
|
|
163
|
+
const [engine, setEngine] = useState();
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
const abortController = new AbortController();
|
|
166
|
+
let engine = undefined;
|
|
167
|
+
(async () => {
|
|
168
|
+
setEngine(engine = await ReactNativeEngine.tryCreateAsync(abortController.signal) ?? undefined);
|
|
169
|
+
})();
|
|
170
|
+
return () => {
|
|
171
|
+
abortController.abort();
|
|
172
|
+
// NOTE: Do not use setEngine with a callback to dispose the engine instance as that callback does not get called during component unmount when compiled in release.
|
|
173
|
+
engine?.dispose();
|
|
174
|
+
setEngine(undefined);
|
|
175
|
+
};
|
|
176
|
+
}, []);
|
|
177
|
+
return engine;
|
|
178
|
+
}
|
|
179
|
+
//# s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QACX,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC9C,IAAI,MAAM,GAAkC,SAAS,CAAC;QAEtD,CAAC,KAAK,IAAI,EAAE;YACR,SAAS,CAAC,MAAM,GAAG,MAAM,iBAAiB,CAAC,cAAc,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,CAAC;QACpG,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,GAAG,EAAE;YACR,eAAe,CAAC,KAAK,EAAE,CAAC;YACxB,oKAAoK;YACpK,MAAM,EAAE,OAAO,EAAE,CAAC;YAClB,SAAS,CAAC,SAAS,CAAC,CAAC;QACzB,CAAC,CAAC;IACN,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/EngineView.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
import { ViewProps } from 'react-native';
|
|
3
|
+
import { Camera } from '@babylonjs/core';
|
|
4
|
+
export interface EngineViewProps extends ViewProps {
|
|
5
|
+
camera?: Camera;
|
|
6
|
+
displayFrameRate?: boolean;
|
|
7
|
+
isTransparent?: boolean;
|
|
8
|
+
onInitialized?: (view: EngineViewCallbacks) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface EngineViewCallbacks {
|
|
11
|
+
takeSnapshot: () => Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
export declare const EngineView: FunctionComponent<EngineViewProps>;
|
package/EngineView.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState, useRef } from 'react';
|
|
2
|
+
import { requireNativeComponent, AppState, View, Text, findNodeHandle, UIManager } from 'react-native';
|
|
3
|
+
import { SceneInstrumentation } from '@babylonjs/core';
|
|
4
|
+
import { ensureInitialized } from './BabylonModule';
|
|
5
|
+
const NativeEngineView = global['EngineView'] || (global['EngineView'] = requireNativeComponent('EngineView'));
|
|
6
|
+
export const EngineView = (props) => {
|
|
7
|
+
const [initialized, setInitialized] = useState();
|
|
8
|
+
const [appState, setAppState] = useState(AppState.currentState);
|
|
9
|
+
//const [fps, setFps] = useState<number>();
|
|
10
|
+
const [sceneStats, setSceneStats] = useState();
|
|
11
|
+
const engineViewRef = useRef(null);
|
|
12
|
+
const snapshotPromise = useRef();
|
|
13
|
+
const isTransparent = props.isTransparent || false;
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
(async () => {
|
|
16
|
+
setInitialized(await ensureInitialized());
|
|
17
|
+
})();
|
|
18
|
+
}, []);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const onAppStateChanged = (appState) => {
|
|
21
|
+
setAppState(appState);
|
|
22
|
+
};
|
|
23
|
+
AppState.addEventListener("change", onAppStateChanged);
|
|
24
|
+
return () => {
|
|
25
|
+
AppState.removeEventListener("change", onAppStateChanged);
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (props.camera && appState === "active") {
|
|
30
|
+
const engine = props.camera.getScene().getEngine();
|
|
31
|
+
if (!engine.isDisposed) {
|
|
32
|
+
engine.runRenderLoop(() => {
|
|
33
|
+
for (let scene of engine.scenes) {
|
|
34
|
+
scene.render();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return () => {
|
|
38
|
+
if (!engine.isDisposed) {
|
|
39
|
+
engine.stopRenderLoop();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}, [props.camera, appState]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (props.camera && (props.displayFrameRate ?? __DEV__)) {
|
|
48
|
+
const scene = props.camera.getScene();
|
|
49
|
+
const engine = scene.getEngine();
|
|
50
|
+
if (!engine.isDisposed) {
|
|
51
|
+
setSceneStats({ frameRate: 0, frameTime: 0 });
|
|
52
|
+
const sceneInstrumentation = new SceneInstrumentation(scene);
|
|
53
|
+
sceneInstrumentation.captureFrameTime = true;
|
|
54
|
+
const timerHandle = setInterval(() => {
|
|
55
|
+
setSceneStats({ frameRate: engine.getFps(), frameTime: sceneInstrumentation.frameTimeCounter.lastSecAverage });
|
|
56
|
+
}, 1000);
|
|
57
|
+
return () => {
|
|
58
|
+
clearInterval(timerHandle);
|
|
59
|
+
setSceneStats(undefined);
|
|
60
|
+
sceneInstrumentation.dispose();
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}, [props.camera, props.displayFrameRate]);
|
|
66
|
+
// Call onInitialized if provided, and include the callback for takeSnapshot.
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (props.onInitialized) {
|
|
69
|
+
props.onInitialized({
|
|
70
|
+
takeSnapshot: () => {
|
|
71
|
+
if (!snapshotPromise.current) {
|
|
72
|
+
let resolveFunction;
|
|
73
|
+
const promise = new Promise((resolutionFunc) => {
|
|
74
|
+
resolveFunction = resolutionFunc;
|
|
75
|
+
});
|
|
76
|
+
// Resolution functions should always be initialized.
|
|
77
|
+
if (resolveFunction) {
|
|
78
|
+
snapshotPromise.current = { promise: promise, resolve: resolveFunction };
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw new Error("Resolution functions not initialized after snapshot promise creation.");
|
|
82
|
+
}
|
|
83
|
+
UIManager.dispatchViewManagerCommand(findNodeHandle(engineViewRef.current), "takeSnapshot", []);
|
|
84
|
+
}
|
|
85
|
+
return snapshotPromise.current.promise;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}, [props.onInitialized]);
|
|
90
|
+
// Handle snapshot data returned.
|
|
91
|
+
const snapshotDataReturnedHandler = useCallback((event) => {
|
|
92
|
+
// The nativeEvent is a DOMEvent which doesn't have a typescript definition. Cast it to an Event object with a data property.
|
|
93
|
+
const { data } = event.nativeEvent;
|
|
94
|
+
if (snapshotPromise.current) {
|
|
95
|
+
snapshotPromise.current.resolve(data);
|
|
96
|
+
snapshotPromise.current = undefined;
|
|
97
|
+
}
|
|
98
|
+
}, []);
|
|
99
|
+
if (initialized !== false) {
|
|
100
|
+
return (React.createElement(View, { style: [{ flex: 1 }, props.style, { overflow: "hidden" }] },
|
|
101
|
+
initialized && React.createElement(NativeEngineView, { ref: engineViewRef, style: { flex: 1 }, onSnapshotDataReturned: snapshotDataReturnedHandler, isTransparent: isTransparent }),
|
|
102
|
+
sceneStats !== undefined &&
|
|
103
|
+
React.createElement(View, { style: { backgroundColor: '#00000040', opacity: 1, position: 'absolute', right: 0, left: 0, top: 0, flexDirection: 'row-reverse' } },
|
|
104
|
+
React.createElement(Text, { style: { color: 'yellow', alignSelf: 'flex-end', margin: 3, fontVariant: ['tabular-nums'] } },
|
|
105
|
+
"FPS: ",
|
|
106
|
+
sceneStats.frameRate.toFixed(0)))));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const message = "Could not initialize Babylon Native.";
|
|
110
|
+
if (!__DEV__) {
|
|
111
|
+
throw new Error(message);
|
|
112
|
+
}
|
|
113
|
+
return (React.createElement(View, { style: { flex: 1, justifyContent: 'center', alignItems: 'center' } },
|
|
114
|
+
React.createElement(Text, { style: { fontSize: 24 } }, message),
|
|
115
|
+
React.createElement(Text, { style: { fontSize: 12 } }, "React Native remote debugging does not work with Babylon Native.")));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=EngineView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EngineView.js","sourceRoot":"","sources":["../../Modules/@babylonjs/react-native/EngineView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAgD,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtH,OAAO,EAAE,sBAAsB,EAAa,QAAQ,EAAkB,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC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,OAAO,CAAC,CAAC;SAC5B;QAED,OAAO,CACH,oBAAC,IAAI,IAAC,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE;YACpE,oBAAC,IAAI,IAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAG,OAAO,CAAQ;YAC/C,oBAAC,IAAI,IAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,uEAAyE,CACnG,CACV,CAAC;KACL;AACL,CAAC,CAAA"}
|
package/FontFace.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Partial Polyfill for FontFace Web API to wrap the NativeCanvas object.
|
|
3
|
+
*/
|
|
4
|
+
export declare class FontFace {
|
|
5
|
+
readonly family: string;
|
|
6
|
+
private source;
|
|
7
|
+
private _status;
|
|
8
|
+
get status(): "unloaded" | "loading" | "loaded" | "error";
|
|
9
|
+
get loaded(): boolean;
|
|
10
|
+
constructor(family: string, source: string | ArrayBuffer);
|
|
11
|
+
load(): Promise<void>;
|
|
12
|
+
}
|
package/FontFace.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Tools } from '@babylonjs/core';
|
|
2
|
+
/**
|
|
3
|
+
* Partial Polyfill for FontFace Web API to wrap the NativeCanvas object.
|
|
4
|
+
*/
|
|
5
|
+
export class FontFace {
|
|
6
|
+
family;
|
|
7
|
+
source;
|
|
8
|
+
_status = "unloaded";
|
|
9
|
+
get status() {
|
|
10
|
+
return this._status;
|
|
11
|
+
}
|
|
12
|
+
get loaded() {
|
|
13
|
+
return this._status === "loaded";
|
|
14
|
+
}
|
|
15
|
+
constructor(family, source) {
|
|
16
|
+
this.family = family;
|
|
17
|
+
this.source = source;
|
|
18
|
+
}
|
|
19
|
+
async load() {
|
|
20
|
+
try {
|
|
21
|
+
this._status = "loading";
|
|
22
|
+
if (typeof this.source === 'string') {
|
|
23
|
+
this.source = await Tools.LoadFileAsync(this.source);
|
|
24
|
+
}
|
|
25
|
+
await _native.Canvas.loadTTFAsync(this.family, this.source);
|
|
26
|
+
this.source = undefined;
|
|
27
|
+
this._status = "loaded";
|
|
28
|
+
}
|
|
29
|
+
catch (ex) {
|
|
30
|
+
console.error("Error encountered when loading font: " + ex);
|
|
31
|
+
this._status = "error";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=FontFace.js.map
|
package/FontFace.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FontFace.js","sourceRoot":"","sources":["../../Modules/@babylonjs/react-native/FontFace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAKxC;;GAEG;AACH,MAAM,OAAO,QAAQ;IAWgB;IAV3B,MAAM,CAAmC;IACzC,OAAO,GAAgD,UAAU,CAAC;IAC1E,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC;IACnC,CAAC;IAED,YAAmC,MAAc,EAAE,MAA4B;QAA5C,WAAM,GAAN,MAAM,CAAQ;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,IAAI;YACF,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YACzB,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE;gBACnC,IAAI,CAAC,MAAM,GAAG,MAAM,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aACtD;YAED,MAAM,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC5D,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAA;SACxB;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,CAAC,KAAK,CAAC,uCAAuC,GAAG,EAAE,CAAC,CAAC;YAC5D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACxB;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Camera } from '@babylonjs/core';
|
|
2
|
+
export declare type CapturedFrame = {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
format: "RGBA8" | "BGRA8" | undefined;
|
|
6
|
+
yFlip: boolean;
|
|
7
|
+
data: ArrayBuffer;
|
|
8
|
+
};
|
|
9
|
+
export declare type CaptureCallback = (capture: CapturedFrame) => void;
|
|
10
|
+
export declare class CaptureSession {
|
|
11
|
+
private readonly nativeCapture;
|
|
12
|
+
constructor(camera: Camera | undefined, onCaptureCallback: CaptureCallback);
|
|
13
|
+
dispose(): void;
|
|
14
|
+
}
|
package/NativeCapture.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
;
|
|
2
|
+
export class CaptureSession {
|
|
3
|
+
nativeCapture;
|
|
4
|
+
constructor(camera, onCaptureCallback) {
|
|
5
|
+
console.warn(`CaptureSession is experimental and likely to change significantly.`);
|
|
6
|
+
// HACK: There is no exposed way to access the frame buffer from render target texture
|
|
7
|
+
this.nativeCapture = new NativeCapture(camera?.outputRenderTarget?.renderTarget?._framebuffer);
|
|
8
|
+
this.nativeCapture.addCallback(onCaptureCallback);
|
|
9
|
+
}
|
|
10
|
+
dispose() {
|
|
11
|
+
this.nativeCapture.dispose();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=NativeCapture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeCapture.js","sourceRoot":"","sources":["../../Modules/@babylonjs/react-native/NativeCapture.ts"],"names":[],"mappings":"AAgBC,CAAC;AAEF,MAAM,OAAO,cAAc;IACN,aAAa,CAAgB;IAE9C,YAAmB,MAA0B,EAAE,iBAAkC;QAC7E,OAAO,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;QACnF,sFAAsF;QACtF,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAE,MAAM,EAAE,kBAAkB,EAAE,YAAoB,EAAE,YAAY,CAAC,CAAC;QACxG,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;IACtD,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;CACJ"}
|
package/README.md
CHANGED
|
@@ -18,14 +18,6 @@ The minimum Android SDK version is 18. This must be set as `minSdkVersion` in th
|
|
|
18
18
|
|
|
19
19
|
The minimum deployment target version is 12. This must be set as `iOS Deployment Target` in the consuming project's `project.pbxproj`, and must also be set as `platform` in the consuming project's `podfile`.
|
|
20
20
|
|
|
21
|
-
When running from XCode (with the debugger attached), `API Metal Validation` must be disabled:
|
|
22
|
-
|
|
23
|
-
1. From within XCode, select from the main menu `Product -> Scheme -> Edit Scheme...`
|
|
24
|
-
1. Ensure the target for your app is selected in the upper left corner of the window.
|
|
25
|
-
1. Select `Run` from the scheme list.
|
|
26
|
-
1. Select the `Options` tab.
|
|
27
|
-
1. Change `API Metal Validation` to `Disabled`.
|
|
28
|
-
|
|
29
21
|
### Universal Windows Platform (UWP) Configuration
|
|
30
22
|
|
|
31
23
|
For windows support, install `@babylonjs/react-native-windows`.
|
|
@@ -84,4 +76,12 @@ const MyComponent: FunctionComponent<MyComponentProps> = (props: MyComponentProp
|
|
|
84
76
|
}
|
|
85
77
|
```
|
|
86
78
|
|
|
79
|
+
Also the `EngineView` has a boolean `isTransparent` flag which defines whether the background of the scene should be transparent or not.
|
|
80
|
+
|
|
81
|
+
e.g.
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
<EngineView style={{flex: 1}} camera={camera} isTransparent={true} />
|
|
85
|
+
```
|
|
86
|
+
|
|
87
87
|
Note: Currently only one `EngineView` can be active at any given time. Multi-view will be supported in a future release.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NativeEngine } from '@babylonjs/core';
|
|
2
|
+
export declare class ReactNativeEngine extends NativeEngine {
|
|
3
|
+
private _isDisposed;
|
|
4
|
+
static tryCreateAsync(abortSignal: AbortSignal): Promise<ReactNativeEngine | null>;
|
|
5
|
+
get isDisposed(): boolean;
|
|
6
|
+
dispose(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ensureInitialized, reset } from './BabylonModule';
|
|
2
|
+
import { NativeEngine } from '@babylonjs/core';
|
|
3
|
+
export class ReactNativeEngine extends NativeEngine {
|
|
4
|
+
_isDisposed = false;
|
|
5
|
+
static async tryCreateAsync(abortSignal) {
|
|
6
|
+
if (!await ensureInitialized() || abortSignal.aborted) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
// This waits Graphics/NativeEngine to be created.
|
|
10
|
+
await BabylonNative.initializationPromise;
|
|
11
|
+
// Check for cancellation.
|
|
12
|
+
if (abortSignal.aborted) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return new ReactNativeEngine();
|
|
16
|
+
}
|
|
17
|
+
get isDisposed() {
|
|
18
|
+
return this._isDisposed;
|
|
19
|
+
}
|
|
20
|
+
dispose() {
|
|
21
|
+
if (!this.isDisposed) {
|
|
22
|
+
super.dispose();
|
|
23
|
+
// Ideally we would always do a reset here as we don't want different behavior between debug and release. Unfortunately, fast refresh has some strange behavior that
|
|
24
|
+
// makes it quite difficult to get this to work correctly (e.g. it re-runs previous useEffect instances, which means it can try to use Babylon Native in a de-initialized state).
|
|
25
|
+
// TODO: https://github.com/BabylonJS/BabylonReactNative/issues/125
|
|
26
|
+
if (!__DEV__) {
|
|
27
|
+
reset();
|
|
28
|
+
}
|
|
29
|
+
this._isDisposed = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ReactNativeEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactNativeEngine.js","sourceRoot":"","sources":["../../Modules/@babylonjs/react-native/ReactNativeEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAS/C,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IACvC,WAAW,GAAG,KAAK,CAAC;IAErB,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,WAAwB;QACvD,IAAI,CAAC,MAAM,iBAAiB,EAAE,IAAI,WAAW,CAAC,OAAO,EAAE;YACnD,OAAO,IAAI,CAAC;SACf;QAED,kDAAkD;QAClD,MAAM,aAAa,CAAC,qBAAqB,CAAC;QAE1C,0BAA0B;QAC1B,IAAI,WAAW,CAAC,OAAO,EAAE;YACrB,OAAO,IAAI,CAAC;SACf;QAED,OAAO,IAAI,iBAAiB,EAAE,CAAC;IACnC,CAAC;IAED,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAClB,KAAK,CAAC,OAAO,EAAE,CAAC;YAEhB,oKAAoK;YACpK,iLAAiL;YACjL,mEAAmE;YACnE,IAAI,CAAC,OAAO,EAAE;gBACV,KAAK,EAAE,CAAC;aACX;YAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;SAC3B;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Engine } from '@babylonjs/core';
|
|
2
|
-
import { satisfies, minVersion } from 'semver'
|
|
2
|
+
import { satisfies, minVersion } from 'semver';
|
|
3
3
|
import packageDefinition from './package.json';
|
|
4
|
-
|
|
5
4
|
if (__DEV__) {
|
|
6
5
|
const babylonJSPackageName = "@babylonjs/core";
|
|
7
6
|
const requiredVersion = packageDefinition.peerDependencies[babylonJSPackageName];
|
|
@@ -10,4 +9,5 @@ if (__DEV__) {
|
|
|
10
9
|
if (!satisfies(currentVersion, requiredVersion)) {
|
|
11
10
|
console.error(`${packageDefinition.name}@${packageDefinition.version} requires ${babylonJSPackageName}@${requiredVersion} but version ${currentVersion} is currently installed. Run 'npm install ${babylonJSPackageName}@${minRequiredVersion}' in your app's root directory to upgrade.`);
|
|
12
11
|
}
|
|
13
|
-
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=VersionValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VersionValidation.js","sourceRoot":"","sources":["../../Modules/@babylonjs/react-native/VersionValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAC9C,OAAO,iBAAiB,MAAM,gBAAgB,CAAC;AAE/C,IAAI,OAAO,EAAE;IACT,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;IAC/C,MAAM,eAAe,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;IACjF,MAAM,kBAAkB,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IACvD,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC;IACtC,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,eAAe,CAAC,EAAE;QAC7C,OAAO,CAAC,KAAK,CAAC,GAAG,iBAAiB,CAAC,IAAI,IAAI,iBAAiB,CAAC,OAAO,aAAa,oBAAoB,IAAI,eAAe,gBAAgB,cAAc,6CAA6C,oBAAoB,IAAI,kBAAkB,4CAA4C,CAAC,CAAC;KAC9R;CACJ"}
|
package/android/build.gradle
CHANGED
|
@@ -19,6 +19,10 @@ def safeExtGet(prop, fallback) {
|
|
|
19
19
|
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
def reactProperties = new Properties()
|
|
23
|
+
file("$projectDir/../../../react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
|
24
|
+
def REACT_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
|
|
25
|
+
|
|
22
26
|
apply plugin: 'com.android.library'
|
|
23
27
|
apply plugin: 'maven'
|
|
24
28
|
|
|
@@ -59,6 +63,14 @@ android {
|
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
|
|
66
|
+
// The full/real version of libturbomodulejsijni.so will be built and included in apps using React Native 0.64 or newer,
|
|
67
|
+
// so exclude Babylon React Native's minimal version of these libs in this case.
|
|
68
|
+
if (REACT_VERSION >= 64) {
|
|
69
|
+
android.packagingOptions.excludes += 'lib/armeabi-v7a/libturbomodulejsijni.so'
|
|
70
|
+
android.packagingOptions.excludes += 'lib/arm64-v8a/libturbomodulejsijni.so'
|
|
71
|
+
android.packagingOptions.excludes += 'lib/x86/libturbomodulejsijni.so'
|
|
72
|
+
}
|
|
73
|
+
|
|
62
74
|
repositories {
|
|
63
75
|
// ref: https://www.baeldung.com/maven-local-repository
|
|
64
76
|
mavenLocal()
|
|
@@ -77,7 +89,7 @@ repositories {
|
|
|
77
89
|
dependencies {
|
|
78
90
|
//noinspection GradleDynamicVersion
|
|
79
91
|
implementation 'com.facebook.react:react-native:+' // From node_modules
|
|
80
|
-
implementation 'com.google.ar:core:1.
|
|
92
|
+
implementation 'com.google.ar:core:1.22.0'
|
|
81
93
|
}
|
|
82
94
|
|
|
83
95
|
def configureReactNativePom(def pom) {
|
|
@@ -27,9 +27,11 @@ public final class BabylonModule extends ReactContextBaseJavaModule {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
@ReactMethod
|
|
31
|
+
public void resetView(Promise promise) {
|
|
32
|
+
this.getReactApplicationContext().runOnUiQueueThread(() -> {
|
|
33
|
+
BabylonNativeInterop.resetView();
|
|
34
|
+
promise.resolve(null);
|
|
35
|
+
});
|
|
34
36
|
}
|
|
35
37
|
}
|