Skip to content

Commit

Permalink
fix(iframe): allow updating noloading props after mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
mjancarik committed Sep 7, 2018
1 parent e0ee74b commit 1003262
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/iframe/HtmlIframe.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ export default class HtmlIframe extends React.PureComponent {
};
}

static getDerivedStateFromProps(nextProps, prevState) {
return {
visibleInViewport:
nextProps.noloading || prevState.visibleInViewport || false
};
}

constructor(props, context) {
super(props, context);

this.state = {
visibleInViewport: props.noloading || false
};
this.state = {};

this._registeredVisibilityId = null;

Expand Down Expand Up @@ -128,10 +133,13 @@ export default class HtmlIframe extends React.PureComponent {
}

onVisibilityWriter(visibility, observer) {
if (this.state.visibleInViewport === false && visibility > 0) {
if (visibility > 0) {
observer && observer.disconnect();
this._unregisterToCheckingVisibility();
this.setState({ visibleInViewport: true });

if (this.state.visibleInViewport === false) {
this.setState({ visibleInViewport: true });
}
}
}

Expand Down

0 comments on commit 1003262

Please sign in to comment.