-
Notifications
You must be signed in to change notification settings - Fork 68
Converge react native integration layers across platforms #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
3b28873
First pass, iOS only
ryantrem 0d33202
Don't even initialize Babylon Native if we have remote debugging enabled
ryantrem 722e908
First pass cleanup
ryantrem 06f26e8
JS cleanup
ryantrem 8c9f977
Remove comments and logs
ryantrem fd28325
Remove dead code
ryantrem f65336c
Convert BabylonReactNative shared lib to just a shared CMakeLists.txt…
ryantrem 209f2d3
Move shared code
ryantrem 2d54fdc
Update Android to use shared code
ryantrem 6690729
Cleanup and queue updateView on JS thread
ryantrem f56d5e9
Fix crash when toggling engine screen off from XR and then toggling e…
ryantrem 1701e2d
Ensure UpdateView is called after Initialize (from the JS side)
ryantrem 2aeb5d2
Minor cleanup
ryantrem 17111f2
Fix package build
ryantrem 9f34496
Remove unused decl of jsCallInvoker
ryantrem e13f54c
Remove old setJSThread stuff from EngineView.tsx
ryantrem 895e0c9
std::move jsCallInvoker in dispatcher
ryantrem 6031d69
Remove use of getActionButton, which is only available in API levle 2…
ryantrem d34d0db
Add ReactNativeEngine
ryantrem bbe9e60
Address feedback on C++ side
ryantrem 9a8e53b
Move ReactNativeEngine to its own file and clean it up more
ryantrem cc32e2d
Add ReactNativeEngine to package
ryantrem 8c9848c
Switch from CallInvoker to a Dispatcher function since on UWP CallInv…
ryantrem 9d351b7
Fix bad import
ryantrem 100f491
Merge master
ryantrem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,24 @@ | ||
| import { NativeModules } from 'react-native'; | ||
| import { NativeEngine } from '@babylonjs/core'; | ||
|
|
||
| // This global object is part of Babylon Native. | ||
| declare const _native: { | ||
| whenGraphicsReady: () => Promise<void>; | ||
| engineInstance: NativeEngine; | ||
| } | ||
| declare const global: { | ||
| nativeCallSyncHook: any; | ||
| }; | ||
| const isRemoteDebuggingEnabled = !global.nativeCallSyncHook; | ||
|
|
||
| const NativeBabylonModule: { | ||
| initialize(): Promise<boolean>; | ||
| whenInitialized(): Promise<boolean>; | ||
| reset(): Promise<boolean>; | ||
| // This legacy React Native module is created by Babylon React Native, and is only used to bootstrap the JSI object creation. | ||
| // This will likely be removed when the BabylonNative global object is eventually converted to a TurboModule. | ||
| const BabylonModule: { | ||
| initialize(): Promise<void>; | ||
| } = NativeModules.BabylonModule; | ||
|
|
||
| export const BabylonModule = { | ||
| initialize: async () => { | ||
| const initialized = await NativeBabylonModule.initialize(); | ||
| if (initialized) { | ||
| await _native.whenGraphicsReady(); | ||
| } | ||
| return initialized; | ||
| }, | ||
|
|
||
| whenInitialized: NativeBabylonModule.whenInitialized, | ||
| reset: NativeBabylonModule.reset, | ||
|
|
||
| createEngine: () => { | ||
| const engine = new NativeEngine(); | ||
| _native.engineInstance = engine; | ||
| return engine; | ||
| export async function ensureInitialized(): Promise<boolean> { | ||
| if (isRemoteDebuggingEnabled) { | ||
| // When remote debugging is enabled, JavaScript runs on the debugging host machine, not on the device where the app is running. | ||
| // 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. | ||
| return false; | ||
| } else { | ||
| // This does the first stage of Babylon Native initialization, including creating the BabylonNative JSI object. | ||
| await BabylonModule.initialize(); | ||
| return true; | ||
| } | ||
| }; | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { ensureInitialized } from './BabylonModule'; | ||
| import { NativeEngine } from '@babylonjs/core'; | ||
|
|
||
| // This global object is owned by Babylon Native. | ||
| declare const _native: { | ||
| whenGraphicsReady: () => Promise<void>; | ||
| }; | ||
|
|
||
| // This JSI-based global object is owned by Babylon React Native. | ||
| // This will likely be converted to a TurboModule when they are fully supported. | ||
| declare const BabylonNative: { | ||
| readonly initializationPromise: Promise<void>; | ||
| setEngineInstance: (engine: NativeEngine | null) => void; | ||
| reset: () => void; | ||
| }; | ||
|
|
||
| export class ReactNativeEngine extends NativeEngine { | ||
| private _isDisposed = false; | ||
|
|
||
| private constructor() { | ||
| super(); | ||
| BabylonNative.setEngineInstance(this); | ||
| } | ||
|
|
||
| public static async tryCreateAsync(abortSignal: AbortSignal): Promise<ReactNativeEngine | null> { | ||
| if (!await ensureInitialized() || abortSignal.aborted) { | ||
| return null; | ||
| } | ||
|
|
||
| // This waits Graphics/NativeEngine to be created (which in turn makes the whenGraphicsReady available). | ||
| await BabylonNative.initializationPromise; | ||
|
|
||
| // Check for cancellation. | ||
| if (abortSignal.aborted) { | ||
| return null; | ||
| } | ||
|
|
||
| // This waits for the Graphics system to be up and running. | ||
| await _native.whenGraphicsReady(); | ||
|
|
||
| // Check for cancellation. | ||
| if (abortSignal.aborted) { | ||
| return null; | ||
| } | ||
|
|
||
| return new ReactNativeEngine(); | ||
| } | ||
|
|
||
| public get isDisposed() { | ||
| return this._isDisposed; | ||
| } | ||
|
|
||
| public dispose(): void { | ||
| if (!this.isDisposed) { | ||
| super.dispose(); | ||
|
|
||
| // 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 | ||
| // 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). | ||
| // TODO: https://github.com/BabylonJS/BabylonReactNative/issues/125 | ||
| if (!__DEV__) { | ||
| BabylonNative.reset(); | ||
| } | ||
|
|
||
| this._isDisposed = true; | ||
| } | ||
|
|
||
| BabylonNative.setEngineInstance(null); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.