@react-three/fiber 8.0.8 → 8.0.11

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.
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var THREE = require('three');
6
6
  var expoAsset = require('expo-asset');
7
- var index = require('../../dist/index-b8ee55f0.cjs.dev.js');
7
+ var index = require('../../dist/index-f7939a95.cjs.dev.js');
8
8
  var _extends = require('@babel/runtime/helpers/extends');
9
9
  var React = require('react');
10
10
  var mergeRefs = require('react-merge-refs');
@@ -127,23 +127,32 @@ function createTouchEvents(store) {
127
127
  };
128
128
  }
129
129
 
130
- const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
131
130
  /**
132
131
  * A native canvas which accepts threejs elements as children.
133
132
  * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
134
133
  */
135
-
136
134
  const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
137
135
  children,
138
136
  style,
139
- events,
137
+ gl,
138
+ events = createTouchEvents,
139
+ shadows,
140
+ linear,
141
+ flat,
142
+ legacy,
143
+ orthographic,
144
+ frameloop,
145
+ performance,
146
+ raycaster,
147
+ camera,
148
+ onPointerMissed,
149
+ onCreated,
140
150
  ...props
141
151
  }, forwardedRef) => {
142
152
  // Create a known catalogue of Threejs-native elements
143
153
  // This will include the entire THREE namespace by default, users can extend
144
154
  // their own elements by using the createRoot API instead
145
155
  React__namespace.useMemo(() => index.extend(THREE__namespace), []);
146
- const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
147
156
  const [{
148
157
  width,
149
158
  height
@@ -153,12 +162,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
153
162
  });
154
163
  const [canvas, setCanvas] = React__namespace.useState(null);
155
164
  const [bind, setBind] = React__namespace.useState();
156
- const canvasProps = index.pick({ ...props,
157
- onPointerMissed
158
- }, CANVAS_PROPS);
159
- const viewProps = index.omit({ ...props,
160
- onPointerMissed
161
- }, CANVAS_PROPS);
165
+ const handlePointerMissed = index.useMutableCallback(onPointerMissed);
162
166
  const [block, setBlock] = React__namespace.useState(false);
163
167
  const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
164
168
 
@@ -191,25 +195,19 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
191
195
  }, []);
192
196
 
193
197
  if (width > 0 && height > 0 && canvas) {
194
- if (!root.current) root.current = index.createRoot(canvas); // Overwrite onCreated to apply RN bindings
195
-
196
- const onCreated = state => {
197
- // Bind events after creation
198
- const handlers = state.events.connect == null ? void 0 : state.events.connect(viewRef.current);
199
- setBind(handlers); // Bind render to RN bridge
200
-
201
- const context = state.gl.getContext();
202
- const renderFrame = state.gl.render.bind(state.gl);
203
-
204
- state.gl.render = (scene, camera) => {
205
- renderFrame(scene, camera);
206
- context.endFrameEXP();
207
- };
208
-
209
- return canvasProps == null ? void 0 : canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
210
- };
211
-
212
- root.current.configure({ ...canvasProps,
198
+ if (!root.current) root.current = index.createRoot(canvas);
199
+ root.current.configure({
200
+ gl,
201
+ events,
202
+ shadows,
203
+ linear,
204
+ flat,
205
+ legacy,
206
+ orthographic,
207
+ frameloop,
208
+ performance,
209
+ raycaster,
210
+ camera,
213
211
  // expo-gl can only render at native dpr/resolution
214
212
  // https://github.com/expo/expo-three/issues/39
215
213
  dpr: reactNative.PixelRatio.get(),
@@ -217,8 +215,24 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
217
215
  width,
218
216
  height
219
217
  },
220
- events: events || createTouchEvents,
221
- onCreated
218
+ // Pass mutable reference to onPointerMissed so it's free to update
219
+ onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
220
+ // Overwrite onCreated to apply RN bindings
221
+ onCreated: state => {
222
+ // Bind events after creation
223
+ const handlers = state.events.connect == null ? void 0 : state.events.connect(viewRef.current);
224
+ setBind(handlers); // Bind render to RN bridge
225
+
226
+ const context = state.gl.getContext();
227
+ const renderFrame = state.gl.render.bind(state.gl);
228
+
229
+ state.gl.render = (scene, camera) => {
230
+ renderFrame(scene, camera);
231
+ context.endFrameEXP();
232
+ };
233
+
234
+ return onCreated == null ? void 0 : onCreated(state);
235
+ }
222
236
  });
223
237
  root.current.render( /*#__PURE__*/React__namespace.createElement(index.ErrorBoundary, {
224
238
  set: setError
@@ -230,9 +244,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
230
244
  }
231
245
 
232
246
  React__namespace.useEffect(() => {
233
- return () => index.unmountComponentAtNode(canvas);
247
+ if (canvas) {
248
+ return () => index.unmountComponentAtNode(canvas);
249
+ }
234
250
  }, [canvas]);
235
- return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, viewProps, {
251
+ return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, props, {
236
252
  ref: mergeRefs__default['default']([viewRef, forwardedRef]),
237
253
  onLayout: onLayout,
238
254
  style: {
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var THREE = require('three');
6
6
  var expoAsset = require('expo-asset');
7
- var index = require('../../dist/index-c4e0ac66.cjs.prod.js');
7
+ var index = require('../../dist/index-e936c560.cjs.prod.js');
8
8
  var _extends = require('@babel/runtime/helpers/extends');
9
9
  var React = require('react');
10
10
  var mergeRefs = require('react-merge-refs');
@@ -127,23 +127,32 @@ function createTouchEvents(store) {
127
127
  };
128
128
  }
129
129
 
130
- const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
131
130
  /**
132
131
  * A native canvas which accepts threejs elements as children.
133
132
  * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
134
133
  */
135
-
136
134
  const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
137
135
  children,
138
136
  style,
139
- events,
137
+ gl,
138
+ events = createTouchEvents,
139
+ shadows,
140
+ linear,
141
+ flat,
142
+ legacy,
143
+ orthographic,
144
+ frameloop,
145
+ performance,
146
+ raycaster,
147
+ camera,
148
+ onPointerMissed,
149
+ onCreated,
140
150
  ...props
141
151
  }, forwardedRef) => {
142
152
  // Create a known catalogue of Threejs-native elements
143
153
  // This will include the entire THREE namespace by default, users can extend
144
154
  // their own elements by using the createRoot API instead
145
155
  React__namespace.useMemo(() => index.extend(THREE__namespace), []);
146
- const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
147
156
  const [{
148
157
  width,
149
158
  height
@@ -153,12 +162,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
153
162
  });
154
163
  const [canvas, setCanvas] = React__namespace.useState(null);
155
164
  const [bind, setBind] = React__namespace.useState();
156
- const canvasProps = index.pick({ ...props,
157
- onPointerMissed
158
- }, CANVAS_PROPS);
159
- const viewProps = index.omit({ ...props,
160
- onPointerMissed
161
- }, CANVAS_PROPS);
165
+ const handlePointerMissed = index.useMutableCallback(onPointerMissed);
162
166
  const [block, setBlock] = React__namespace.useState(false);
163
167
  const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
164
168
 
@@ -191,25 +195,19 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
191
195
  }, []);
192
196
 
193
197
  if (width > 0 && height > 0 && canvas) {
194
- if (!root.current) root.current = index.createRoot(canvas); // Overwrite onCreated to apply RN bindings
195
-
196
- const onCreated = state => {
197
- // Bind events after creation
198
- const handlers = state.events.connect == null ? void 0 : state.events.connect(viewRef.current);
199
- setBind(handlers); // Bind render to RN bridge
200
-
201
- const context = state.gl.getContext();
202
- const renderFrame = state.gl.render.bind(state.gl);
203
-
204
- state.gl.render = (scene, camera) => {
205
- renderFrame(scene, camera);
206
- context.endFrameEXP();
207
- };
208
-
209
- return canvasProps == null ? void 0 : canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
210
- };
211
-
212
- root.current.configure({ ...canvasProps,
198
+ if (!root.current) root.current = index.createRoot(canvas);
199
+ root.current.configure({
200
+ gl,
201
+ events,
202
+ shadows,
203
+ linear,
204
+ flat,
205
+ legacy,
206
+ orthographic,
207
+ frameloop,
208
+ performance,
209
+ raycaster,
210
+ camera,
213
211
  // expo-gl can only render at native dpr/resolution
214
212
  // https://github.com/expo/expo-three/issues/39
215
213
  dpr: reactNative.PixelRatio.get(),
@@ -217,8 +215,24 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
217
215
  width,
218
216
  height
219
217
  },
220
- events: events || createTouchEvents,
221
- onCreated
218
+ // Pass mutable reference to onPointerMissed so it's free to update
219
+ onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
220
+ // Overwrite onCreated to apply RN bindings
221
+ onCreated: state => {
222
+ // Bind events after creation
223
+ const handlers = state.events.connect == null ? void 0 : state.events.connect(viewRef.current);
224
+ setBind(handlers); // Bind render to RN bridge
225
+
226
+ const context = state.gl.getContext();
227
+ const renderFrame = state.gl.render.bind(state.gl);
228
+
229
+ state.gl.render = (scene, camera) => {
230
+ renderFrame(scene, camera);
231
+ context.endFrameEXP();
232
+ };
233
+
234
+ return onCreated == null ? void 0 : onCreated(state);
235
+ }
222
236
  });
223
237
  root.current.render( /*#__PURE__*/React__namespace.createElement(index.ErrorBoundary, {
224
238
  set: setError
@@ -230,9 +244,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
230
244
  }
231
245
 
232
246
  React__namespace.useEffect(() => {
233
- return () => index.unmountComponentAtNode(canvas);
247
+ if (canvas) {
248
+ return () => index.unmountComponentAtNode(canvas);
249
+ }
234
250
  }, [canvas]);
235
- return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, viewProps, {
251
+ return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, props, {
236
252
  ref: mergeRefs__default['default']([viewRef, forwardedRef]),
237
253
  onLayout: onLayout,
238
254
  style: {
@@ -1,7 +1,7 @@
1
1
  import * as THREE from 'three';
2
2
  import { Asset } from 'expo-asset';
3
- import { c as createEvents, e as extend, u as useMemoizedFn, p as pick, o as omit, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-548cf96a.esm.js';
4
- export { t as ReactThreeFiber, w as _roots, v as act, n as addAfterEffect, m as addEffect, q as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, s as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, z as useFrame, A as useGraph, C as useLoader, x as useStore, y as useThree } from '../../dist/index-548cf96a.esm.js';
3
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-3c7aae97.esm.js';
4
+ export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from '../../dist/index-3c7aae97.esm.js';
5
5
  import _extends from '@babel/runtime/helpers/esm/extends';
6
6
  import * as React from 'react';
7
7
  import mergeRefs from 'react-merge-refs';
@@ -97,23 +97,32 @@ function createTouchEvents(store) {
97
97
  };
98
98
  }
99
99
 
100
- const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
101
100
  /**
102
101
  * A native canvas which accepts threejs elements as children.
103
102
  * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
104
103
  */
105
-
106
104
  const Canvas = /*#__PURE__*/React.forwardRef(({
107
105
  children,
108
106
  style,
109
- events,
107
+ gl,
108
+ events = createTouchEvents,
109
+ shadows,
110
+ linear,
111
+ flat,
112
+ legacy,
113
+ orthographic,
114
+ frameloop,
115
+ performance,
116
+ raycaster,
117
+ camera,
118
+ onPointerMissed,
119
+ onCreated,
110
120
  ...props
111
121
  }, forwardedRef) => {
112
122
  // Create a known catalogue of Threejs-native elements
113
123
  // This will include the entire THREE namespace by default, users can extend
114
124
  // their own elements by using the createRoot API instead
115
125
  React.useMemo(() => extend(THREE), []);
116
- const onPointerMissed = useMemoizedFn(props.onPointerMissed);
117
126
  const [{
118
127
  width,
119
128
  height
@@ -123,12 +132,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
123
132
  });
124
133
  const [canvas, setCanvas] = React.useState(null);
125
134
  const [bind, setBind] = React.useState();
126
- const canvasProps = pick({ ...props,
127
- onPointerMissed
128
- }, CANVAS_PROPS);
129
- const viewProps = omit({ ...props,
130
- onPointerMissed
131
- }, CANVAS_PROPS);
135
+ const handlePointerMissed = useMutableCallback(onPointerMissed);
132
136
  const [block, setBlock] = React.useState(false);
133
137
  const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
134
138
 
@@ -161,25 +165,19 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
161
165
  }, []);
162
166
 
163
167
  if (width > 0 && height > 0 && canvas) {
164
- if (!root.current) root.current = createRoot(canvas); // Overwrite onCreated to apply RN bindings
165
-
166
- const onCreated = state => {
167
- // Bind events after creation
168
- const handlers = state.events.connect == null ? void 0 : state.events.connect(viewRef.current);
169
- setBind(handlers); // Bind render to RN bridge
170
-
171
- const context = state.gl.getContext();
172
- const renderFrame = state.gl.render.bind(state.gl);
173
-
174
- state.gl.render = (scene, camera) => {
175
- renderFrame(scene, camera);
176
- context.endFrameEXP();
177
- };
178
-
179
- return canvasProps == null ? void 0 : canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
180
- };
181
-
182
- root.current.configure({ ...canvasProps,
168
+ if (!root.current) root.current = createRoot(canvas);
169
+ root.current.configure({
170
+ gl,
171
+ events,
172
+ shadows,
173
+ linear,
174
+ flat,
175
+ legacy,
176
+ orthographic,
177
+ frameloop,
178
+ performance,
179
+ raycaster,
180
+ camera,
183
181
  // expo-gl can only render at native dpr/resolution
184
182
  // https://github.com/expo/expo-three/issues/39
185
183
  dpr: PixelRatio.get(),
@@ -187,8 +185,24 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
187
185
  width,
188
186
  height
189
187
  },
190
- events: events || createTouchEvents,
191
- onCreated
188
+ // Pass mutable reference to onPointerMissed so it's free to update
189
+ onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
190
+ // Overwrite onCreated to apply RN bindings
191
+ onCreated: state => {
192
+ // Bind events after creation
193
+ const handlers = state.events.connect == null ? void 0 : state.events.connect(viewRef.current);
194
+ setBind(handlers); // Bind render to RN bridge
195
+
196
+ const context = state.gl.getContext();
197
+ const renderFrame = state.gl.render.bind(state.gl);
198
+
199
+ state.gl.render = (scene, camera) => {
200
+ renderFrame(scene, camera);
201
+ context.endFrameEXP();
202
+ };
203
+
204
+ return onCreated == null ? void 0 : onCreated(state);
205
+ }
192
206
  });
193
207
  root.current.render( /*#__PURE__*/React.createElement(ErrorBoundary, {
194
208
  set: setError
@@ -200,9 +214,11 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
200
214
  }
201
215
 
202
216
  React.useEffect(() => {
203
- return () => unmountComponentAtNode(canvas);
217
+ if (canvas) {
218
+ return () => unmountComponentAtNode(canvas);
219
+ }
204
220
  }, [canvas]);
205
- return /*#__PURE__*/React.createElement(View, _extends({}, viewProps, {
221
+ return /*#__PURE__*/React.createElement(View, _extends({}, props, {
206
222
  ref: mergeRefs([viewRef, forwardedRef]),
207
223
  onLayout: onLayout,
208
224
  style: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.0.8",
3
+ "version": "8.0.11",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",