Make InstancesEditor initialization more robust against new react-dnd versions

This commit is contained in:
Florian Rival
2019-03-17 21:55:44 +00:00
parent a27d0705a4
commit 06a4d30223
2 changed files with 21 additions and 3 deletions

View File

@@ -34,7 +34,7 @@ const styles = {
type ScrollableComponent = {
scrollTo: (number, number) => void,
getViewPosition: () => ViewPosition,
getViewPosition: () => ?ViewPosition,
};
type Props = {
@@ -121,7 +121,9 @@ export const addScrollbars = (WrappedComponent: any) => {
};
_handleViewPositionChange = throttle(
(viewPosition: ViewPosition) => {
(viewPosition: ?ViewPosition) => {
if (!viewPosition) return;
this._setAndAdjust({
xValue: viewPosition.getViewX(),
yValue: viewPosition.getViewY(),

View File

@@ -37,6 +37,22 @@ export default class InstancesEditorContainer extends Component {
}
componentDidMount() {
// Initialize the PIXI renderer, if possible
if (this.canvasArea && !this.pixiRenderer) {
this._initializeCanvasAndRenderer();
}
}
componentDidUpdate() {
// Initialize the PIXI renderer, if not already done.
// This can happen if canvasArea was not rendered
// just after the mount (depends on react-dnd versions?).
if (this.canvasArea && !this.pixiRenderer) {
this._initializeCanvasAndRenderer();
}
}
_initializeCanvasAndRenderer() {
this.pixiRenderer = PIXI.autoDetectRenderer(
this.props.width,
this.props.height
@@ -544,7 +560,7 @@ export default class InstancesEditorContainer extends Component {
);
};
getViewPosition = () => {
getViewPosition = () /*: ?ViewPosition */ => {
return this.viewPosition;
};