@react-three/fiber 8.0.7 → 8.0.10

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.
@@ -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-e42f8ac9.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-e42f8ac9.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-91152509.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-91152509.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
@@ -64,79 +66,54 @@ function createTouchEvents(store) {
64
66
  }), {}),
65
67
  connect: () => {
66
68
  const {
67
- setEvents,
69
+ set,
68
70
  events
69
71
  } = store.getState();
70
72
  events.disconnect == null ? void 0 : events.disconnect();
71
73
  const connected = new Pressability(events == null ? void 0 : events.handlers);
72
- setEvents({
73
- connected
74
- });
74
+ set(state => ({
75
+ events: { ...state.events,
76
+ connected
77
+ }
78
+ }));
75
79
  const handlers = connected.getEventHandlers();
76
80
  return handlers;
77
81
  },
78
82
  disconnect: () => {
79
83
  const {
80
- setEvents,
84
+ set,
81
85
  events
82
86
  } = store.getState();
83
87
 
84
88
  if (events.connected) {
85
89
  events.connected.reset();
86
- setEvents({
87
- connected: undefined
88
- });
90
+ set(state => ({
91
+ events: { ...state.events,
92
+ connected: undefined
93
+ }
94
+ }));
89
95
  }
90
96
  }
91
97
  };
92
98
  }
93
99
 
94
100
  const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
95
-
96
- function Block({
97
- set
98
- }) {
99
- React.useLayoutEffect(() => {
100
- set(new Promise(() => null));
101
- return () => set(false);
102
- }, [set]);
103
- return null;
104
- }
105
-
106
- class ErrorBoundary extends React.Component {
107
- constructor(...args) {
108
- super(...args);
109
- this.state = {
110
- error: false
111
- };
112
- }
113
-
114
- componentDidCatch(error) {
115
- this.props.set(error);
116
- }
117
-
118
- render() {
119
- return this.state.error ? null : this.props.children;
120
- }
121
-
122
- }
123
-
124
- ErrorBoundary.getDerivedStateFromError = () => ({
125
- error: true
126
- });
101
+ /**
102
+ * A native canvas which accepts threejs elements as children.
103
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
104
+ */
127
105
 
128
106
  const Canvas = /*#__PURE__*/React.forwardRef(({
129
107
  children,
130
- fallback,
131
108
  style,
132
109
  events,
110
+ onPointerMissed,
133
111
  ...props
134
112
  }, forwardedRef) => {
135
113
  // Create a known catalogue of Threejs-native elements
136
114
  // This will include the entire THREE namespace by default, users can extend
137
115
  // their own elements by using the createRoot API instead
138
116
  React.useMemo(() => extend(THREE), []);
139
- const onPointerMissed = useMemoizedFn(props.onPointerMissed);
140
117
  const [{
141
118
  width,
142
119
  height
@@ -146,12 +123,9 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
146
123
  });
147
124
  const [canvas, setCanvas] = React.useState(null);
148
125
  const [bind, setBind] = React.useState();
149
- const canvasProps = pick({ ...props,
150
- onPointerMissed
151
- }, CANVAS_PROPS);
152
- const viewProps = omit({ ...props,
153
- onPointerMissed
154
- }, CANVAS_PROPS);
126
+ const handlePointerMissed = useMutableCallback(onPointerMissed);
127
+ const canvasProps = pick(props, CANVAS_PROPS);
128
+ const viewProps = omit(props, CANVAS_PROPS);
155
129
  const [block, setBlock] = React.useState(false);
156
130
  const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
157
131
 
@@ -203,6 +177,8 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
203
177
  };
204
178
 
205
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),
206
182
  // expo-gl can only render at native dpr/resolution
207
183
  // https://github.com/expo/expo-three/issues/39
208
184
  dpr: PixelRatio.get(),
@@ -223,7 +199,9 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
223
199
  }
224
200
 
225
201
  React.useEffect(() => {
226
- return () => unmountComponentAtNode(canvas);
202
+ if (canvas) {
203
+ return () => unmountComponentAtNode(canvas);
204
+ }
227
205
  }, [canvas]);
228
206
  return /*#__PURE__*/React.createElement(View, _extends({}, viewProps, {
229
207
  ref: mergeRefs([viewRef, forwardedRef]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.0.7",
3
+ "version": "8.0.10",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",