Skip to content

Commit

Permalink
fix(View): Allow method call from prop change
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Jan 27, 2021
1 parent 931acac commit e2c57e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/GeometryRepresentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class GeometryRepresentation extends Component {

componentWillUnmount() {
if (this.view) {
this.view.renderer.remoteActor(this.actor);
this.view.renderer.removeActor(this.actor);
}

this.actor.delete();
Expand Down
22 changes: 22 additions & 0 deletions src/core/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ export default class View extends Component {
cameraPosition,
cameraViewUp,
cameraParallelProjection,
triggerRender,
triggerResetCamera,
} = props;
if (background && (!previous || background !== previous.background)) {
this.renderer.setBackground(background);
Expand Down Expand Up @@ -256,6 +258,14 @@ export default class View extends Component {
this.resetCamera();
}
}

// Allow to trigger method call from property change
if (previous && triggerRender !== previous.triggerRender) {
setTimeout(this.renderView, 0);
}
if (previous && triggerResetCamera !== previous.triggerResetCamera) {
setTimeout(this.resetCamera, 0);
}
}

resetCamera() {
Expand All @@ -272,6 +282,8 @@ View.defaultProps = {
cameraPosition: [0, 0, 1],
cameraViewUp: [0, 1, 0],
cameraParallelProjection: false,
triggerRender: 0,
triggerResetCamera: 0,
interactorSettings: [
{
button: 1,
Expand Down Expand Up @@ -342,6 +354,16 @@ View.propTypes = {
*/
cameraParallelProjection: PropTypes.bool,

/**
* Property use to trigger a render when changing.
*/
triggerRender: PropTypes.number,

/**
* Property use to trigger a resetCamera when changing.
*/
triggerResetCamera: PropTypes.number,

/**
* List of representation to show
*/
Expand Down

0 comments on commit e2c57e8

Please sign in to comment.