-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
amp-instagram: Resizing in response to messages posted by iframe #7705
Conversation
if (this.iframe_./*OK*/offsetHeight !== height) { | ||
// Height returned by Instagram includes header, so | ||
// subtract 48px top padding | ||
this.attemptChangeHeight(height - PADDING_TOP).catch(() => {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably OK to call changeHeight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just one small request (created an issue for amp-youtube to do the same #7720)
@@ -120,6 +126,10 @@ class AmpInstagram extends AMP.BaseElement { | |||
layoutCallback() { | |||
const iframe = this.element.ownerDocument.createElement('iframe'); | |||
this.iframe_ = iframe; | |||
|
|||
this.win.addEventListener( | |||
'message', event => this.handleInstagramMessages_(event)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep a reference to the unlisten
function so we remove the listener in unlayout
e.g.
(listen
is a utility function that can be imported from ../../../src/event-helper
)
this.unlistenMessage_ = listen(this.win, 'message', this.handleInstagramMessages_.bind(this));
then in unlayout
if (this.unlistenMessage_) {
this.unlistenMessage_();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I'll add that!
} | ||
if (data.type == 'MEASURE') { | ||
const height = data.details.height; | ||
if (this.iframe_./*OK*/offsetHeight !== height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be in vsync?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to be in vsync. attemptChangeHeight
does its own mutate so I think we can do the check and the attemptChangeHeight
in the same measure block. e.g.:
const height = data.details.height;
this.getVsync().measure(() => {
if (this.iframe_./*OK*/offsetHeight !== height) {
this.attemptChangeHeight(height - PADDING_TOP).catch(() => {});
}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, approved pending gulp check-types
passes.
@@ -55,6 +62,9 @@ class AmpInstagram extends AMP.BaseElement { | |||
|
|||
/** @private {?string} */ | |||
this.shortcode_ = ''; | |||
|
|||
/** @private {?function} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{?Function}
* Resizing in response to messages posted by Instagram iframe * Fixing lint errors * Adding listen/unlisten and use of getVsync * Fixing type check
…project#7705) * Resizing in response to messages posted by Instagram iframe * Fixing lint errors * Adding listen/unlisten and use of getVsync * Fixing type check
Enabling the automatic resize of the
amp-instagram
component in response to messages received from the Instagram iframe. Instagram posts messages with the following data property:Fixes issue #5032.