@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.
- package/CHANGELOG.md +19 -1
- package/dist/declarations/src/core/hooks.d.ts +0 -4
- package/dist/declarations/src/core/index.d.ts +24 -6
- package/dist/declarations/src/core/store.d.ts +1 -20
- package/dist/declarations/src/core/utils.d.ts +29 -1
- package/dist/declarations/src/index.d.ts +3 -3
- package/dist/declarations/src/native/Canvas.d.ts +1 -6
- package/dist/declarations/src/native/events.d.ts +1 -2
- package/dist/declarations/src/native.d.ts +3 -3
- package/dist/declarations/src/three-types.d.ts +1 -0
- package/dist/declarations/src/web/Canvas.d.ts +1 -5
- package/dist/{index-75d39ab1.cjs.dev.js → index-018d2d45.cjs.dev.js} +176 -52
- package/dist/{index-e42f8ac9.esm.js → index-91152509.esm.js} +173 -52
- package/dist/{index-4fb4daff.cjs.prod.js → index-c8c0474b.cjs.prod.js} +176 -52
- package/dist/react-three-fiber.cjs.dev.js +30 -54
- package/dist/react-three-fiber.cjs.prod.js +30 -54
- package/dist/react-three-fiber.esm.js +29 -52
- package/native/dist/react-three-fiber-native.cjs.dev.js +30 -53
- package/native/dist/react-three-fiber-native.cjs.prod.js +30 -53
- package/native/dist/react-three-fiber-native.esm.js +29 -51
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-c8c0474b.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -53,6 +53,8 @@ const DOM_EVENTS = {
|
|
|
53
53
|
onPointerCancel: ['pointercancel', true],
|
|
54
54
|
onLostPointerCapture: ['lostpointercapture', true]
|
|
55
55
|
};
|
|
56
|
+
/** Default R3F event manager for web */
|
|
57
|
+
|
|
56
58
|
function createPointerEvents(store) {
|
|
57
59
|
const {
|
|
58
60
|
handlePointer
|
|
@@ -76,13 +78,15 @@ function createPointerEvents(store) {
|
|
|
76
78
|
var _events$handlers;
|
|
77
79
|
|
|
78
80
|
const {
|
|
79
|
-
|
|
81
|
+
set,
|
|
80
82
|
events
|
|
81
83
|
} = store.getState();
|
|
82
84
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
set(state => ({
|
|
86
|
+
events: { ...state.events,
|
|
87
|
+
connected: target
|
|
88
|
+
}
|
|
89
|
+
}));
|
|
86
90
|
Object.entries((_events$handlers = events == null ? void 0 : events.handlers) != null ? _events$handlers : []).forEach(([name, event]) => {
|
|
87
91
|
const [eventName, passive] = DOM_EVENTS[name];
|
|
88
92
|
target.addEventListener(eventName, event, {
|
|
@@ -92,7 +96,7 @@ function createPointerEvents(store) {
|
|
|
92
96
|
},
|
|
93
97
|
disconnect: () => {
|
|
94
98
|
const {
|
|
95
|
-
|
|
99
|
+
set,
|
|
96
100
|
events
|
|
97
101
|
} = store.getState();
|
|
98
102
|
|
|
@@ -105,53 +109,28 @@ function createPointerEvents(store) {
|
|
|
105
109
|
events.connected.removeEventListener(eventName, event);
|
|
106
110
|
}
|
|
107
111
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
set(state => ({
|
|
113
|
+
events: { ...state.events,
|
|
114
|
+
connected: undefined
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
};
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
React__namespace.useLayoutEffect(() => {
|
|
122
|
-
set(new Promise(() => null));
|
|
123
|
-
return () => set(false);
|
|
124
|
-
}, [set]);
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
class ErrorBoundary extends React__namespace.Component {
|
|
129
|
-
constructor(...args) {
|
|
130
|
-
super(...args);
|
|
131
|
-
this.state = {
|
|
132
|
-
error: false
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
componentDidCatch(error) {
|
|
137
|
-
this.props.set(error);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
render() {
|
|
141
|
-
return this.state.error ? null : this.props.children;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
147
|
-
error: true
|
|
148
|
-
});
|
|
123
|
+
/**
|
|
124
|
+
* A DOM canvas which accepts threejs elements as children.
|
|
125
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
126
|
+
*/
|
|
149
127
|
|
|
150
128
|
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
151
129
|
children,
|
|
152
130
|
fallback,
|
|
153
131
|
resize,
|
|
154
132
|
style,
|
|
133
|
+
onPointerMissed,
|
|
155
134
|
events = createPointerEvents,
|
|
156
135
|
...props
|
|
157
136
|
}, forwardedRef) {
|
|
@@ -159,7 +138,6 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
159
138
|
// This will include the entire THREE namespace by default, users can extend
|
|
160
139
|
// their own elements by using the createRoot API instead
|
|
161
140
|
React__namespace.useMemo(() => index.extend(THREE__namespace), []);
|
|
162
|
-
const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
|
|
163
141
|
const [containerRef, {
|
|
164
142
|
width,
|
|
165
143
|
height
|
|
@@ -171,15 +149,12 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
171
149
|
},
|
|
172
150
|
...resize
|
|
173
151
|
});
|
|
174
|
-
const meshRef = React__namespace.useRef(null);
|
|
175
152
|
const canvasRef = React__namespace.useRef(null);
|
|
153
|
+
const meshRef = React__namespace.useRef(null);
|
|
176
154
|
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const divProps = index.omit({ ...props,
|
|
181
|
-
onPointerMissed
|
|
182
|
-
}, CANVAS_PROPS);
|
|
155
|
+
const handlePointerMissed = index.useMutableCallback(onPointerMissed);
|
|
156
|
+
const canvasProps = index.pick(props, CANVAS_PROPS);
|
|
157
|
+
const divProps = index.omit(props, CANVAS_PROPS);
|
|
183
158
|
const [block, setBlock] = React__namespace.useState(false);
|
|
184
159
|
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
185
160
|
|
|
@@ -191,6 +166,8 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
191
166
|
if (width > 0 && height > 0 && canvas) {
|
|
192
167
|
if (!root.current) root.current = index.createRoot(canvas);
|
|
193
168
|
root.current.configure({ ...canvasProps,
|
|
169
|
+
// Pass mutable reference to onPointerMissed so it's free to update
|
|
170
|
+
onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
|
|
194
171
|
onCreated: state => {
|
|
195
172
|
state.events.connect == null ? void 0 : state.events.connect(meshRef.current);
|
|
196
173
|
canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
@@ -201,20 +178,20 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
201
178
|
},
|
|
202
179
|
events
|
|
203
180
|
});
|
|
204
|
-
root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
181
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(index.ErrorBoundary, {
|
|
205
182
|
set: setError
|
|
206
183
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
207
|
-
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
184
|
+
fallback: /*#__PURE__*/React__namespace.createElement(index.Block, {
|
|
208
185
|
set: setBlock
|
|
209
186
|
})
|
|
210
187
|
}, children)));
|
|
211
188
|
}
|
|
212
189
|
|
|
213
|
-
|
|
190
|
+
index.useIsomorphicLayoutEffect(() => {
|
|
214
191
|
setCanvas(canvasRef.current);
|
|
215
192
|
}, []);
|
|
216
193
|
React__namespace.useEffect(() => {
|
|
217
|
-
return () => index.unmountComponentAtNode(canvas);
|
|
194
|
+
if (canvas) return () => index.unmountComponentAtNode(canvas);
|
|
218
195
|
}, [canvas]);
|
|
219
196
|
return /*#__PURE__*/React__namespace.createElement("div", _extends({
|
|
220
197
|
ref: mergeRefs__default['default']([meshRef, containerRef]),
|
|
@@ -254,7 +231,6 @@ exports.unmountComponentAtNode = index.unmountComponentAtNode;
|
|
|
254
231
|
exports.useFrame = index.useFrame;
|
|
255
232
|
exports.useGraph = index.useGraph;
|
|
256
233
|
exports.useLoader = index.useLoader;
|
|
257
|
-
exports.useMemoizedFn = index.useMemoizedFn;
|
|
258
234
|
exports.useStore = index.useStore;
|
|
259
235
|
exports.useThree = index.useThree;
|
|
260
236
|
exports.Canvas = Canvas;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, u as
|
|
2
|
-
export { t as ReactThreeFiber,
|
|
1
|
+
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, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-91152509.esm.js';
|
|
2
|
+
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 './index-91152509.esm.js';
|
|
3
3
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import * as THREE from 'three';
|
|
@@ -23,6 +23,8 @@ const DOM_EVENTS = {
|
|
|
23
23
|
onPointerCancel: ['pointercancel', true],
|
|
24
24
|
onLostPointerCapture: ['lostpointercapture', true]
|
|
25
25
|
};
|
|
26
|
+
/** Default R3F event manager for web */
|
|
27
|
+
|
|
26
28
|
function createPointerEvents(store) {
|
|
27
29
|
const {
|
|
28
30
|
handlePointer
|
|
@@ -46,13 +48,15 @@ function createPointerEvents(store) {
|
|
|
46
48
|
var _events$handlers;
|
|
47
49
|
|
|
48
50
|
const {
|
|
49
|
-
|
|
51
|
+
set,
|
|
50
52
|
events
|
|
51
53
|
} = store.getState();
|
|
52
54
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
set(state => ({
|
|
56
|
+
events: { ...state.events,
|
|
57
|
+
connected: target
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
56
60
|
Object.entries((_events$handlers = events == null ? void 0 : events.handlers) != null ? _events$handlers : []).forEach(([name, event]) => {
|
|
57
61
|
const [eventName, passive] = DOM_EVENTS[name];
|
|
58
62
|
target.addEventListener(eventName, event, {
|
|
@@ -62,7 +66,7 @@ function createPointerEvents(store) {
|
|
|
62
66
|
},
|
|
63
67
|
disconnect: () => {
|
|
64
68
|
const {
|
|
65
|
-
|
|
69
|
+
set,
|
|
66
70
|
events
|
|
67
71
|
} = store.getState();
|
|
68
72
|
|
|
@@ -75,53 +79,28 @@ function createPointerEvents(store) {
|
|
|
75
79
|
events.connected.removeEventListener(eventName, event);
|
|
76
80
|
}
|
|
77
81
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
set(state => ({
|
|
83
|
+
events: { ...state.events,
|
|
84
|
+
connected: undefined
|
|
85
|
+
}
|
|
86
|
+
}));
|
|
81
87
|
}
|
|
82
88
|
}
|
|
83
89
|
};
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
React.useLayoutEffect(() => {
|
|
92
|
-
set(new Promise(() => null));
|
|
93
|
-
return () => set(false);
|
|
94
|
-
}, [set]);
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
class ErrorBoundary extends React.Component {
|
|
99
|
-
constructor(...args) {
|
|
100
|
-
super(...args);
|
|
101
|
-
this.state = {
|
|
102
|
-
error: false
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
componentDidCatch(error) {
|
|
107
|
-
this.props.set(error);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
render() {
|
|
111
|
-
return this.state.error ? null : this.props.children;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
117
|
-
error: true
|
|
118
|
-
});
|
|
93
|
+
/**
|
|
94
|
+
* A DOM canvas which accepts threejs elements as children.
|
|
95
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
96
|
+
*/
|
|
119
97
|
|
|
120
98
|
const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
121
99
|
children,
|
|
122
100
|
fallback,
|
|
123
101
|
resize,
|
|
124
102
|
style,
|
|
103
|
+
onPointerMissed,
|
|
125
104
|
events = createPointerEvents,
|
|
126
105
|
...props
|
|
127
106
|
}, forwardedRef) {
|
|
@@ -129,7 +108,6 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
129
108
|
// This will include the entire THREE namespace by default, users can extend
|
|
130
109
|
// their own elements by using the createRoot API instead
|
|
131
110
|
React.useMemo(() => extend(THREE), []);
|
|
132
|
-
const onPointerMissed = useMemoizedFn(props.onPointerMissed);
|
|
133
111
|
const [containerRef, {
|
|
134
112
|
width,
|
|
135
113
|
height
|
|
@@ -141,15 +119,12 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
141
119
|
},
|
|
142
120
|
...resize
|
|
143
121
|
});
|
|
144
|
-
const meshRef = React.useRef(null);
|
|
145
122
|
const canvasRef = React.useRef(null);
|
|
123
|
+
const meshRef = React.useRef(null);
|
|
146
124
|
const [canvas, setCanvas] = React.useState(null);
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const divProps = omit({ ...props,
|
|
151
|
-
onPointerMissed
|
|
152
|
-
}, CANVAS_PROPS);
|
|
125
|
+
const handlePointerMissed = useMutableCallback(onPointerMissed);
|
|
126
|
+
const canvasProps = pick(props, CANVAS_PROPS);
|
|
127
|
+
const divProps = omit(props, CANVAS_PROPS);
|
|
153
128
|
const [block, setBlock] = React.useState(false);
|
|
154
129
|
const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
155
130
|
|
|
@@ -161,6 +136,8 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
161
136
|
if (width > 0 && height > 0 && canvas) {
|
|
162
137
|
if (!root.current) root.current = createRoot(canvas);
|
|
163
138
|
root.current.configure({ ...canvasProps,
|
|
139
|
+
// Pass mutable reference to onPointerMissed so it's free to update
|
|
140
|
+
onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
|
|
164
141
|
onCreated: state => {
|
|
165
142
|
state.events.connect == null ? void 0 : state.events.connect(meshRef.current);
|
|
166
143
|
canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
@@ -180,11 +157,11 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
180
157
|
}, children)));
|
|
181
158
|
}
|
|
182
159
|
|
|
183
|
-
|
|
160
|
+
useIsomorphicLayoutEffect(() => {
|
|
184
161
|
setCanvas(canvasRef.current);
|
|
185
162
|
}, []);
|
|
186
163
|
React.useEffect(() => {
|
|
187
|
-
return () => unmountComponentAtNode(canvas);
|
|
164
|
+
if (canvas) return () => unmountComponentAtNode(canvas);
|
|
188
165
|
}, [canvas]);
|
|
189
166
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
190
167
|
ref: mergeRefs([meshRef, containerRef]),
|
|
@@ -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-
|
|
7
|
+
var index = require('../../dist/index-018d2d45.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
|
|
@@ -94,79 +96,54 @@ function createTouchEvents(store) {
|
|
|
94
96
|
}), {}),
|
|
95
97
|
connect: () => {
|
|
96
98
|
const {
|
|
97
|
-
|
|
99
|
+
set,
|
|
98
100
|
events
|
|
99
101
|
} = store.getState();
|
|
100
102
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
101
103
|
const connected = new Pressability__default['default'](events == null ? void 0 : events.handlers);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
set(state => ({
|
|
105
|
+
events: { ...state.events,
|
|
106
|
+
connected
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
105
109
|
const handlers = connected.getEventHandlers();
|
|
106
110
|
return handlers;
|
|
107
111
|
},
|
|
108
112
|
disconnect: () => {
|
|
109
113
|
const {
|
|
110
|
-
|
|
114
|
+
set,
|
|
111
115
|
events
|
|
112
116
|
} = store.getState();
|
|
113
117
|
|
|
114
118
|
if (events.connected) {
|
|
115
119
|
events.connected.reset();
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
set(state => ({
|
|
121
|
+
events: { ...state.events,
|
|
122
|
+
connected: undefined
|
|
123
|
+
}
|
|
124
|
+
}));
|
|
119
125
|
}
|
|
120
126
|
}
|
|
121
127
|
};
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
React__namespace.useLayoutEffect(() => {
|
|
130
|
-
set(new Promise(() => null));
|
|
131
|
-
return () => set(false);
|
|
132
|
-
}, [set]);
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
class ErrorBoundary extends React__namespace.Component {
|
|
137
|
-
constructor(...args) {
|
|
138
|
-
super(...args);
|
|
139
|
-
this.state = {
|
|
140
|
-
error: false
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
componentDidCatch(error) {
|
|
145
|
-
this.props.set(error);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
render() {
|
|
149
|
-
return this.state.error ? null : this.props.children;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
155
|
-
error: true
|
|
156
|
-
});
|
|
131
|
+
/**
|
|
132
|
+
* A native canvas which accepts threejs elements as children.
|
|
133
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
134
|
+
*/
|
|
157
135
|
|
|
158
136
|
const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
159
137
|
children,
|
|
160
|
-
fallback,
|
|
161
138
|
style,
|
|
162
139
|
events,
|
|
140
|
+
onPointerMissed,
|
|
163
141
|
...props
|
|
164
142
|
}, forwardedRef) => {
|
|
165
143
|
// Create a known catalogue of Threejs-native elements
|
|
166
144
|
// This will include the entire THREE namespace by default, users can extend
|
|
167
145
|
// their own elements by using the createRoot API instead
|
|
168
146
|
React__namespace.useMemo(() => index.extend(THREE__namespace), []);
|
|
169
|
-
const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
|
|
170
147
|
const [{
|
|
171
148
|
width,
|
|
172
149
|
height
|
|
@@ -176,12 +153,9 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
176
153
|
});
|
|
177
154
|
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
178
155
|
const [bind, setBind] = React__namespace.useState();
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const viewProps = index.omit({ ...props,
|
|
183
|
-
onPointerMissed
|
|
184
|
-
}, CANVAS_PROPS);
|
|
156
|
+
const handlePointerMissed = index.useMutableCallback(onPointerMissed);
|
|
157
|
+
const canvasProps = index.pick(props, CANVAS_PROPS);
|
|
158
|
+
const viewProps = index.omit(props, CANVAS_PROPS);
|
|
185
159
|
const [block, setBlock] = React__namespace.useState(false);
|
|
186
160
|
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
187
161
|
|
|
@@ -233,6 +207,8 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
233
207
|
};
|
|
234
208
|
|
|
235
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),
|
|
236
212
|
// expo-gl can only render at native dpr/resolution
|
|
237
213
|
// https://github.com/expo/expo-three/issues/39
|
|
238
214
|
dpr: reactNative.PixelRatio.get(),
|
|
@@ -243,17 +219,19 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
243
219
|
events: events || createTouchEvents,
|
|
244
220
|
onCreated
|
|
245
221
|
});
|
|
246
|
-
root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
222
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(index.ErrorBoundary, {
|
|
247
223
|
set: setError
|
|
248
224
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
249
|
-
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
225
|
+
fallback: /*#__PURE__*/React__namespace.createElement(index.Block, {
|
|
250
226
|
set: setBlock
|
|
251
227
|
})
|
|
252
228
|
}, children)));
|
|
253
229
|
}
|
|
254
230
|
|
|
255
231
|
React__namespace.useEffect(() => {
|
|
256
|
-
|
|
232
|
+
if (canvas) {
|
|
233
|
+
return () => index.unmountComponentAtNode(canvas);
|
|
234
|
+
}
|
|
257
235
|
}, [canvas]);
|
|
258
236
|
return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, viewProps, {
|
|
259
237
|
ref: mergeRefs__default['default']([viewRef, forwardedRef]),
|
|
@@ -372,7 +350,6 @@ exports.unmountComponentAtNode = index.unmountComponentAtNode;
|
|
|
372
350
|
exports.useFrame = index.useFrame;
|
|
373
351
|
exports.useGraph = index.useGraph;
|
|
374
352
|
exports.useLoader = index.useLoader;
|
|
375
|
-
exports.useMemoizedFn = index.useMemoizedFn;
|
|
376
353
|
exports.useStore = index.useStore;
|
|
377
354
|
exports.useThree = index.useThree;
|
|
378
355
|
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-
|
|
7
|
+
var index = require('../../dist/index-c8c0474b.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
|
|
@@ -94,79 +96,54 @@ function createTouchEvents(store) {
|
|
|
94
96
|
}), {}),
|
|
95
97
|
connect: () => {
|
|
96
98
|
const {
|
|
97
|
-
|
|
99
|
+
set,
|
|
98
100
|
events
|
|
99
101
|
} = store.getState();
|
|
100
102
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
101
103
|
const connected = new Pressability__default['default'](events == null ? void 0 : events.handlers);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
set(state => ({
|
|
105
|
+
events: { ...state.events,
|
|
106
|
+
connected
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
105
109
|
const handlers = connected.getEventHandlers();
|
|
106
110
|
return handlers;
|
|
107
111
|
},
|
|
108
112
|
disconnect: () => {
|
|
109
113
|
const {
|
|
110
|
-
|
|
114
|
+
set,
|
|
111
115
|
events
|
|
112
116
|
} = store.getState();
|
|
113
117
|
|
|
114
118
|
if (events.connected) {
|
|
115
119
|
events.connected.reset();
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
set(state => ({
|
|
121
|
+
events: { ...state.events,
|
|
122
|
+
connected: undefined
|
|
123
|
+
}
|
|
124
|
+
}));
|
|
119
125
|
}
|
|
120
126
|
}
|
|
121
127
|
};
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
React__namespace.useLayoutEffect(() => {
|
|
130
|
-
set(new Promise(() => null));
|
|
131
|
-
return () => set(false);
|
|
132
|
-
}, [set]);
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
class ErrorBoundary extends React__namespace.Component {
|
|
137
|
-
constructor(...args) {
|
|
138
|
-
super(...args);
|
|
139
|
-
this.state = {
|
|
140
|
-
error: false
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
componentDidCatch(error) {
|
|
145
|
-
this.props.set(error);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
render() {
|
|
149
|
-
return this.state.error ? null : this.props.children;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
155
|
-
error: true
|
|
156
|
-
});
|
|
131
|
+
/**
|
|
132
|
+
* A native canvas which accepts threejs elements as children.
|
|
133
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
134
|
+
*/
|
|
157
135
|
|
|
158
136
|
const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
159
137
|
children,
|
|
160
|
-
fallback,
|
|
161
138
|
style,
|
|
162
139
|
events,
|
|
140
|
+
onPointerMissed,
|
|
163
141
|
...props
|
|
164
142
|
}, forwardedRef) => {
|
|
165
143
|
// Create a known catalogue of Threejs-native elements
|
|
166
144
|
// This will include the entire THREE namespace by default, users can extend
|
|
167
145
|
// their own elements by using the createRoot API instead
|
|
168
146
|
React__namespace.useMemo(() => index.extend(THREE__namespace), []);
|
|
169
|
-
const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
|
|
170
147
|
const [{
|
|
171
148
|
width,
|
|
172
149
|
height
|
|
@@ -176,12 +153,9 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
176
153
|
});
|
|
177
154
|
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
178
155
|
const [bind, setBind] = React__namespace.useState();
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const viewProps = index.omit({ ...props,
|
|
183
|
-
onPointerMissed
|
|
184
|
-
}, CANVAS_PROPS);
|
|
156
|
+
const handlePointerMissed = index.useMutableCallback(onPointerMissed);
|
|
157
|
+
const canvasProps = index.pick(props, CANVAS_PROPS);
|
|
158
|
+
const viewProps = index.omit(props, CANVAS_PROPS);
|
|
185
159
|
const [block, setBlock] = React__namespace.useState(false);
|
|
186
160
|
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
187
161
|
|
|
@@ -233,6 +207,8 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
233
207
|
};
|
|
234
208
|
|
|
235
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),
|
|
236
212
|
// expo-gl can only render at native dpr/resolution
|
|
237
213
|
// https://github.com/expo/expo-three/issues/39
|
|
238
214
|
dpr: reactNative.PixelRatio.get(),
|
|
@@ -243,17 +219,19 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
243
219
|
events: events || createTouchEvents,
|
|
244
220
|
onCreated
|
|
245
221
|
});
|
|
246
|
-
root.current.render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
222
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(index.ErrorBoundary, {
|
|
247
223
|
set: setError
|
|
248
224
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
249
|
-
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
225
|
+
fallback: /*#__PURE__*/React__namespace.createElement(index.Block, {
|
|
250
226
|
set: setBlock
|
|
251
227
|
})
|
|
252
228
|
}, children)));
|
|
253
229
|
}
|
|
254
230
|
|
|
255
231
|
React__namespace.useEffect(() => {
|
|
256
|
-
|
|
232
|
+
if (canvas) {
|
|
233
|
+
return () => index.unmountComponentAtNode(canvas);
|
|
234
|
+
}
|
|
257
235
|
}, [canvas]);
|
|
258
236
|
return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, viewProps, {
|
|
259
237
|
ref: mergeRefs__default['default']([viewRef, forwardedRef]),
|
|
@@ -372,7 +350,6 @@ exports.unmountComponentAtNode = index.unmountComponentAtNode;
|
|
|
372
350
|
exports.useFrame = index.useFrame;
|
|
373
351
|
exports.useGraph = index.useGraph;
|
|
374
352
|
exports.useLoader = index.useLoader;
|
|
375
|
-
exports.useMemoizedFn = index.useMemoizedFn;
|
|
376
353
|
exports.useStore = index.useStore;
|
|
377
354
|
exports.useThree = index.useThree;
|
|
378
355
|
exports.Canvas = Canvas;
|