@react-three/fiber 8.10.0 → 8.10.2
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 +12 -0
- package/dist/{index-d957aeb6.cjs.prod.js → index-661b9d11.cjs.prod.js} +408 -503
- package/dist/{index-4ea38fa1.cjs.dev.js → index-bf8a2906.cjs.dev.js} +408 -503
- package/dist/{index-27a1523b.esm.js → index-fb77d67d.esm.js} +408 -503
- package/dist/react-three-fiber.cjs.dev.js +20 -23
- package/dist/react-three-fiber.cjs.prod.js +20 -23
- package/dist/react-three-fiber.esm.js +21 -24
- package/native/dist/react-three-fiber-native.cjs.dev.js +36 -44
- package/native/dist/react-three-fiber-native.cjs.prod.js +36 -44
- package/native/dist/react-three-fiber-native.esm.js +37 -45
- 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('../../dist/index-
|
|
5
|
+
var index = require('../../dist/index-661b9d11.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -60,36 +60,36 @@ const DOM_EVENTS = {
|
|
|
60
60
|
[EVENTS.HOVEROUT]: 'onPointerOut',
|
|
61
61
|
[EVENTS.PRESSMOVE]: 'onPointerMove'
|
|
62
62
|
};
|
|
63
|
-
/** Default R3F event manager for react-native */
|
|
64
63
|
|
|
64
|
+
/** Default R3F event manager for react-native */
|
|
65
65
|
function createTouchEvents(store) {
|
|
66
66
|
const {
|
|
67
67
|
handlePointer
|
|
68
68
|
} = index.createEvents(store);
|
|
69
|
-
|
|
70
69
|
const handleTouch = (event, name) => {
|
|
71
|
-
event.persist()
|
|
70
|
+
event.persist()
|
|
71
|
+
|
|
72
|
+
// Apply offset
|
|
72
73
|
;
|
|
73
74
|
event.nativeEvent.offsetX = event.nativeEvent.locationX;
|
|
74
|
-
event.nativeEvent.offsetY = event.nativeEvent.locationY;
|
|
75
|
+
event.nativeEvent.offsetY = event.nativeEvent.locationY;
|
|
75
76
|
|
|
77
|
+
// Emulate DOM event
|
|
76
78
|
const callback = handlePointer(DOM_EVENTS[name]);
|
|
77
79
|
return callback(event.nativeEvent);
|
|
78
80
|
};
|
|
79
|
-
|
|
80
81
|
return {
|
|
81
82
|
priority: 1,
|
|
82
83
|
enabled: true,
|
|
83
|
-
|
|
84
84
|
compute(event, state, previous) {
|
|
85
85
|
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
86
86
|
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
87
87
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
88
88
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
89
89
|
},
|
|
90
|
-
|
|
91
90
|
connected: undefined,
|
|
92
|
-
handlers: Object.values(EVENTS).reduce((acc, name) => ({
|
|
91
|
+
handlers: Object.values(EVENTS).reduce((acc, name) => ({
|
|
92
|
+
...acc,
|
|
93
93
|
[name]: event => handleTouch(event, name)
|
|
94
94
|
}), {}),
|
|
95
95
|
connect: () => {
|
|
@@ -100,7 +100,8 @@ function createTouchEvents(store) {
|
|
|
100
100
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
101
101
|
const connected = new Pressability__default["default"](events.handlers);
|
|
102
102
|
set(state => ({
|
|
103
|
-
events: {
|
|
103
|
+
events: {
|
|
104
|
+
...state.events,
|
|
104
105
|
connected
|
|
105
106
|
}
|
|
106
107
|
}));
|
|
@@ -112,11 +113,11 @@ function createTouchEvents(store) {
|
|
|
112
113
|
set,
|
|
113
114
|
events
|
|
114
115
|
} = store.getState();
|
|
115
|
-
|
|
116
116
|
if (events.connected) {
|
|
117
117
|
events.connected.reset();
|
|
118
118
|
set(state => ({
|
|
119
|
-
events: {
|
|
119
|
+
events: {
|
|
120
|
+
...state.events,
|
|
120
121
|
connected: undefined
|
|
121
122
|
}
|
|
122
123
|
}));
|
|
@@ -127,45 +128,39 @@ function createTouchEvents(store) {
|
|
|
127
128
|
|
|
128
129
|
// Check if expo-asset is installed (available with expo modules)
|
|
129
130
|
let expAsset;
|
|
130
|
-
|
|
131
131
|
try {
|
|
132
132
|
var _require;
|
|
133
|
-
|
|
134
133
|
expAsset = (_require = require('expo-asset')) == null ? void 0 : _require.Asset;
|
|
135
134
|
} catch (_) {}
|
|
135
|
+
|
|
136
136
|
/**
|
|
137
137
|
* Generates an asset based on input type.
|
|
138
138
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
139
|
function getAsset(input) {
|
|
142
140
|
switch (typeof input) {
|
|
143
141
|
case 'string':
|
|
144
142
|
return expAsset.fromURI(input);
|
|
145
|
-
|
|
146
143
|
case 'number':
|
|
147
144
|
return expAsset.fromModule(input);
|
|
148
|
-
|
|
149
145
|
default:
|
|
150
146
|
throw new Error('R3F: Invalid asset! Must be a URI or module.');
|
|
151
147
|
}
|
|
152
148
|
}
|
|
153
|
-
|
|
154
149
|
let injected = false;
|
|
155
150
|
function polyfills() {
|
|
156
151
|
if (!expAsset || injected) return;
|
|
157
|
-
injected = true;
|
|
152
|
+
injected = true;
|
|
158
153
|
|
|
154
|
+
// Don't pre-process urls, let expo-asset generate an absolute URL
|
|
159
155
|
const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
|
|
156
|
+
THREE__namespace.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './';
|
|
160
157
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
// There's no Image in native, so create a data texture instead
|
|
164
159
|
const prevTextureLoad = THREE__namespace.TextureLoader.prototype.load;
|
|
165
|
-
|
|
166
160
|
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
167
|
-
const texture = new THREE__namespace.Texture();
|
|
161
|
+
const texture = new THREE__namespace.Texture();
|
|
168
162
|
|
|
163
|
+
// @ts-ignore
|
|
169
164
|
texture.isDataTexture = true;
|
|
170
165
|
getAsset(url).downloadAsync().then(asset => {
|
|
171
166
|
texture.image = {
|
|
@@ -179,11 +174,10 @@ function polyfills() {
|
|
|
179
174
|
onLoad == null ? void 0 : onLoad(texture);
|
|
180
175
|
}).catch(onError);
|
|
181
176
|
return texture;
|
|
182
|
-
};
|
|
183
|
-
|
|
177
|
+
};
|
|
184
178
|
|
|
179
|
+
// Fetches assets via XMLHttpRequest
|
|
185
180
|
const prevFileLoad = THREE__namespace.FileLoader.prototype.load;
|
|
186
|
-
|
|
187
181
|
THREE__namespace.FileLoader.prototype.load = function (url, onLoad, onProgress, onError) {
|
|
188
182
|
if (this.path) url = this.path + url;
|
|
189
183
|
const request = new XMLHttpRequest();
|
|
@@ -214,18 +208,16 @@ function polyfills() {
|
|
|
214
208
|
}, false);
|
|
215
209
|
if (this.responseType) request.responseType = this.responseType;
|
|
216
210
|
if (this.withCredentials) request.withCredentials = this.withCredentials;
|
|
217
|
-
|
|
218
211
|
for (const header in this.requestHeader) {
|
|
219
212
|
request.setRequestHeader(header, this.requestHeader[header]);
|
|
220
213
|
}
|
|
221
|
-
|
|
222
214
|
request.send(null);
|
|
223
215
|
this.manager.itemStart(url);
|
|
224
216
|
});
|
|
225
217
|
return request;
|
|
226
|
-
};
|
|
227
|
-
|
|
218
|
+
};
|
|
228
219
|
|
|
220
|
+
// Cleanup function
|
|
229
221
|
return () => {
|
|
230
222
|
THREE__namespace.LoaderUtils.extractUrlBase = extractUrlBase;
|
|
231
223
|
THREE__namespace.TextureLoader.prototype.load = prevTextureLoad;
|
|
@@ -276,14 +268,16 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
276
268
|
React__namespace.useImperativeHandle(forwardedRef, () => viewRef.current);
|
|
277
269
|
const handlePointerMissed = index.useMutableCallback(onPointerMissed);
|
|
278
270
|
const [block, setBlock] = React__namespace.useState(false);
|
|
279
|
-
const [error, setError] = React__namespace.useState(undefined);
|
|
280
|
-
|
|
281
|
-
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
271
|
+
const [error, setError] = React__namespace.useState(undefined);
|
|
282
272
|
|
|
273
|
+
// Suspend this component if block is a promise (2nd run)
|
|
274
|
+
if (block) throw block;
|
|
275
|
+
// Throw exception outwards if anything within canvas throws
|
|
283
276
|
if (error) throw error;
|
|
284
277
|
const viewRef = React__namespace.useRef(null);
|
|
285
|
-
const root = React__namespace.useRef(null);
|
|
278
|
+
const root = React__namespace.useRef(null);
|
|
286
279
|
|
|
280
|
+
// Inject and cleanup RN polyfills if able
|
|
287
281
|
React__namespace.useLayoutEffect(() => polyfills(), []);
|
|
288
282
|
const onLayout = React__namespace.useCallback(e => {
|
|
289
283
|
const {
|
|
@@ -298,9 +292,10 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
298
292
|
top: y,
|
|
299
293
|
left: x
|
|
300
294
|
});
|
|
301
|
-
}, []);
|
|
302
|
-
// https://github.com/pmndrs/react-three-fiber/pull/2297
|
|
295
|
+
}, []);
|
|
303
296
|
|
|
297
|
+
// Called on context create or swap
|
|
298
|
+
// https://github.com/pmndrs/react-three-fiber/pull/2297
|
|
304
299
|
const onContextCreate = React__namespace.useCallback(context => {
|
|
305
300
|
const canvasShim = {
|
|
306
301
|
width: context.drawingBufferWidth,
|
|
@@ -314,7 +309,6 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
314
309
|
root.current = index.createRoot(canvasShim);
|
|
315
310
|
setCanvas(canvasShim);
|
|
316
311
|
}, []);
|
|
317
|
-
|
|
318
312
|
if (root.current && width > 0 && height > 0) {
|
|
319
313
|
root.current.configure({
|
|
320
314
|
gl,
|
|
@@ -343,16 +337,15 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
343
337
|
onCreated: state => {
|
|
344
338
|
// Bind events after creation
|
|
345
339
|
const handlers = state.events.connect == null ? void 0 : state.events.connect(viewRef.current);
|
|
346
|
-
setBind(handlers);
|
|
340
|
+
setBind(handlers);
|
|
347
341
|
|
|
342
|
+
// Bind render to RN bridge
|
|
348
343
|
const context = state.gl.getContext();
|
|
349
344
|
const renderFrame = state.gl.render.bind(state.gl);
|
|
350
|
-
|
|
351
345
|
state.gl.render = (scene, camera) => {
|
|
352
346
|
renderFrame(scene, camera);
|
|
353
347
|
context.endFrameEXP();
|
|
354
348
|
};
|
|
355
|
-
|
|
356
349
|
return onCreated == null ? void 0 : onCreated(state);
|
|
357
350
|
}
|
|
358
351
|
});
|
|
@@ -364,7 +357,6 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
364
357
|
})
|
|
365
358
|
}, children))));
|
|
366
359
|
}
|
|
367
|
-
|
|
368
360
|
React__namespace.useEffect(() => {
|
|
369
361
|
if (canvas) {
|
|
370
362
|
return () => index.unmountComponentAtNode(canvas);
|
|
@@ -382,11 +374,11 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
382
374
|
style: reactNative.StyleSheet.absoluteFill
|
|
383
375
|
}));
|
|
384
376
|
});
|
|
377
|
+
|
|
385
378
|
/**
|
|
386
379
|
* A native canvas which accepts threejs elements as children.
|
|
387
380
|
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
388
381
|
*/
|
|
389
|
-
|
|
390
382
|
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(props, ref) {
|
|
391
383
|
return /*#__PURE__*/React__namespace.createElement(itsFine.FiberProvider, null, /*#__PURE__*/React__namespace.createElement(CanvasImpl, _extends({}, props, {
|
|
392
384
|
ref: ref
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
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-
|
|
2
|
-
export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, a as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-
|
|
1
|
+
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-fb77d67d.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, a as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-fb77d67d.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';
|
|
@@ -33,36 +33,36 @@ const DOM_EVENTS = {
|
|
|
33
33
|
[EVENTS.HOVEROUT]: 'onPointerOut',
|
|
34
34
|
[EVENTS.PRESSMOVE]: 'onPointerMove'
|
|
35
35
|
};
|
|
36
|
-
/** Default R3F event manager for react-native */
|
|
37
36
|
|
|
37
|
+
/** Default R3F event manager for react-native */
|
|
38
38
|
function createTouchEvents(store) {
|
|
39
39
|
const {
|
|
40
40
|
handlePointer
|
|
41
41
|
} = createEvents(store);
|
|
42
|
-
|
|
43
42
|
const handleTouch = (event, name) => {
|
|
44
|
-
event.persist()
|
|
43
|
+
event.persist()
|
|
44
|
+
|
|
45
|
+
// Apply offset
|
|
45
46
|
;
|
|
46
47
|
event.nativeEvent.offsetX = event.nativeEvent.locationX;
|
|
47
|
-
event.nativeEvent.offsetY = event.nativeEvent.locationY;
|
|
48
|
+
event.nativeEvent.offsetY = event.nativeEvent.locationY;
|
|
48
49
|
|
|
50
|
+
// Emulate DOM event
|
|
49
51
|
const callback = handlePointer(DOM_EVENTS[name]);
|
|
50
52
|
return callback(event.nativeEvent);
|
|
51
53
|
};
|
|
52
|
-
|
|
53
54
|
return {
|
|
54
55
|
priority: 1,
|
|
55
56
|
enabled: true,
|
|
56
|
-
|
|
57
57
|
compute(event, state, previous) {
|
|
58
58
|
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
59
59
|
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
60
60
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
61
61
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
62
62
|
},
|
|
63
|
-
|
|
64
63
|
connected: undefined,
|
|
65
|
-
handlers: Object.values(EVENTS).reduce((acc, name) => ({
|
|
64
|
+
handlers: Object.values(EVENTS).reduce((acc, name) => ({
|
|
65
|
+
...acc,
|
|
66
66
|
[name]: event => handleTouch(event, name)
|
|
67
67
|
}), {}),
|
|
68
68
|
connect: () => {
|
|
@@ -73,7 +73,8 @@ function createTouchEvents(store) {
|
|
|
73
73
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
74
74
|
const connected = new Pressability(events.handlers);
|
|
75
75
|
set(state => ({
|
|
76
|
-
events: {
|
|
76
|
+
events: {
|
|
77
|
+
...state.events,
|
|
77
78
|
connected
|
|
78
79
|
}
|
|
79
80
|
}));
|
|
@@ -85,11 +86,11 @@ function createTouchEvents(store) {
|
|
|
85
86
|
set,
|
|
86
87
|
events
|
|
87
88
|
} = store.getState();
|
|
88
|
-
|
|
89
89
|
if (events.connected) {
|
|
90
90
|
events.connected.reset();
|
|
91
91
|
set(state => ({
|
|
92
|
-
events: {
|
|
92
|
+
events: {
|
|
93
|
+
...state.events,
|
|
93
94
|
connected: undefined
|
|
94
95
|
}
|
|
95
96
|
}));
|
|
@@ -100,45 +101,39 @@ function createTouchEvents(store) {
|
|
|
100
101
|
|
|
101
102
|
// Check if expo-asset is installed (available with expo modules)
|
|
102
103
|
let expAsset;
|
|
103
|
-
|
|
104
104
|
try {
|
|
105
105
|
var _require;
|
|
106
|
-
|
|
107
106
|
expAsset = (_require = require('expo-asset')) == null ? void 0 : _require.Asset;
|
|
108
107
|
} catch (_) {}
|
|
108
|
+
|
|
109
109
|
/**
|
|
110
110
|
* Generates an asset based on input type.
|
|
111
111
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
114
112
|
function getAsset(input) {
|
|
115
113
|
switch (typeof input) {
|
|
116
114
|
case 'string':
|
|
117
115
|
return expAsset.fromURI(input);
|
|
118
|
-
|
|
119
116
|
case 'number':
|
|
120
117
|
return expAsset.fromModule(input);
|
|
121
|
-
|
|
122
118
|
default:
|
|
123
119
|
throw new Error('R3F: Invalid asset! Must be a URI or module.');
|
|
124
120
|
}
|
|
125
121
|
}
|
|
126
|
-
|
|
127
122
|
let injected = false;
|
|
128
123
|
function polyfills() {
|
|
129
124
|
if (!expAsset || injected) return;
|
|
130
|
-
injected = true;
|
|
125
|
+
injected = true;
|
|
131
126
|
|
|
127
|
+
// Don't pre-process urls, let expo-asset generate an absolute URL
|
|
132
128
|
const extractUrlBase = THREE.LoaderUtils.extractUrlBase.bind(THREE.LoaderUtils);
|
|
129
|
+
THREE.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './';
|
|
133
130
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
// There's no Image in native, so create a data texture instead
|
|
137
132
|
const prevTextureLoad = THREE.TextureLoader.prototype.load;
|
|
138
|
-
|
|
139
133
|
THREE.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
140
|
-
const texture = new THREE.Texture();
|
|
134
|
+
const texture = new THREE.Texture();
|
|
141
135
|
|
|
136
|
+
// @ts-ignore
|
|
142
137
|
texture.isDataTexture = true;
|
|
143
138
|
getAsset(url).downloadAsync().then(asset => {
|
|
144
139
|
texture.image = {
|
|
@@ -152,11 +147,10 @@ function polyfills() {
|
|
|
152
147
|
onLoad == null ? void 0 : onLoad(texture);
|
|
153
148
|
}).catch(onError);
|
|
154
149
|
return texture;
|
|
155
|
-
};
|
|
156
|
-
|
|
150
|
+
};
|
|
157
151
|
|
|
152
|
+
// Fetches assets via XMLHttpRequest
|
|
158
153
|
const prevFileLoad = THREE.FileLoader.prototype.load;
|
|
159
|
-
|
|
160
154
|
THREE.FileLoader.prototype.load = function (url, onLoad, onProgress, onError) {
|
|
161
155
|
if (this.path) url = this.path + url;
|
|
162
156
|
const request = new XMLHttpRequest();
|
|
@@ -187,18 +181,16 @@ function polyfills() {
|
|
|
187
181
|
}, false);
|
|
188
182
|
if (this.responseType) request.responseType = this.responseType;
|
|
189
183
|
if (this.withCredentials) request.withCredentials = this.withCredentials;
|
|
190
|
-
|
|
191
184
|
for (const header in this.requestHeader) {
|
|
192
185
|
request.setRequestHeader(header, this.requestHeader[header]);
|
|
193
186
|
}
|
|
194
|
-
|
|
195
187
|
request.send(null);
|
|
196
188
|
this.manager.itemStart(url);
|
|
197
189
|
});
|
|
198
190
|
return request;
|
|
199
|
-
};
|
|
200
|
-
|
|
191
|
+
};
|
|
201
192
|
|
|
193
|
+
// Cleanup function
|
|
202
194
|
return () => {
|
|
203
195
|
THREE.LoaderUtils.extractUrlBase = extractUrlBase;
|
|
204
196
|
THREE.TextureLoader.prototype.load = prevTextureLoad;
|
|
@@ -249,14 +241,16 @@ const CanvasImpl = /*#__PURE__*/React.forwardRef(({
|
|
|
249
241
|
React.useImperativeHandle(forwardedRef, () => viewRef.current);
|
|
250
242
|
const handlePointerMissed = useMutableCallback(onPointerMissed);
|
|
251
243
|
const [block, setBlock] = React.useState(false);
|
|
252
|
-
const [error, setError] = React.useState(undefined);
|
|
253
|
-
|
|
254
|
-
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
244
|
+
const [error, setError] = React.useState(undefined);
|
|
255
245
|
|
|
246
|
+
// Suspend this component if block is a promise (2nd run)
|
|
247
|
+
if (block) throw block;
|
|
248
|
+
// Throw exception outwards if anything within canvas throws
|
|
256
249
|
if (error) throw error;
|
|
257
250
|
const viewRef = React.useRef(null);
|
|
258
|
-
const root = React.useRef(null);
|
|
251
|
+
const root = React.useRef(null);
|
|
259
252
|
|
|
253
|
+
// Inject and cleanup RN polyfills if able
|
|
260
254
|
React.useLayoutEffect(() => polyfills(), []);
|
|
261
255
|
const onLayout = React.useCallback(e => {
|
|
262
256
|
const {
|
|
@@ -271,9 +265,10 @@ const CanvasImpl = /*#__PURE__*/React.forwardRef(({
|
|
|
271
265
|
top: y,
|
|
272
266
|
left: x
|
|
273
267
|
});
|
|
274
|
-
}, []);
|
|
275
|
-
// https://github.com/pmndrs/react-three-fiber/pull/2297
|
|
268
|
+
}, []);
|
|
276
269
|
|
|
270
|
+
// Called on context create or swap
|
|
271
|
+
// https://github.com/pmndrs/react-three-fiber/pull/2297
|
|
277
272
|
const onContextCreate = React.useCallback(context => {
|
|
278
273
|
const canvasShim = {
|
|
279
274
|
width: context.drawingBufferWidth,
|
|
@@ -287,7 +282,6 @@ const CanvasImpl = /*#__PURE__*/React.forwardRef(({
|
|
|
287
282
|
root.current = createRoot(canvasShim);
|
|
288
283
|
setCanvas(canvasShim);
|
|
289
284
|
}, []);
|
|
290
|
-
|
|
291
285
|
if (root.current && width > 0 && height > 0) {
|
|
292
286
|
root.current.configure({
|
|
293
287
|
gl,
|
|
@@ -316,16 +310,15 @@ const CanvasImpl = /*#__PURE__*/React.forwardRef(({
|
|
|
316
310
|
onCreated: state => {
|
|
317
311
|
// Bind events after creation
|
|
318
312
|
const handlers = state.events.connect == null ? void 0 : state.events.connect(viewRef.current);
|
|
319
|
-
setBind(handlers);
|
|
313
|
+
setBind(handlers);
|
|
320
314
|
|
|
315
|
+
// Bind render to RN bridge
|
|
321
316
|
const context = state.gl.getContext();
|
|
322
317
|
const renderFrame = state.gl.render.bind(state.gl);
|
|
323
|
-
|
|
324
318
|
state.gl.render = (scene, camera) => {
|
|
325
319
|
renderFrame(scene, camera);
|
|
326
320
|
context.endFrameEXP();
|
|
327
321
|
};
|
|
328
|
-
|
|
329
322
|
return onCreated == null ? void 0 : onCreated(state);
|
|
330
323
|
}
|
|
331
324
|
});
|
|
@@ -337,7 +330,6 @@ const CanvasImpl = /*#__PURE__*/React.forwardRef(({
|
|
|
337
330
|
})
|
|
338
331
|
}, children))));
|
|
339
332
|
}
|
|
340
|
-
|
|
341
333
|
React.useEffect(() => {
|
|
342
334
|
if (canvas) {
|
|
343
335
|
return () => unmountComponentAtNode(canvas);
|
|
@@ -355,11 +347,11 @@ const CanvasImpl = /*#__PURE__*/React.forwardRef(({
|
|
|
355
347
|
style: StyleSheet.absoluteFill
|
|
356
348
|
}));
|
|
357
349
|
});
|
|
350
|
+
|
|
358
351
|
/**
|
|
359
352
|
* A native canvas which accepts threejs elements as children.
|
|
360
353
|
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
361
354
|
*/
|
|
362
|
-
|
|
363
355
|
const Canvas = /*#__PURE__*/React.forwardRef(function CanvasWrapper(props, ref) {
|
|
364
356
|
return /*#__PURE__*/React.createElement(FiberProvider, null, /*#__PURE__*/React.createElement(CanvasImpl, _extends({}, props, {
|
|
365
357
|
ref: ref
|