Skip to content

Commit

Permalink
fix: visibility helper - unregister only registered listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiri Fencl committed Jul 30, 2018
1 parent 39f9344 commit 01d911c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/iframe/HtmlIframe.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class HtmlIframe extends React.PureComponent {
this._registeredVisibilityId = null;

this._onVisibilityWriter = this.onVisibilityWriter.bind(this);
this._visibilityWriterRegistered = false;

this._rootElement = React.createRef();
}
Expand Down Expand Up @@ -136,9 +137,12 @@ export default class HtmlIframe extends React.PureComponent {
}

_unregisterToCheckingVisibility() {
this.utils.$UIComponentHelper.visibility.unregister(
this._registeredVisibilityId
);
if (this._visibilityWriterRegistered) {
this.utils.$UIComponentHelper.visibility.unregister(
this._registeredVisibilityId
);
this._visibilityWriterRegistered = false;
}
}

_registerToCheckingVisibility() {
Expand All @@ -157,5 +161,6 @@ export default class HtmlIframe extends React.PureComponent {
}),
$UIComponentHelper.wrapVisibilityWriter(this._onVisibilityWriter)
);
this._visibilityWriterRegistered = true;
}
}
11 changes: 8 additions & 3 deletions src/image/HtmlImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class HtmlImage extends React.PureComponent {
this._registeredVisibilityId = null;

this._onVisibilityWriter = this.onVisibilityWriter.bind(this);
this._visibilityWriterRegistered = false;

this._rootElement = React.createRef();
}
Expand Down Expand Up @@ -160,9 +161,12 @@ export default class HtmlImage extends React.PureComponent {
}

_unregisterToCheckingVisibility() {
this.utils.$UIComponentHelper.visibility.unregister(
this._registeredVisibilityId
);
if (this._visibilityWriterRegistered) {
this.utils.$UIComponentHelper.visibility.unregister(
this._registeredVisibilityId
);
this._visibilityWriterRegistered = false;
}
}

_registerToCheckingVisibility() {
Expand All @@ -186,6 +190,7 @@ export default class HtmlImage extends React.PureComponent {
}),
$UIComponentHelper.wrapVisibilityWriter(this._onVisibilityWriter)
);
this._visibilityWriterRegistered = true;
}

_preLoadImage() {
Expand Down
11 changes: 8 additions & 3 deletions src/video/HtmlVideo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class HtmlVideo extends React.PureComponent {
this._registeredVisibilityId = null;

this._onVisibilityWriter = this.onVisibilityWriter.bind(this);
this._visibilityWriterRegistered = false;

this._rootElement = React.createRef();
}
Expand Down Expand Up @@ -130,9 +131,12 @@ export default class HtmlVideo extends React.PureComponent {
}

_unregisterToCheckingVisibility() {
this.utils.$UIComponentHelper.visibility.unregister(
this._registeredVisibilityId
);
if (this._visibilityWriterRegistered) {
this.utils.$UIComponentHelper.visibility.unregister(
this._registeredVisibilityId
);
this._visibilityWriterRegistered = false;
}
}

_registerToCheckingVisibility() {
Expand All @@ -152,6 +156,7 @@ export default class HtmlVideo extends React.PureComponent {
}),
$UIComponentHelper.wrapVisibilityWriter(this._onVisibilityWriter)
);
this._visibilityWriterRegistered = true;
}

_preLoadPosterImage() {
Expand Down

0 comments on commit 01d911c

Please sign in to comment.