@react-three/fiber 8.0.0-beta-03 → 8.0.0-beta-04
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/dist/declarations/src/core/events.d.ts +1 -0
- package/dist/declarations/src/{web → core}/index.d.ts +2 -4
- package/dist/declarations/src/index.d.ts +3 -1
- package/dist/declarations/src/native/Canvas.d.ts +2 -5
- package/dist/declarations/src/native/events.d.ts +0 -1
- package/dist/declarations/src/native.d.ts +3 -1
- package/dist/declarations/src/web/Canvas.d.ts +1 -1
- package/dist/declarations/src/web/events.d.ts +0 -1
- package/dist/{hooks-7b7e01e6.cjs.prod.js → index-eb414398.cjs.prod.js} +276 -60
- package/dist/{hooks-15c12e3e.esm.js → index-fccd77b0.esm.js} +265 -54
- package/dist/{hooks-6526f63c.cjs.dev.js → index-ff3eb68b.cjs.dev.js} +276 -60
- package/dist/react-three-fiber.cjs.dev.js +53 -274
- package/dist/react-three-fiber.cjs.prod.js +53 -274
- package/dist/react-three-fiber.esm.js +29 -250
- package/native/dist/react-three-fiber-native.cjs.dev.js +135 -336
- package/native/dist/react-three-fiber-native.cjs.prod.js +135 -336
- package/native/dist/react-three-fiber-native.esm.js +110 -311
- package/package.json +2 -1
- package/dist/declarations/src/native/index.d.ts +0 -36
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
|
-
var React = require('react');
|
|
5
|
+
var index = require('../../dist/index-ff3eb68b.cjs.dev.js');
|
|
8
6
|
var THREE = require('three');
|
|
9
|
-
var reactNative = require('react-native');
|
|
10
|
-
var expoGl = require('expo-gl');
|
|
11
|
-
var constants = require('react-reconciler/constants');
|
|
12
|
-
var Pressability = require('react-native/Libraries/Pressability/Pressability');
|
|
13
7
|
var expoAsset = require('expo-asset');
|
|
14
8
|
var expoFileSystem = require('expo-file-system');
|
|
15
9
|
var base64Arraybuffer = require('base64-arraybuffer');
|
|
16
10
|
var suspendReact = require('suspend-react');
|
|
11
|
+
var _extends = require('@babel/runtime/helpers/extends');
|
|
12
|
+
var React = require('react');
|
|
13
|
+
var reactNative = require('react-native');
|
|
14
|
+
var expoGl = require('expo-gl');
|
|
15
|
+
var Pressability = require('react-native/Libraries/Pressability/Pressability');
|
|
16
|
+
require('react-reconciler/constants');
|
|
17
|
+
require('zustand');
|
|
17
18
|
require('react-reconciler');
|
|
18
19
|
require('scheduler');
|
|
19
|
-
require('zustand');
|
|
20
20
|
|
|
21
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
22
22
|
|
|
@@ -40,103 +40,10 @@ function _interopNamespace(e) {
|
|
|
40
40
|
return Object.freeze(n);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
44
43
|
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
44
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
45
45
|
var Pressability__default = /*#__PURE__*/_interopDefault(Pressability);
|
|
46
46
|
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
const EVENTS = {
|
|
49
|
-
PRESS: 'onPress',
|
|
50
|
-
PRESSIN: 'onPressIn',
|
|
51
|
-
PRESSOUT: 'onPressOut',
|
|
52
|
-
LONGPRESS: 'onLongPress',
|
|
53
|
-
HOVERIN: 'onHoverIn',
|
|
54
|
-
HOVEROUT: 'onHoverOut',
|
|
55
|
-
PRESSMOVE: 'onPressMove'
|
|
56
|
-
};
|
|
57
|
-
const DOM_EVENTS = {
|
|
58
|
-
[EVENTS.PRESS]: 'onClick',
|
|
59
|
-
[EVENTS.PRESSIN]: 'onPointerDown',
|
|
60
|
-
[EVENTS.PRESSOUT]: 'onPointerUp',
|
|
61
|
-
[EVENTS.LONGPRESS]: 'onDoubleClick',
|
|
62
|
-
[EVENTS.HOVERIN]: 'onPointerOver',
|
|
63
|
-
[EVENTS.HOVEROUT]: 'onPointerOut',
|
|
64
|
-
[EVENTS.PRESSMOVE]: 'onPointerMove'
|
|
65
|
-
}; // https://github.com/facebook/react/tree/main/packages/react-reconciler#getcurrenteventpriority
|
|
66
|
-
// Gives React a clue as to how import the current interaction is
|
|
67
|
-
|
|
68
|
-
function getEventPriority() {
|
|
69
|
-
var _window, _window$event;
|
|
70
|
-
|
|
71
|
-
let name = (_window = window) == null ? void 0 : (_window$event = _window.event) == null ? void 0 : _window$event.type;
|
|
72
|
-
|
|
73
|
-
switch (name) {
|
|
74
|
-
case EVENTS.PRESS:
|
|
75
|
-
case EVENTS.PRESSIN:
|
|
76
|
-
case EVENTS.PRESSOUT:
|
|
77
|
-
case EVENTS.LONGPRESS:
|
|
78
|
-
return constants.DiscreteEventPriority;
|
|
79
|
-
|
|
80
|
-
case EVENTS.HOVERIN:
|
|
81
|
-
case EVENTS.HOVEROUT:
|
|
82
|
-
case EVENTS.PRESSMOVE:
|
|
83
|
-
return constants.ContinuousEventPriority;
|
|
84
|
-
|
|
85
|
-
default:
|
|
86
|
-
return constants.DefaultEventPriority;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function createTouchEvents(store) {
|
|
90
|
-
const {
|
|
91
|
-
handlePointer
|
|
92
|
-
} = hooks.createEvents(store);
|
|
93
|
-
|
|
94
|
-
const handleTouch = (event, name) => {
|
|
95
|
-
event.persist() // Apply offset
|
|
96
|
-
;
|
|
97
|
-
event.nativeEvent.offsetX = event.nativeEvent.pageX;
|
|
98
|
-
event.nativeEvent.offsetY = event.nativeEvent.pageY; // Emulate DOM event
|
|
99
|
-
|
|
100
|
-
const callback = handlePointer(DOM_EVENTS[name]);
|
|
101
|
-
return callback(event.nativeEvent);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
connected: false,
|
|
106
|
-
handlers: Object.values(EVENTS).reduce((acc, name) => ({ ...acc,
|
|
107
|
-
[name]: event => handleTouch(event, name)
|
|
108
|
-
}), {}),
|
|
109
|
-
connect: () => {
|
|
110
|
-
const {
|
|
111
|
-
set,
|
|
112
|
-
events
|
|
113
|
-
} = store.getState();
|
|
114
|
-
events.disconnect == null ? void 0 : events.disconnect();
|
|
115
|
-
const manager = new Pressability__default['default'](events == null ? void 0 : events.handlers);
|
|
116
|
-
set(state => ({
|
|
117
|
-
events: { ...state.events,
|
|
118
|
-
connected: manager
|
|
119
|
-
}
|
|
120
|
-
}));
|
|
121
|
-
},
|
|
122
|
-
disconnect: () => {
|
|
123
|
-
const {
|
|
124
|
-
set,
|
|
125
|
-
events
|
|
126
|
-
} = store.getState();
|
|
127
|
-
|
|
128
|
-
if (events.connected) {
|
|
129
|
-
events.connected.reset();
|
|
130
|
-
set(state => ({
|
|
131
|
-
events: { ...state.events,
|
|
132
|
-
connected: false
|
|
133
|
-
}
|
|
134
|
-
}));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
47
|
/**
|
|
141
48
|
* Generates an asset based on input type.
|
|
142
49
|
*/
|
|
@@ -206,7 +113,7 @@ function loadingFn(extensions, onProgress) {
|
|
|
206
113
|
|
|
207
114
|
if (url.startsWith != null && url.startsWith('http') && Proto.prototype.hasOwnProperty('load')) {
|
|
208
115
|
return loader.load(entry, data => {
|
|
209
|
-
if (data.scene) Object.assign(data,
|
|
116
|
+
if (data.scene) Object.assign(data, index.buildGraph(data.scene));
|
|
210
117
|
res(data);
|
|
211
118
|
}, onProgress, error => reject(`Could not load ${url}: ${error.message}`));
|
|
212
119
|
} // Otherwise, create a localUri and a file buffer
|
|
@@ -218,7 +125,7 @@ function loadingFn(extensions, onProgress) {
|
|
|
218
125
|
const arrayBuffer = await toBuffer(localUri); // Parse it
|
|
219
126
|
|
|
220
127
|
const parsed = loader.parse == null ? void 0 : loader.parse(arrayBuffer, undefined, data => {
|
|
221
|
-
if (data.scene) Object.assign(data,
|
|
128
|
+
if (data.scene) Object.assign(data, index.buildGraph(data.scene));
|
|
222
129
|
res(data);
|
|
223
130
|
}, error => reject(`Could not load ${url}: ${error.message}`)); // Respect synchronous parsers which don't have callbacks
|
|
224
131
|
|
|
@@ -231,7 +138,7 @@ function useLoader(Proto, input, extensions, onProgress) {
|
|
|
231
138
|
// Use suspense to load async assets
|
|
232
139
|
const keys = Array.isArray(input) ? input : [input];
|
|
233
140
|
const results = suspendReact.suspend(loadingFn(extensions, onProgress), [Proto, ...keys], {
|
|
234
|
-
equal:
|
|
141
|
+
equal: index.is.equ
|
|
235
142
|
}); // Return the object/s
|
|
236
143
|
|
|
237
144
|
return Array.isArray(input) ? results : results[0];
|
|
@@ -247,205 +154,77 @@ useLoader.clear = function (Proto, input) {
|
|
|
247
154
|
return suspendReact.clear([Proto, ...keys]);
|
|
248
155
|
};
|
|
249
156
|
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
} = hooks.createRenderer(roots, getEventPriority);
|
|
259
|
-
|
|
260
|
-
const createRendererInstance = (gl, context) => {
|
|
261
|
-
// Create canvas shim
|
|
262
|
-
const canvas = {
|
|
263
|
-
width: context.drawingBufferWidth,
|
|
264
|
-
height: context.drawingBufferHeight,
|
|
265
|
-
style: {},
|
|
266
|
-
addEventListener: () => {},
|
|
267
|
-
removeEventListener: () => {},
|
|
268
|
-
clientHeight: context.drawingBufferHeight
|
|
269
|
-
}; // If a renderer is specified, return it
|
|
270
|
-
|
|
271
|
-
const customRenderer = typeof gl === 'function' ? gl(canvas, context) : gl;
|
|
272
|
-
if (hooks.isRenderer(customRenderer)) return customRenderer; // Create renderer and pass our canvas and its context
|
|
273
|
-
|
|
274
|
-
const renderer = new THREE__namespace.WebGLRenderer({
|
|
275
|
-
powerPreference: 'high-performance',
|
|
276
|
-
antialias: true,
|
|
277
|
-
alpha: true,
|
|
278
|
-
...gl,
|
|
279
|
-
canvas,
|
|
280
|
-
context
|
|
281
|
-
}); // Set color management
|
|
282
|
-
|
|
283
|
-
renderer.outputEncoding = THREE__namespace.sRGBEncoding;
|
|
284
|
-
renderer.toneMapping = THREE__namespace.ACESFilmicToneMapping; // Set GL props
|
|
285
|
-
|
|
286
|
-
if (gl) applyProps(renderer, gl); // Bind render to RN bridge
|
|
287
|
-
|
|
288
|
-
if (context.endFrameEXP) {
|
|
289
|
-
const renderFrame = renderer.render.bind(renderer);
|
|
290
|
-
|
|
291
|
-
renderer.render = (scene, camera) => {
|
|
292
|
-
renderFrame(scene, camera);
|
|
293
|
-
context.endFrameEXP();
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return renderer;
|
|
157
|
+
const EVENTS = {
|
|
158
|
+
PRESS: 'onPress',
|
|
159
|
+
PRESSIN: 'onPressIn',
|
|
160
|
+
PRESSOUT: 'onPressOut',
|
|
161
|
+
LONGPRESS: 'onLongPress',
|
|
162
|
+
HOVERIN: 'onHoverIn',
|
|
163
|
+
HOVEROUT: 'onHoverOut',
|
|
164
|
+
PRESSMOVE: 'onPressMove'
|
|
298
165
|
};
|
|
166
|
+
const DOM_EVENTS = {
|
|
167
|
+
[EVENTS.PRESS]: 'onClick',
|
|
168
|
+
[EVENTS.PRESSIN]: 'onPointerDown',
|
|
169
|
+
[EVENTS.PRESSOUT]: 'onPointerUp',
|
|
170
|
+
[EVENTS.LONGPRESS]: 'onDoubleClick',
|
|
171
|
+
[EVENTS.HOVERIN]: 'onPointerOver',
|
|
172
|
+
[EVENTS.HOVEROUT]: 'onPointerOut',
|
|
173
|
+
[EVENTS.PRESSMOVE]: 'onPointerMove'
|
|
174
|
+
};
|
|
175
|
+
function createTouchEvents(store) {
|
|
176
|
+
const {
|
|
177
|
+
handlePointer
|
|
178
|
+
} = index.createEvents(store);
|
|
299
179
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
let {
|
|
306
|
-
gl,
|
|
307
|
-
size = {
|
|
308
|
-
width: 0,
|
|
309
|
-
height: 0
|
|
310
|
-
},
|
|
311
|
-
events,
|
|
312
|
-
onCreated,
|
|
313
|
-
...props
|
|
314
|
-
} = config || {};
|
|
315
|
-
let root = roots.get(context);
|
|
316
|
-
let fiber = root == null ? void 0 : root.fiber;
|
|
317
|
-
let store = root == null ? void 0 : root.store;
|
|
318
|
-
let state = (_store = store) == null ? void 0 : _store.getState();
|
|
319
|
-
|
|
320
|
-
if (fiber && state) {
|
|
321
|
-
// When a root was found, see if any fundamental props must be changed or exchanged
|
|
322
|
-
// Check size
|
|
323
|
-
if (state.size.width !== size.width || state.size.height !== size.height) state.setSize(size.width, size.height); // Check frameloop
|
|
324
|
-
|
|
325
|
-
if (state.frameloop !== props.frameloop) state.setFrameloop(props.frameloop); // For some props we want to reset the entire root
|
|
326
|
-
// Changes to the color-space
|
|
327
|
-
|
|
328
|
-
const linearChanged = props.linear !== state.internal.lastProps.linear;
|
|
329
|
-
|
|
330
|
-
if (linearChanged) {
|
|
331
|
-
unmountComponentAtNode(context);
|
|
332
|
-
fiber = undefined;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
if (!fiber) {
|
|
337
|
-
// If no root has been found, make one
|
|
338
|
-
// Create gl
|
|
339
|
-
const glRenderer = createRendererInstance(gl, context); // Create store
|
|
340
|
-
|
|
341
|
-
store = hooks.createStore(applyProps, invalidate, advance, {
|
|
342
|
-
gl: glRenderer,
|
|
343
|
-
size,
|
|
344
|
-
...props,
|
|
345
|
-
// expo-gl can only render at native dpr/resolution
|
|
346
|
-
// https://github.com/expo/expo-three/issues/39
|
|
347
|
-
dpr: reactNative.PixelRatio.get()
|
|
348
|
-
});
|
|
349
|
-
const state = store.getState(); // Create renderer
|
|
350
|
-
|
|
351
|
-
fiber = reconciler.createContainer(store, constants.ConcurrentRoot, false, null); // Map it
|
|
352
|
-
|
|
353
|
-
roots.set(context, {
|
|
354
|
-
fiber,
|
|
355
|
-
store
|
|
356
|
-
}); // Store event manager internally and connect it
|
|
180
|
+
const handleTouch = (event, name) => {
|
|
181
|
+
event.persist() // Apply offset
|
|
182
|
+
;
|
|
183
|
+
event.nativeEvent.offsetX = event.nativeEvent.pageX;
|
|
184
|
+
event.nativeEvent.offsetY = event.nativeEvent.pageY; // Emulate DOM event
|
|
357
185
|
|
|
358
|
-
|
|
359
|
-
|
|
186
|
+
const callback = handlePointer(DOM_EVENTS[name]);
|
|
187
|
+
return callback(event.nativeEvent);
|
|
188
|
+
};
|
|
360
189
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
190
|
+
return {
|
|
191
|
+
connected: false,
|
|
192
|
+
handlers: Object.values(EVENTS).reduce((acc, name) => ({ ...acc,
|
|
193
|
+
[name]: event => handleTouch(event, name)
|
|
194
|
+
}), {}),
|
|
195
|
+
connect: () => {
|
|
196
|
+
const {
|
|
197
|
+
set,
|
|
198
|
+
events
|
|
199
|
+
} = store.getState();
|
|
200
|
+
events.disconnect == null ? void 0 : events.disconnect();
|
|
201
|
+
const connected = new Pressability__default['default'](events == null ? void 0 : events.handlers);
|
|
202
|
+
const handlers = connected.getEventHandlers();
|
|
203
|
+
set(state => ({
|
|
204
|
+
events: { ...state.events,
|
|
205
|
+
connected,
|
|
206
|
+
handlers
|
|
365
207
|
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (store && fiber) {
|
|
369
|
-
reconciler.updateContainer( /*#__PURE__*/React__namespace.createElement(Provider, {
|
|
370
|
-
store: store,
|
|
371
|
-
element: element,
|
|
372
|
-
onCreated: onCreated
|
|
373
|
-
}), fiber, null, () => undefined);
|
|
374
|
-
return store;
|
|
375
|
-
} else {
|
|
376
|
-
throw 'Error creating root!';
|
|
377
|
-
}
|
|
208
|
+
}));
|
|
378
209
|
},
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
console.warn('R3F.render is no longer supported in React 18. Use createRoot instead!');
|
|
385
|
-
return createRoot(context, config).render(element);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
function Provider({
|
|
389
|
-
store,
|
|
390
|
-
element,
|
|
391
|
-
onCreated
|
|
392
|
-
}) {
|
|
393
|
-
React__namespace.useEffect(() => {
|
|
394
|
-
const state = store.getState(); // Flag the canvas active, rendering will now begin
|
|
395
|
-
|
|
396
|
-
state.set(state => ({
|
|
397
|
-
internal: { ...state.internal,
|
|
398
|
-
active: true
|
|
399
|
-
}
|
|
400
|
-
})); // Notifiy that init is completed, the scene graph exists, but nothing has yet rendered
|
|
401
|
-
|
|
402
|
-
if (onCreated) onCreated(state); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
403
|
-
}, []);
|
|
404
|
-
return /*#__PURE__*/React__namespace.createElement(hooks.context.Provider, {
|
|
405
|
-
value: store
|
|
406
|
-
}, element);
|
|
407
|
-
}
|
|
210
|
+
disconnect: () => {
|
|
211
|
+
const {
|
|
212
|
+
set,
|
|
213
|
+
events
|
|
214
|
+
} = store.getState();
|
|
408
215
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const state = root == null ? void 0 : root.store.getState();
|
|
415
|
-
if (state) state.internal.active = false;
|
|
416
|
-
reconciler.updateContainer(null, fiber, null, () => {
|
|
417
|
-
if (state) {
|
|
418
|
-
setTimeout(() => {
|
|
419
|
-
try {
|
|
420
|
-
var _state$gl, _state$gl$renderLists, _state$gl2;
|
|
421
|
-
|
|
422
|
-
state.events.disconnect == null ? void 0 : state.events.disconnect();
|
|
423
|
-
(_state$gl = state.gl) == null ? void 0 : (_state$gl$renderLists = _state$gl.renderLists) == null ? void 0 : _state$gl$renderLists.dispose == null ? void 0 : _state$gl$renderLists.dispose();
|
|
424
|
-
(_state$gl2 = state.gl) == null ? void 0 : _state$gl2.forceContextLoss == null ? void 0 : _state$gl2.forceContextLoss();
|
|
425
|
-
hooks.dispose(state);
|
|
426
|
-
roots.delete(context);
|
|
427
|
-
if (callback) callback(context);
|
|
428
|
-
} catch (e) {
|
|
429
|
-
/* ... */
|
|
216
|
+
if (events.connected) {
|
|
217
|
+
events.connected.reset();
|
|
218
|
+
set(state => ({
|
|
219
|
+
events: { ...state.events,
|
|
220
|
+
connected: false
|
|
430
221
|
}
|
|
431
|
-
}
|
|
222
|
+
}));
|
|
432
223
|
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
const act = React__namespace.unstable_act;
|
|
438
|
-
|
|
439
|
-
function createPortal(children, container) {
|
|
440
|
-
return reconciler.createPortal(children, container, null, null);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
441
226
|
}
|
|
442
227
|
|
|
443
|
-
reconciler.injectIntoDevTools({
|
|
444
|
-
bundleType: process.env.NODE_ENV === 'production' ? 0 : 1,
|
|
445
|
-
rendererPackageName: '@react-three/fiber',
|
|
446
|
-
version: '18.0.0'
|
|
447
|
-
});
|
|
448
|
-
|
|
449
228
|
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'performance', 'clock', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
450
229
|
|
|
451
230
|
function Block({
|
|
@@ -485,14 +264,12 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
485
264
|
fallback,
|
|
486
265
|
style,
|
|
487
266
|
events,
|
|
488
|
-
nativeRef_EXPERIMENTAL,
|
|
489
|
-
onContextCreate,
|
|
490
267
|
...props
|
|
491
268
|
}, forwardedRef) => {
|
|
492
269
|
// Create a known catalogue of Threejs-native elements
|
|
493
270
|
// This will include the entire THREE namespace by default, users can extend
|
|
494
271
|
// their own elements by using the createRoot API instead
|
|
495
|
-
React__namespace.useMemo(() =>
|
|
272
|
+
React__namespace.useMemo(() => index.extend(THREE__namespace), []);
|
|
496
273
|
const [{
|
|
497
274
|
width,
|
|
498
275
|
height
|
|
@@ -500,10 +277,10 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
500
277
|
width: 0,
|
|
501
278
|
height: 0
|
|
502
279
|
});
|
|
503
|
-
const [
|
|
280
|
+
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
504
281
|
const [bind, setBind] = React__namespace.useState();
|
|
505
|
-
const canvasProps =
|
|
506
|
-
const viewProps =
|
|
282
|
+
const canvasProps = index.pick(props, CANVAS_PROPS);
|
|
283
|
+
const viewProps = index.omit(props, CANVAS_PROPS);
|
|
507
284
|
const [block, setBlock] = React__namespace.useState(false);
|
|
508
285
|
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
509
286
|
|
|
@@ -520,14 +297,46 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
520
297
|
height
|
|
521
298
|
});
|
|
522
299
|
}, []);
|
|
300
|
+
const onContextCreate = React__namespace.useCallback(context => {
|
|
301
|
+
const canvasShim = {
|
|
302
|
+
width: context.drawingBufferWidth,
|
|
303
|
+
height: context.drawingBufferHeight,
|
|
304
|
+
style: {},
|
|
305
|
+
addEventListener: () => {},
|
|
306
|
+
removeEventListener: () => {},
|
|
307
|
+
clientHeight: context.drawingBufferHeight,
|
|
308
|
+
getContext: () => context
|
|
309
|
+
};
|
|
310
|
+
setCanvas(canvasShim);
|
|
311
|
+
}, []);
|
|
312
|
+
|
|
313
|
+
if (width > 0 && height > 0 && canvas) {
|
|
314
|
+
// Overwrite onCreated to apply RN bindings
|
|
315
|
+
const onCreated = state => {
|
|
316
|
+
// Bind events after creation
|
|
317
|
+
setBind(state.events.handlers); // Bind render to RN bridge
|
|
318
|
+
|
|
319
|
+
const context = state.gl.getContext();
|
|
320
|
+
const renderFrame = state.gl.render.bind(state.gl);
|
|
321
|
+
|
|
322
|
+
state.gl.render = (scene, camera) => {
|
|
323
|
+
renderFrame(scene, camera);
|
|
324
|
+
context.endFrameEXP();
|
|
325
|
+
};
|
|
523
326
|
|
|
524
|
-
|
|
525
|
-
|
|
327
|
+
return canvasProps == null ? void 0 : canvasProps.onCreated == null ? void 0 : canvasProps.onCreated(state);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
index.createRoot(canvas, { ...canvasProps,
|
|
331
|
+
// expo-gl can only render at native dpr/resolution
|
|
332
|
+
// https://github.com/expo/expo-three/issues/39
|
|
333
|
+
dpr: reactNative.PixelRatio.get(),
|
|
526
334
|
size: {
|
|
527
335
|
width,
|
|
528
336
|
height
|
|
529
337
|
},
|
|
530
|
-
events: events || createTouchEvents
|
|
338
|
+
events: events || createTouchEvents,
|
|
339
|
+
onCreated
|
|
531
340
|
}).render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
532
341
|
set: setError
|
|
533
342
|
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
@@ -535,13 +344,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
535
344
|
set: setBlock
|
|
536
345
|
})
|
|
537
346
|
}, children)));
|
|
538
|
-
const state = store.getState();
|
|
539
|
-
setBind(state.events.connected.getEventHandlers());
|
|
540
347
|
}
|
|
541
348
|
|
|
542
349
|
React__namespace.useEffect(() => {
|
|
543
|
-
return () => unmountComponentAtNode(
|
|
544
|
-
}, [
|
|
350
|
+
return () => index.unmountComponentAtNode(canvas);
|
|
351
|
+
}, [canvas]);
|
|
545
352
|
return /*#__PURE__*/React__namespace.createElement(reactNative.View, _extends({}, viewProps, {
|
|
546
353
|
ref: forwardedRef,
|
|
547
354
|
onLayout: onLayout,
|
|
@@ -550,40 +357,32 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
550
357
|
...style
|
|
551
358
|
}
|
|
552
359
|
}, bind), width > 0 && /*#__PURE__*/React__namespace.createElement(expoGl.GLView, {
|
|
553
|
-
|
|
554
|
-
if (nativeRef_EXPERIMENTAL && !nativeRef_EXPERIMENTAL.current) {
|
|
555
|
-
nativeRef_EXPERIMENTAL.current = ref;
|
|
556
|
-
}
|
|
557
|
-
},
|
|
558
|
-
onContextCreate: async gl => {
|
|
559
|
-
await (onContextCreate == null ? void 0 : onContextCreate(gl));
|
|
560
|
-
setContext(gl);
|
|
561
|
-
},
|
|
360
|
+
onContextCreate: onContextCreate,
|
|
562
361
|
style: reactNative.StyleSheet.absoluteFill
|
|
563
362
|
}));
|
|
564
363
|
});
|
|
565
364
|
|
|
566
|
-
exports.ReactThreeFiber =
|
|
567
|
-
exports.
|
|
568
|
-
exports.
|
|
569
|
-
exports.
|
|
570
|
-
exports.
|
|
571
|
-
exports.
|
|
572
|
-
exports.
|
|
573
|
-
exports.
|
|
574
|
-
exports.
|
|
575
|
-
exports.
|
|
576
|
-
exports.
|
|
365
|
+
exports.ReactThreeFiber = index.threeTypes;
|
|
366
|
+
exports._roots = index.roots;
|
|
367
|
+
exports.act = index.act;
|
|
368
|
+
exports.addAfterEffect = index.addAfterEffect;
|
|
369
|
+
exports.addEffect = index.addEffect;
|
|
370
|
+
exports.addTail = index.addTail;
|
|
371
|
+
exports.advance = index.advance;
|
|
372
|
+
exports.applyProps = index.applyProps;
|
|
373
|
+
exports.context = index.context;
|
|
374
|
+
exports.createPortal = index.createPortal;
|
|
375
|
+
exports.createRoot = index.createRoot;
|
|
376
|
+
exports.dispose = index.dispose;
|
|
377
|
+
exports.extend = index.extend;
|
|
378
|
+
exports.invalidate = index.invalidate;
|
|
379
|
+
exports.reconciler = index.reconciler;
|
|
380
|
+
exports.render = index.render;
|
|
381
|
+
exports.unmountComponentAtNode = index.unmountComponentAtNode;
|
|
382
|
+
exports.useFrame = index.useFrame;
|
|
383
|
+
exports.useGraph = index.useGraph;
|
|
384
|
+
exports.useStore = index.useStore;
|
|
385
|
+
exports.useThree = index.useThree;
|
|
577
386
|
exports.Canvas = Canvas;
|
|
578
|
-
exports._roots = roots;
|
|
579
|
-
exports.act = act;
|
|
580
|
-
exports.advance = advance;
|
|
581
|
-
exports.applyProps = applyProps;
|
|
582
|
-
exports.createPortal = createPortal;
|
|
583
|
-
exports.createRoot = createRoot;
|
|
584
387
|
exports.events = createTouchEvents;
|
|
585
|
-
exports.invalidate = invalidate;
|
|
586
|
-
exports.reconciler = reconciler;
|
|
587
|
-
exports.render = render;
|
|
588
|
-
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
589
388
|
exports.useLoader = useLoader;
|