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

✨ Implement example code blocks with preview in iframe #2637

Merged
merged 54 commits into from
Aug 2, 2019

Conversation

sebil
Copy link
Collaborator

@sebil sebil commented Jul 29, 2019

We now support example code blocks in markdown files with preview in iframe: [example preview="top-frame" orientation="portrait"]

This PR contains:

  • Changed grow [example] plugin to support new mode and 'orientation' attribute
  • Changed Templates to render the preview
  • Guides and Tutorials with examples that did not work in inline preview mode now use top-frame (see attachments)
  • Information in the documentation for editors
  • Fix for standalone example code generation from inline code snippets
  • Fix for reload button of standalone example (ampbyexample) pages

Closes: #2053

top-frame-example-video
top-frame-example-landscape
top-frame-example-portrait

tharders and others added 30 commits June 28, 2019 12:34
To docs-detail and components-detail templates, where inline examples exist #2053
Implement orientation classes, set initial preview url, add dynamic source attr for realod, adjust amp-iframe attrs #2053
with new markup and features #2053
Increase thickness like the horizontal scrollbar, fix glitch in scrollbar-corner #2053
Remove general margin from amp-iframe, add padding to all ap--content containers, not only the first #2053
Better handle preview specific styling #2053
…ject/docs into feature/example_preview_in_iframe
Add padding to iframe and remove shading background-color #2053
Due to design review changes #2053
Since we have only one but for toggling, we have to adjust the code to boolean principle.
This is also a change due to design review #2053
Might fixes sporadically loading issues #2053
Since now multiple elements are used as controls, the orientation-toggle itself makes no sense anymore. This combines reload-button and orientation-toggle to one and styles it via code-preview.scss #2053
Due to design review changes #2053
Due to design review changes #2053
…ject/docs into feature/example_preview_in_iframe
@sebil
Copy link
Collaborator Author

sebil commented Jul 31, 2019

Hi @sebastianbenz ,

after a long try getting the preview rotate animation as intuitive and 'realistic' as on real-life devices, we decided sticking with this solution. (See screen capture below)

What I basically did is fading and rotating the <amp-iframe> (child) while morphing the <div> (parent) to it's new aspect ratio. Additionally I gave the parent background-color: black and set overflow: hidden to make it feel more like a real device.

IMPORTANT NOTE: To morph the size of the preview I had to transition padding and max-width of child and parent element. I know that these are not part of the white listed properties for keyframes, but in this case it is necessary to get the desired effect and since it causes no amp validation error, I think we can shut one eye on this... what do you think?

ezgif com-video-to-gif

P.S. the other thing is also fixed now, so the preview should keep it's dimensions anytime on any resolution.

P.P.S. I also got a fallback solution, if you don't like the rotation. It's just morphing the size of the preview, without fading and rotating anything.

But I hope you like it 👍

Good idea with putting the tool icons in the middle. Few high-level comments:

  • it'd be super cool if we could animate the preview rotation 🤪
  • on mobile, the preview does not rotate, but expand to the bottom. We should keep the preview dimensions during rotation.

@sebastianbenz
Copy link
Collaborator

Impressive! Thanks for trying! However, we shouldn't use non-hardware accelerated properties for the animation (we have to be a good example :-) ). What does the fallback look like?

@sebil
Copy link
Collaborator Author

sebil commented Jul 31, 2019

The fallback looks like this, but unfortunately it also uses non-hardware accelerated properties:

ezgif com-video-to-gif (1)

The padding-top of <amp-iframe> is changing from 56.25% to 177.78% (16:9 to 9:16) and the max-width of the parent <div> is changing from 56.25% to 100%.

Both elements have the transition property, which I'll remove now.

I'll try a new solution with just transform and opacity.

@sebil
Copy link
Collaborator Author

sebil commented Jul 31, 2019

Okay, 2 new solutions:

  1. I removed the transition properties and left the rotating animation as it was. This causes that the code block is jumping up and down, because of different dimension heights.

  2. I gave the landscape frame a dynamic margin, so it takes the same height as in portrait mode. This fixes the jumping code block issue, but waste space in landscape mode.

Screen captures:

First: code block is jumping up and down
ezgif com-video-to-gif (2)

Second: code block stands still, but space is wasted
ezgif com-video-to-gif (4)

@sebastianbenz
Copy link
Collaborator

Awesome! I think the first one is perfect! The jumping code block is not a problem.

@sebil
Copy link
Collaborator Author

sebil commented Jul 31, 2019

I'm glad you like it!

@sebil sebil marked this pull request as ready for review July 31, 2019 14:56
@sebil sebil changed the title Draft: Example code block preview in iframe ✨ Implement example code blocks with preview in iframe Jul 31, 2019
@sebil
Copy link
Collaborator Author

sebil commented Jul 31, 2019

@sebastianbenz This PR is ready for official review now. Don't be suprised, I just renamed it.

@LongoOfficial
Copy link

Awesome! I think the first one is perfect! The jumping code block is not a problem.

@sebastianbenz, I wouldn't recommend that compromise. without the animation of the iframe container between the two states, the rotation of only the content makes the example feels broken and not meaningful anymore. Although we put some effort to it, wouldn't it be better for the user if we do not have an animation at all?

@sebil
Copy link
Collaborator Author

sebil commented Aug 1, 2019

Hey @sebastianbenz
like we discusses I tried to give it a last shot based on your suggestion and here are my results:

I could achieve a morphing effect for the iframe container by adding a background div and change its transform: scale() values to fit in the correct dimensions.

This method brings two major issues with it: Sometimes the iframe is flickering and if you do a stress-test by rapidly clicking the button, it doesn't behave like expected. It looks broken, see screen captures below

  1. On white background color (your suggestion)
    ezgif com-video-to-gif (6)

  2. On black background color (as before)
    ezgif com-video-to-gif (7)

So @LongoOfficial and I wouldn't recommend this solution and we should rather stick without an animation then.

What do you think?

@sebastianbenz
Copy link
Collaborator

I agree, this doesn't work too well. One thing I'd be curious about: what if we remove the morph animation from iframe and speedup the rotation?

@sebil
Copy link
Collaborator Author

sebil commented Aug 1, 2019

I decreased the rotation angle from 75deg to 45deg and the animation duration from 650ms to 350ms so it's quite faster and snappier now, compared to the old version without morphing.

I like it better now, what do you say?

New version: 350ms, 45deg

ezgif com-video-to-gif (8)

Old version: 650ms, 75deg

ezgif com-video-to-gif (2)

@sebastianbenz
Copy link
Collaborator

I think 350ms, 45deg works best so far, maybe even only 250ms. Did you try the version without morph and animated placeholder?

Disabling rotation of iframe and just morph a background container via transform scale #2637
@sebil
Copy link
Collaborator Author

sebil commented Aug 2, 2019

As discussed I removed the rotation and speed up the morphing background container to 250ms.

Here is the result:
ezgif com-video-to-gif (1)

sebil added 2 commits August 2, 2019 18:10
Split fade and morph animations; use two seperate buttons and play the same morph animation reverse on the second button; hide and show buttons to keep feeling of one toggle button; use toggleClass to prevent use of amp-bind. #2637
Add overflow: auto; to nav
Copy link
Collaborator

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

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

Whoop! Whoop! Thanks a lot Sebil!

@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

ℹ️ Googlers: Go here for more info.

@sebastianbenz
Copy link
Collaborator

Are we good to merge or is anything missing?

@sebil
Copy link
Collaborator Author

sebil commented Aug 2, 2019

From my side we are ready. The only things that are missing are planned for the next steps, eg. the 'side-frame' preview, update for the sampler, etc.

@sebastianbenz sebastianbenz merged commit 217ffb9 into future Aug 2, 2019
@sebastianbenz sebastianbenz deleted the feature/example_preview_in_iframe branch August 2, 2019 18:21
@sebil sebil restored the feature/example_preview_in_iframe branch August 5, 2019 08:50
@matthiasrohmer matthiasrohmer deleted the feature/example_preview_in_iframe branch October 8, 2019 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate inline doc samples to preview.amp.dev
5 participants