Skip to content
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

Merged
merged 4 commits into from
Feb 27, 2017
Merged

amp-instagram: Resizing in response to messages posted by iframe #7705

merged 4 commits into from
Feb 27, 2017

Conversation

src-code
Copy link
Contributor

@src-code src-code commented Feb 21, 2017

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:

"data": {
  "type": "MEASURE",
  "details": {
    "height": 123
  }
}

Fixes issue #5032.

if (this.iframe_./*OK*/offsetHeight !== height) {
// Height returned by Instagram includes header, so
// subtract 48px top padding
this.attemptChangeHeight(height - PADDING_TOP).catch(() => {});
Copy link
Member

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

Copy link
Contributor

@aghassemi aghassemi left a 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));
Copy link
Contributor

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_();
}

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor

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(() => {});
      }
    });

Copy link
Contributor

@aghassemi aghassemi left a 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} */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{?Function}

@jridgewell jridgewell merged commit 3dbce5e into ampproject:master Feb 27, 2017
adelinamart pushed a commit that referenced this pull request Mar 1, 2017
* Resizing in response to messages posted by Instagram iframe

* Fixing lint errors

* Adding listen/unlisten and use of getVsync

* Fixing type check
@src-code src-code deleted the issue5032 branch March 5, 2017 07:45
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
…project#7705)

* Resizing in response to messages posted by Instagram iframe

* Fixing lint errors

* Adding listen/unlisten and use of getVsync

* Fixing type check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants