BabylonReactNative
BabylonReactNative copied to clipboard
Add React Native for macOS support.
Describe the change
We can now run BabylonReactNative on macOS.
plus additional class component support - Higher-order component withEngine
and Prop type for class WithEngineProps
added.
usage:
import React from 'react';
import { View } from 'react-native';
import { Camera, Scene } from '@babylonjs/core';
import { EngineView, withEngine, WithEngineProps } from '@babylonjs/react-native';
class App extends React.Component<WithEngineProps, { camera: Camera | undefined }> {
constructor(props: WithEngineProps) {
super(props);
this.state = { camera: undefined };
}
async componentDidMount() {
while (!this.props.engine) await new Promise((_: any) => setTimeout(_, 100));
const scene = new Scene(this.props.engine);
scene.createDefaultCamera(true);
const sphere = MeshBuilder.CreateSphere('sphere', { diameter: 1 }, scene);
const camera = scene.activeCamera!;
this.setState({ camera });
}
componentWillUnmount() { this.props.engine?.dispose(); }
render() {
return (
<View style={{ flex: 1 }}>
<EngineView style={{ flex: 1 }} camera={ this.state.camera } />
</View>
);
}
}
export default withEngine(App);
Screenshots
Documentation
Have you updated the documentation to reflect your changes? Yes
Testing
Have you tested the final iteration of your changes? Yes