Skip to content
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

Add UWP support to BabylonReactNative #137

Merged
merged 80 commits into from
Jan 21, 2021

Conversation

chrisfromwork
Copy link
Contributor

@chrisfromwork chrisfromwork commented Jan 7, 2021

This pr adds support for react-native-windows. Instructions for building the react-native-windows babylon.js package can be found at Modules@babylonjs\react-native\windows\README.txt

Overview:

  • A CMakeLists.txt file has been added for the windows @babylonjs/react-native package that sets up BabylonNative dependencies, the react-native needed jsi project and a BabylonNative.lib that utilizes pre-existing BabylonReactNative BabylonNative initialization logic
  • We've updated BabylonNative.lib to expose the ability to specify a windowTypePtr. The windowTypePtr needs to be specified to use XAML SwapChainPanels when rendering
  • BabylonReactNative.dll has been added to the @babylonjs/react-native package to implement EngineView/EngineViewManager/BabylonModule native components
  • The Playground app has been updated to support react-native-windows scenarios
  • @react-native-community/slider has been updated to a newer version that supports react-native-windows
  • @react-native-permissions has been updated to a newer version that supports react-native-windows
  • react and react-native have been updated to versions that support react-native-windows
  • metro.config.js for the Playground app has been updated to exclude windows files that should not be bundled/deployed

TODOs:

  • Fix Slider logic/find a slider implementation that is supported on all platforms
  • Fix xr camera permissions logic. Permissions is not currently a supported react-native-windows native module
  • Refactor logic to support newer BabylonReactNative commits

Follow up issues to file:

@chrisfromwork chrisfromwork linked an issue Jan 19, 2021 that may be closed by this pull request
4 tasks
}
});

result.Resolve(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you didn't actually change it though?

winrt::event_token RenderingToken;
};
RevokerData _revokerData{};
winrt::BabylonReactNative::EngineView _engineView{ nullptr };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason this instance is stored is so that it can be replaced, which destroys the old one and unregisters events, right? If/when in the future we add support for multiple view instances, we'll have to update this, and probably do something more like the OnLoaded/OnUnloaded approach I mentioned, but I guess we can just do it this way for now and worry about fixing it up as needed in the future.

Copy link
Contributor Author

@chrisfromwork chrisfromwork Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we can refactor this as wanted. right now it seems like BabylonNative initialization is driven by the BabylonModule initialize call. I wasn't sure if we wanted the BabylonNative initialization/deinitialization to be driven by the SwapChainPanel OnLoaded/OnUnloaded.

FWIW, there are some lifecycle bugs floating around for UWP support. We can address these sorts of changes in these follow up fixes.

Comment on lines +43 to +51
const makeUWPProject = async () => {
exec('.\\..\\Modules\\@babylonjs\\react-native\\windows\\scripts\\Setup.bat');
}

const buildUWPProject = async () => {
exec('.\\..\\Modules\\@babylonjs\\react-native\\windows\\scripts\\Build.bat');
}

const buildUWP = gulp.series(makeUWPProject, buildUWPProject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today we run this gulp build on Mac agents so we can build both iOS and Android, which means this added stuff for UWP will break. I think we are going to need to rework this so that we build Android, iOS, and UWP on different build agents, publish the built stuff as artifacts, and then have a separate stage that pulls the artifacts and packages them all together into the NPM package. Maybe we just save the changes to gulpfile.js for a future PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that sounds good. I'll probably go ahead and add the buildUWP gulp task to the exports. But i agree it shouldn't be in the main build task.

Apps/Playground/App.tsx Outdated Show resolved Hide resolved
Co-authored-by: Ryan Tremblay <ryantrem@msn.com>
namespace winrt::BabylonReactNative::implementation {
EngineView::EngineView() {
_revokerData.SizeChangedRevoker = SizeChanged(winrt::auto_revoke, { this, &EngineView::OnSizeChanged });
_revokerData.PointerPressedRevoker = PointerPressed(winrt::auto_revoke, { this, &EngineView::OnPointerPressed });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For pointer events, rather than subscribing to the evented form, you should instead override the OnPointer* methods. These are invoked before the evented forms, and provide an option for suppressing the event from being raised (by setting the Handled property) in cases where that might not be valuable (think not raising PointerPressed for a button but instead a Click).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, I'll add this to the upcoming packaging review.

@chrisfromwork chrisfromwork merged commit bfaff66 into BabylonJS:master Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable react-native-windows support
3 participants