Skip to content

Commit b481f2c

Browse files
authored
Minor fixes in preparation for packaging (#16)
This change includes a handful of fixes that prepare the repo for packaging and publishing react-native-babylon. In its initial form, this will be as source, where the consuming project compiles the linked projects.
1 parent 392cde5 commit b481f2c

File tree

4 files changed

+92
-14
lines changed

4 files changed

+92
-14
lines changed

Apps/Playground/node_modules/react-native-babylon/.npmignore

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Apps/Playground/node_modules/react-native-babylon/android/build.gradle

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Apps/Playground/node_modules/react-native-babylon/package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,35 @@ Babylon React Native is in the early phase of its development, and has the follo
1313

1414
This quick overview will help you understand the constructs provided by Babylon React Native and how to use them in a React Native application. See the Playground app's [App.tsx](Apps/Playground/App.tsx) for example usage.
1515

16+
### Dependencies
17+
18+
This package has several **peer dependencies**. If these dependencies are unmet, `react-native` will emit warnings. Be sure to add these dependencies to your project.
19+
20+
### C++ Build Requirements
21+
22+
This package includes C++ source, so platform specific tooling to build C++ code must be installed.
23+
24+
### Android Requirements
25+
26+
The minimum Android SDK version is 24. This must be set as `minSdkVersion` in the consuming project's `build.gradle` file.
27+
1628
### `useEngine`
1729

18-
`useEngine` is a **custom React hook** that manages the lifecycle of a Babylon engine instance in the context of an owning React component. A callback is passed to `useEngine` that receives an engine instance which is used to create and configure scenes. For example:
30+
`useEngine` is a **custom React hook** that manages the lifecycle of a Babylon engine instance in the context of an owning React component. `useEngine` creates an engine instance **asynchronously** which is used to create and configure scenes. Typically scene initialization code should exist in a `useEffect` triggered by an `engine` state change. For example:
1931

2032
```tsx
2133
import { useEngine } from 'react-native-babylon';
2234
import { Engine, Scene } from '@babylonjs/core';
2335

2436
const MyComponent: FunctionComponent<MyComponentProps> = (props: MyComponentProps) => {
25-
useEngine((engine: Engine) => {
26-
const scene = new Scene(engine);
27-
// Setup the scene!
28-
});
37+
const engine = useEngine();
38+
39+
useEffect(() => {
40+
if (engine) {
41+
const scene = new Scene(engine);
42+
// Setup the scene!
43+
}
44+
}, [engine]);
2945

3046
return (
3147
<>
@@ -43,16 +59,19 @@ import { useEngine, EngineView } from 'react-native-babylon';
4359
import { Engine, Scene, Camera } from '@babylonjs/core';
4460

4561
const MyComponent: FunctionComponent<MyComponentProps> = (props: MyComponentProps) => {
62+
const engine = useEngine();
4663
const [camera, setCamera] = useState<Camera>();
4764

48-
useEngine((engine: Engine) => {
49-
const scene = new Scene(engine);
50-
scene.createDefaultCamera(true);
51-
if (scene.activeCamera) {
52-
setCamera(scene.activeCamera);
65+
useEffect(() => {
66+
if (engine) {
67+
const scene = new Scene(engine);
68+
scene.createDefaultCamera(true);
69+
if (scene.activeCamera) {
70+
setCamera(scene.activeCamera);
71+
}
72+
// Setup the scene!
5373
}
54-
// Setup the scene!
55-
});
74+
}, [engine]);
5675

5776
return (
5877
<>

0 commit comments

Comments
 (0)