react-pixi-fiber 2.0.0-rc.1 → 2.0.0-rc.3
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/cjs/react-pixi-fiber.development.js +84 -26
- package/cjs/react-pixi-fiber.production.min.js +3 -3
- package/cjs/react-pixi-fiber.production.min.js.map +1 -1
- package/es/react-pixi-fiber.development.js +85 -27
- package/es/react-pixi-fiber.production.min.js +3 -3
- package/es/react-pixi-fiber.production.min.js.map +1 -1
- package/index.d.ts +27 -5
- package/package.json +1 -1
- package/src/ReactPixiFiberComponent.js +8 -4
- package/src/Stage/hooks.js +40 -14
- package/src/Stage/legacy.js +21 -6
- package/umd/react-pixi-fiber.development.js +84 -26
- package/umd/react-pixi-fiber.production.min.js +3 -3
- package/umd/react-pixi-fiber.production.min.js.map +1 -1
|
@@ -23412,6 +23412,10 @@ function setValueForProperty(type, instance, propName, value, internalHandle) {
|
|
|
23412
23412
|
}
|
|
23413
23413
|
|
|
23414
23414
|
// Based on: https://github.com/facebook/react/blob/27535e7bfcb63e8a4d65f273311e380b4ca12eff/packages/react-dom/src/client/ReactDOMFiberComponent.js
|
|
23415
|
+
|
|
23416
|
+
// PixiJS v4 keeps these classes under extras/mesh/particles, which v5+ does not export. Reading them from a
|
|
23417
|
+
// plain copy of the namespace stops bundlers from reporting them as missing ES module exports.
|
|
23418
|
+
var PIXI_V4 = Object.assign({}, PIXI__namespace);
|
|
23415
23419
|
function createInstance(type, props, rootContainer, hostContext, internalHandle) {
|
|
23416
23420
|
var instance;
|
|
23417
23421
|
switch (type) {
|
|
@@ -23422,7 +23426,7 @@ function createInstance(type, props, rootContainer, hostContext, internalHandle)
|
|
|
23422
23426
|
tint: props.tint
|
|
23423
23427
|
};
|
|
23424
23428
|
try {
|
|
23425
|
-
instance = new
|
|
23429
|
+
instance = new PIXI_V4.extras.BitmapText(props.text, style);
|
|
23426
23430
|
} catch (e) {
|
|
23427
23431
|
instance = new PIXI__namespace.BitmapText(props.text, style);
|
|
23428
23432
|
}
|
|
@@ -23435,14 +23439,14 @@ function createInstance(type, props, rootContainer, hostContext, internalHandle)
|
|
|
23435
23439
|
break;
|
|
23436
23440
|
case TYPES.NINE_SLICE_PLANE:
|
|
23437
23441
|
try {
|
|
23438
|
-
instance = new
|
|
23442
|
+
instance = new PIXI_V4.mesh.NineSlicePlane(props.texture, props.leftWidth, props.topHeight, props.rightWidth, props.bottomHeight);
|
|
23439
23443
|
} catch (e) {
|
|
23440
23444
|
instance = new PIXI__namespace.NineSlicePlane(props.texture, props.leftWidth, props.topHeight, props.rightWidth, props.bottomHeight);
|
|
23441
23445
|
}
|
|
23442
23446
|
break;
|
|
23443
23447
|
case TYPES.PARTICLE_CONTAINER:
|
|
23444
23448
|
try {
|
|
23445
|
-
instance = new
|
|
23449
|
+
instance = new PIXI_V4.particles.ParticleContainer(props.maxSize, props.properties, props.batchSize, props.autoResize);
|
|
23446
23450
|
} catch (e) {
|
|
23447
23451
|
instance = new PIXI__namespace.ParticleContainer(props.maxSize, props.properties, props.batchSize, props.autoResize);
|
|
23448
23452
|
}
|
|
@@ -23455,7 +23459,7 @@ function createInstance(type, props, rootContainer, hostContext, internalHandle)
|
|
|
23455
23459
|
break;
|
|
23456
23460
|
case TYPES.TILING_SPRITE:
|
|
23457
23461
|
try {
|
|
23458
|
-
instance = new
|
|
23462
|
+
instance = new PIXI_V4.extras.TilingSprite(props.texture, props.width, props.height);
|
|
23459
23463
|
} catch (e) {
|
|
23460
23464
|
instance = new PIXI__namespace.TilingSprite(props.texture, props.width, props.height);
|
|
23461
23465
|
}
|
|
@@ -24057,26 +24061,51 @@ function useStageRenderer(props, appRef, canvasRef) {
|
|
|
24057
24061
|
|
|
24058
24062
|
// Cleanup current PIXI.Application when unmounting
|
|
24059
24063
|
return function cleanup() {
|
|
24060
|
-
|
|
24064
|
+
// There is no PIXI.Application while waiting for a new canvas, see `useStageRerenderer`
|
|
24065
|
+
if (appRef.current != null) {
|
|
24066
|
+
cleanupStage(appRef.current, STAGE_OPTIONS_UNMOUNT);
|
|
24067
|
+
}
|
|
24061
24068
|
};
|
|
24062
24069
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24063
24070
|
}, []);
|
|
24064
24071
|
}
|
|
24072
|
+
|
|
24073
|
+
// Returns `key` for the rendered canvas. It changes every time PIXI.Application has to be recreated,
|
|
24074
|
+
// so the new PIXI.Application gets a fresh canvas and WebGL context. The old PIXI.Application is
|
|
24075
|
+
// destroyed later (see `cleanupStage`) and destroying a renderer unbinds the current program
|
|
24076
|
+
// (PixiJS v6) or loses the context (PixiJS v7) of its canvas, which would break the new
|
|
24077
|
+
// PIXI.Application if it was sharing that canvas.
|
|
24065
24078
|
function useStageRerenderer(props, appRef, canvasRef) {
|
|
24066
24079
|
var prevProps = usePreviousProps(props);
|
|
24080
|
+
var _useState = React.useState(0),
|
|
24081
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
24082
|
+
canvasKey = _useState2[0],
|
|
24083
|
+
setCanvasKey = _useState2[1];
|
|
24067
24084
|
|
|
24068
24085
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24069
24086
|
React.useLayoutEffect(function () {
|
|
24070
24087
|
// This is first render, no need to do anything
|
|
24071
|
-
if (
|
|
24072
|
-
var app = props.app
|
|
24088
|
+
if (prevProps === emptyObject$1) return;
|
|
24089
|
+
var app = props.app,
|
|
24090
|
+
options = props.options;
|
|
24073
24091
|
if (app instanceof PIXI__namespace.Application) {
|
|
24074
24092
|
// Update stage tree
|
|
24075
24093
|
rerenderStage(appRef.current, prevProps, props);
|
|
24076
24094
|
return;
|
|
24077
24095
|
}
|
|
24078
|
-
var
|
|
24079
|
-
|
|
24096
|
+
var view = canvasRef.current;
|
|
24097
|
+
|
|
24098
|
+
// Previous update destroyed PIXI.Application and rendered a new canvas, create PIXI.Application on it
|
|
24099
|
+
if (appRef.current == null) {
|
|
24100
|
+
appRef.current = createPixiApplication(_objectSpread2({
|
|
24101
|
+
view: view
|
|
24102
|
+
}, options));
|
|
24103
|
+
|
|
24104
|
+
// Set initial properties
|
|
24105
|
+
renderStage(appRef.current, props);
|
|
24106
|
+
return;
|
|
24107
|
+
}
|
|
24108
|
+
var _props$options = props.options;
|
|
24080
24109
|
_props$options.height;
|
|
24081
24110
|
_props$options.width;
|
|
24082
24111
|
var otherOptions = _objectWithoutProperties(_props$options, _excluded$1);
|
|
@@ -24084,22 +24113,27 @@ function useStageRerenderer(props, appRef, canvasRef) {
|
|
|
24084
24113
|
_prevProps$options.height;
|
|
24085
24114
|
_prevProps$options.width;
|
|
24086
24115
|
var prevOtherOptions = _objectWithoutProperties(_prevProps$options, _excluded2$1);
|
|
24087
|
-
var view = canvasRef.current;
|
|
24088
24116
|
|
|
24089
24117
|
// We need to create new PIXI.Application when options other than dimensions
|
|
24090
24118
|
// are changed because some renderer settings are immutable.
|
|
24091
24119
|
if (!shallowEqual$1(otherOptions, prevOtherOptions)) {
|
|
24092
24120
|
// Destroy PIXI.Application
|
|
24093
24121
|
cleanupStage(appRef.current, STAGE_OPTIONS_RECREATE);
|
|
24122
|
+
if (options.view) {
|
|
24123
|
+
// Canvas passed in options as `view` is not ours to replace, reuse it
|
|
24124
|
+
appRef.current = createPixiApplication(_objectSpread2({
|
|
24125
|
+
view: view
|
|
24126
|
+
}, options));
|
|
24094
24127
|
|
|
24095
|
-
|
|
24096
|
-
|
|
24097
|
-
|
|
24098
|
-
|
|
24099
|
-
|
|
24100
|
-
|
|
24101
|
-
|
|
24102
|
-
|
|
24128
|
+
// Set initial properties
|
|
24129
|
+
renderStage(appRef.current, props);
|
|
24130
|
+
} else {
|
|
24131
|
+
// Render a new canvas, PIXI.Application is created on it in the next update
|
|
24132
|
+
appRef.current = null;
|
|
24133
|
+
setCanvasKey(function (canvasKey) {
|
|
24134
|
+
return canvasKey + 1;
|
|
24135
|
+
});
|
|
24136
|
+
}
|
|
24103
24137
|
} else {
|
|
24104
24138
|
// Update stage tree
|
|
24105
24139
|
rerenderStage(appRef.current, prevProps, props);
|
|
@@ -24107,6 +24141,7 @@ function useStageRerenderer(props, appRef, canvasRef) {
|
|
|
24107
24141
|
resizeRenderer(appRef.current, prevProps, props);
|
|
24108
24142
|
}
|
|
24109
24143
|
});
|
|
24144
|
+
return canvasKey;
|
|
24110
24145
|
}
|
|
24111
24146
|
function createStageFunction() {
|
|
24112
24147
|
var Stage = /*#__PURE__*/React.forwardRef(function Stage(props, ref) {
|
|
@@ -24132,7 +24167,7 @@ function createStageFunction() {
|
|
|
24132
24167
|
// - useStageRenderer:
|
|
24133
24168
|
// - is only called once
|
|
24134
24169
|
// - is responsible for creating first PIXI.Application and destroying it when Stage is finally unmounted
|
|
24135
|
-
useStageRerenderer(props, appRef, canvasRef);
|
|
24170
|
+
var canvasKey = useStageRerenderer(props, appRef, canvasRef);
|
|
24136
24171
|
useStageRenderer(props, appRef, canvasRef);
|
|
24137
24172
|
|
|
24138
24173
|
// Do not render anything if PIXI.Application was provided in props
|
|
@@ -24146,6 +24181,7 @@ function createStageFunction() {
|
|
|
24146
24181
|
}
|
|
24147
24182
|
var canvasProps = getCanvasProps(props);
|
|
24148
24183
|
return /*#__PURE__*/React__default["default"].createElement("canvas", _extends({
|
|
24184
|
+
key: canvasKey,
|
|
24149
24185
|
ref: canvasRef
|
|
24150
24186
|
}, canvasProps));
|
|
24151
24187
|
});
|
|
@@ -24167,6 +24203,11 @@ function createStageClass() {
|
|
|
24167
24203
|
_this._app = createRef();
|
|
24168
24204
|
// Store canvas if it was rendered
|
|
24169
24205
|
_this._canvas = createRef();
|
|
24206
|
+
// Changes every time PIXI.Application has to be recreated, so it gets a fresh canvas.
|
|
24207
|
+
// See `getPixiApplication`.
|
|
24208
|
+
_this.state = {
|
|
24209
|
+
canvasKey: 0
|
|
24210
|
+
};
|
|
24170
24211
|
return _this;
|
|
24171
24212
|
}
|
|
24172
24213
|
_inherits(Stage, _React$Component);
|
|
@@ -24185,6 +24226,9 @@ function createStageClass() {
|
|
|
24185
24226
|
key: "componentDidUpdate",
|
|
24186
24227
|
value: function componentDidUpdate(prevProps) {
|
|
24187
24228
|
var app = this.getPixiApplication(this.props, prevProps);
|
|
24229
|
+
|
|
24230
|
+
// Waiting for a new canvas to be rendered, PIXI.Application is created in the next update
|
|
24231
|
+
if (app === null) return;
|
|
24188
24232
|
this.renderStage(app, this.props);
|
|
24189
24233
|
this.rerenderStage(app, this.props, prevProps);
|
|
24190
24234
|
|
|
@@ -24197,7 +24241,8 @@ function createStageClass() {
|
|
|
24197
24241
|
var app = this.props.app;
|
|
24198
24242
|
|
|
24199
24243
|
// Destroy PIXI.Application if it was not provided in props
|
|
24200
|
-
|
|
24244
|
+
// There is no PIXI.Application while waiting for a new canvas, see `getPixiApplication`
|
|
24245
|
+
if (!(app instanceof PIXI__namespace.Application) && this._app.current != null) {
|
|
24201
24246
|
cleanupStage(this._app.current, STAGE_OPTIONS_UNMOUNT);
|
|
24202
24247
|
}
|
|
24203
24248
|
}
|
|
@@ -24219,6 +24264,7 @@ function createStageClass() {
|
|
|
24219
24264
|
}
|
|
24220
24265
|
var canvasProps = getCanvasProps(this.props);
|
|
24221
24266
|
return /*#__PURE__*/React__default["default"].createElement("canvas", _extends({
|
|
24267
|
+
key: this.state.canvasKey,
|
|
24222
24268
|
ref: this._canvas
|
|
24223
24269
|
}, canvasProps));
|
|
24224
24270
|
}
|
|
@@ -24235,7 +24281,7 @@ function createStageClass() {
|
|
|
24235
24281
|
}
|
|
24236
24282
|
var view = this._canvas.current;
|
|
24237
24283
|
|
|
24238
|
-
// Render stage for the first time
|
|
24284
|
+
// Render stage for the first time, or on a new canvas after PIXI.Application was destroyed
|
|
24239
24285
|
if (this._app.current == null) {
|
|
24240
24286
|
// Create new PIXI.Application
|
|
24241
24287
|
// Canvas passed in options as `view` will be used if provided
|
|
@@ -24258,11 +24304,23 @@ function createStageClass() {
|
|
|
24258
24304
|
// Destroy PIXI.Application
|
|
24259
24305
|
cleanupStage(this._app.current, STAGE_OPTIONS_RECREATE);
|
|
24260
24306
|
|
|
24261
|
-
//
|
|
24262
|
-
|
|
24263
|
-
|
|
24264
|
-
|
|
24265
|
-
|
|
24307
|
+
// Canvas passed in options as `view` is not ours to replace, reuse it
|
|
24308
|
+
if (options.view) {
|
|
24309
|
+
return createPixiApplication(_objectSpread2({
|
|
24310
|
+
view: view
|
|
24311
|
+
}, options));
|
|
24312
|
+
}
|
|
24313
|
+
|
|
24314
|
+
// Destroying the old PIXI.Application later unbinds or loses the WebGL context of its canvas,
|
|
24315
|
+
// so render a new canvas and create PIXI.Application on it in the next update
|
|
24316
|
+
this._app.current = null;
|
|
24317
|
+
this.setState(function (_ref) {
|
|
24318
|
+
var canvasKey = _ref.canvasKey;
|
|
24319
|
+
return {
|
|
24320
|
+
canvasKey: canvasKey + 1
|
|
24321
|
+
};
|
|
24322
|
+
});
|
|
24323
|
+
return null;
|
|
24266
24324
|
}
|
|
24267
24325
|
|
|
24268
24326
|
// Return already existing Application otherwise
|