@react-three/fiber 8.0.6 → 8.0.9

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-0076cbd6.cjs.dev.js');
7
+ var index = require('../../dist/index-49237346.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');
@@ -62,6 +62,8 @@ const DOM_EVENTS = {
62
62
  [EVENTS.HOVEROUT]: 'onPointerOut',
63
63
  [EVENTS.PRESSMOVE]: 'onPointerMove'
64
64
  };
65
+ /** Default R3F event manager for react-native */
66
+
65
67
  function createTouchEvents(store) {
66
68
  const {
67
69
  handlePointer
@@ -126,51 +128,22 @@ function createTouchEvents(store) {
126
128
  }
127
129
 
128
130
  const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
129
-
130
- function Block({
131
- set
132
- }) {
133
- React__namespace.useLayoutEffect(() => {
134
- set(new Promise(() => null));
135
- return () => set(false);
136
- }, [set]);
137
- return null;
138
- }
139
-
140
- class ErrorBoundary extends React__namespace.Component {
141
- constructor(...args) {
142
- super(...args);
143
- this.state = {
144
- error: false
145
- };
146
- }
147
-
148
- componentDidCatch(error) {
149
- this.props.set(error);
150
- }
151
-
152
- render() {
153
- return this.state.error ? null : this.props.children;
154
- }
155
-
156
- }
157
-
158
- ErrorBoundary.getDerivedStateFromError = () => ({
159
- error: true
160
- });
131
+ /**
132
+ * A native canvas which accepts threejs elements as children.
133
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
134
+ */
161
135
 
162
136
  const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
163
137
  children,
164
- fallback,
165
138
  style,
166
139
  events,
140
+ onPointerMissed,
167
141
  ...props
168
142
  }, forwardedRef) => {
169
143
  // Create a known catalogue of Threejs-native elements
170
144
  // This will include the entire THREE namespace by default, users can extend
171
145
  // their own elements by using the createRoot API instead
172
146
  React__namespace.useMemo(() => index.extend(THREE__namespace), []);
173
- const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
174
147
  const [{
175
148
  width,
176
149
  height
@@ -180,12 +153,9 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
180
153
  });
181
154
  const [canvas, setCanvas] = React__namespace.useState(null);
182
155
  const [bind, setBind] = React__namespace.useState();
183
- const canvasProps = index.pick({ ...props,
184
- onPointerMissed
185
- }, CANVAS_PROPS);
186
- const viewProps = index.omit({ ...props,
187
- onPointerMissed
188
- }, CANVAS_PROPS);
156
+ const handlePointerMissed = index.useMutableCallback(onPointerMissed);
157
+ const canvasProps = index.pick(props, CANVAS_PROPS);
158
+ const viewProps = index.omit(props, CANVAS_PROPS);
189
159
  const [block, setBlock] = React__namespace.useState(false);
190
160
  const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
191
161
 
@@ -237,6 +207,8 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
237
207
  };
238
208
 
239
209
  root.current.configure({ ...canvasProps,
210
+ // Pass mutable reference to onPointerMissed so it's free to update
211
+ onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
240
212
  // expo-gl can only render at native dpr/resolution
241
213
  // https://github.com/expo/expo-three/issues/39
242
214
  dpr: reactNative.PixelRatio.get(),
@@ -247,10 +219,10 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
247
219
  events: events || createTouchEvents,
248
220
  onCreated
249
221
  });
250
- root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
222
+ root.current.render( /*#__PURE__*/React__namespace.createElement(index.ErrorBoundary, {
251
223
  set: setError
252
224
  }, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
253
- fallback: /*#__PURE__*/React__namespace.createElement(Block, {
225
+ fallback: /*#__PURE__*/React__namespace.createElement(index.Block, {
254
226
  set: setBlock
255
227
  })
256
228
  }, children)));
@@ -258,7 +230,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
258
230
 
259
231
  React__namespace.useEffect(() => {
260
232
  return () => index.unmountComponentAtNode(canvas);
261
- }, [canvas]);
233
+ }, []);
262
234
  return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, viewProps, {
263
235
  ref: mergeRefs__default['default']([viewRef, forwardedRef]),
264
236
  onLayout: onLayout,
@@ -376,7 +348,6 @@ exports.unmountComponentAtNode = index.unmountComponentAtNode;
376
348
  exports.useFrame = index.useFrame;
377
349
  exports.useGraph = index.useGraph;
378
350
  exports.useLoader = index.useLoader;
379
- exports.useMemoizedFn = index.useMemoizedFn;
380
351
  exports.useStore = index.useStore;
381
352
  exports.useThree = index.useThree;
382
353
  exports.Canvas = Canvas;
@@ -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-0e758026.cjs.prod.js');
7
+ var index = require('../../dist/index-4dae9cc6.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');
@@ -62,6 +62,8 @@ const DOM_EVENTS = {
62
62
  [EVENTS.HOVEROUT]: 'onPointerOut',
63
63
  [EVENTS.PRESSMOVE]: 'onPointerMove'
64
64
  };
65
+ /** Default R3F event manager for react-native */
66
+
65
67
  function createTouchEvents(store) {
66
68
  const {
67
69
  handlePointer
@@ -126,51 +128,22 @@ function createTouchEvents(store) {
126
128
  }
127
129
 
128
130
  const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
129
-
130
- function Block({
131
- set
132
- }) {
133
- React__namespace.useLayoutEffect(() => {
134
- set(new Promise(() => null));
135
- return () => set(false);
136
- }, [set]);
137
- return null;
138
- }
139
-
140
- class ErrorBoundary extends React__namespace.Component {
141
- constructor(...args) {
142
- super(...args);
143
- this.state = {
144
- error: false
145
- };
146
- }
147
-
148
- componentDidCatch(error) {
149
- this.props.set(error);
150
- }
151
-
152
- render() {
153
- return this.state.error ? null : this.props.children;
154
- }
155
-
156
- }
157
-
158
- ErrorBoundary.getDerivedStateFromError = () => ({
159
- error: true
160
- });
131
+ /**
132
+ * A native canvas which accepts threejs elements as children.
133
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
134
+ */
161
135
 
162
136
  const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
163
137
  children,
164
- fallback,
165
138
  style,
166
139
  events,
140
+ onPointerMissed,
167
141
  ...props
168
142
  }, forwardedRef) => {
169
143
  // Create a known catalogue of Threejs-native elements
170
144
  // This will include the entire THREE namespace by default, users can extend
171
145
  // their own elements by using the createRoot API instead
172
146
  React__namespace.useMemo(() => index.extend(THREE__namespace), []);
173
- const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
174
147
  const [{
175
148
  width,
176
149
  height
@@ -180,12 +153,9 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
180
153
  });
181
154
  const [canvas, setCanvas] = React__namespace.useState(null);
182
155
  const [bind, setBind] = React__namespace.useState();
183
- const canvasProps = index.pick({ ...props,
184
- onPointerMissed
185
- }, CANVAS_PROPS);
186
- const viewProps = index.omit({ ...props,
187
- onPointerMissed
188
- }, CANVAS_PROPS);
156
+ const handlePointerMissed = index.useMutableCallback(onPointerMissed);
157
+ const canvasProps = index.pick(props, CANVAS_PROPS);
158
+ const viewProps = index.omit(props, CANVAS_PROPS);
189
159
  const [block, setBlock] = React__namespace.useState(false);
190
160
  const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
191
161
 
@@ -237,6 +207,8 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
237
207
  };
238
208
 
239
209
  root.current.configure({ ...canvasProps,
210
+ // Pass mutable reference to onPointerMissed so it's free to update
211
+ onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
240
212
  // expo-gl can only render at native dpr/resolution
241
213
  // https://github.com/expo/expo-three/issues/39
242
214
  dpr: reactNative.PixelRatio.get(),
@@ -247,10 +219,10 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
247
219
  events: events || createTouchEvents,
248
220
  onCreated
249
221
  });
250
- root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
222
+ root.current.render( /*#__PURE__*/React__namespace.createElement(index.ErrorBoundary, {
251
223
  set: setError
252
224
  }, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
253
- fallback: /*#__PURE__*/React__namespace.createElement(Block, {
225
+ fallback: /*#__PURE__*/React__namespace.createElement(index.Block, {
254
226
  set: setBlock
255
227
  })
256
228
  }, children)));
@@ -258,7 +230,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
258
230
 
259
231
  React__namespace.useEffect(() => {
260
232
  return () => index.unmountComponentAtNode(canvas);
261
- }, [canvas]);
233
+ }, []);
262
234
  return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, viewProps, {
263
235
  ref: mergeRefs__default['default']([viewRef, forwardedRef]),
264
236
  onLayout: onLayout,
@@ -376,7 +348,6 @@ exports.unmountComponentAtNode = index.unmountComponentAtNode;
376
348
  exports.useFrame = index.useFrame;
377
349
  exports.useGraph = index.useGraph;
378
350
  exports.useLoader = index.useLoader;
379
- exports.useMemoizedFn = index.useMemoizedFn;
380
351
  exports.useStore = index.useStore;
381
352
  exports.useThree = index.useThree;
382
353
  exports.Canvas = Canvas;
@@ -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, b as unmountComponentAtNode } from '../../dist/index-91900b41.esm.js';
4
- export { t as ReactThreeFiber, v as _roots, s as act, m as addAfterEffect, l as addEffect, n as addTail, k as advance, h as applyProps, d as context, f as createPortal, a as createRoot, i as dispose, e as extend, q as getRootState, j as invalidate, g as reconciler, r as render, b as unmountComponentAtNode, y as useFrame, z as useGraph, A as useLoader, u as useMemoizedFn, w as useStore, x as useThree } from '../../dist/index-91900b41.esm.js';
3
+ import { c as createEvents, e as extend, u as useMutableCallback, p as pick, o as omit, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-4e14a95b.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-4e14a95b.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';
@@ -32,6 +32,8 @@ const DOM_EVENTS = {
32
32
  [EVENTS.HOVEROUT]: 'onPointerOut',
33
33
  [EVENTS.PRESSMOVE]: 'onPointerMove'
34
34
  };
35
+ /** Default R3F event manager for react-native */
36
+
35
37
  function createTouchEvents(store) {
36
38
  const {
37
39
  handlePointer
@@ -96,51 +98,22 @@ function createTouchEvents(store) {
96
98
  }
97
99
 
98
100
  const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
99
-
100
- function Block({
101
- set
102
- }) {
103
- React.useLayoutEffect(() => {
104
- set(new Promise(() => null));
105
- return () => set(false);
106
- }, [set]);
107
- return null;
108
- }
109
-
110
- class ErrorBoundary extends React.Component {
111
- constructor(...args) {
112
- super(...args);
113
- this.state = {
114
- error: false
115
- };
116
- }
117
-
118
- componentDidCatch(error) {
119
- this.props.set(error);
120
- }
121
-
122
- render() {
123
- return this.state.error ? null : this.props.children;
124
- }
125
-
126
- }
127
-
128
- ErrorBoundary.getDerivedStateFromError = () => ({
129
- error: true
130
- });
101
+ /**
102
+ * A native canvas which accepts threejs elements as children.
103
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
104
+ */
131
105
 
132
106
  const Canvas = /*#__PURE__*/React.forwardRef(({
133
107
  children,
134
- fallback,
135
108
  style,
136
109
  events,
110
+ onPointerMissed,
137
111
  ...props
138
112
  }, forwardedRef) => {
139
113
  // Create a known catalogue of Threejs-native elements
140
114
  // This will include the entire THREE namespace by default, users can extend
141
115
  // their own elements by using the createRoot API instead
142
116
  React.useMemo(() => extend(THREE), []);
143
- const onPointerMissed = useMemoizedFn(props.onPointerMissed);
144
117
  const [{
145
118
  width,
146
119
  height
@@ -150,12 +123,9 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
150
123
  });
151
124
  const [canvas, setCanvas] = React.useState(null);
152
125
  const [bind, setBind] = React.useState();
153
- const canvasProps = pick({ ...props,
154
- onPointerMissed
155
- }, CANVAS_PROPS);
156
- const viewProps = omit({ ...props,
157
- onPointerMissed
158
- }, CANVAS_PROPS);
126
+ const handlePointerMissed = useMutableCallback(onPointerMissed);
127
+ const canvasProps = pick(props, CANVAS_PROPS);
128
+ const viewProps = omit(props, CANVAS_PROPS);
159
129
  const [block, setBlock] = React.useState(false);
160
130
  const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
161
131
 
@@ -207,6 +177,8 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
207
177
  };
208
178
 
209
179
  root.current.configure({ ...canvasProps,
180
+ // Pass mutable reference to onPointerMissed so it's free to update
181
+ onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
210
182
  // expo-gl can only render at native dpr/resolution
211
183
  // https://github.com/expo/expo-three/issues/39
212
184
  dpr: PixelRatio.get(),
@@ -228,7 +200,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
228
200
 
229
201
  React.useEffect(() => {
230
202
  return () => unmountComponentAtNode(canvas);
231
- }, [canvas]);
203
+ }, []);
232
204
  return /*#__PURE__*/React.createElement(View, _extends({}, viewProps, {
233
205
  ref: mergeRefs([viewRef, forwardedRef]),
234
206
  onLayout: onLayout,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.0.6",
3
+ "version": "8.0.9",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",