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

✨ [Story bodymoving] Support amp-bodymovin-animation on amp-story-grid-layer #38239

Merged
merged 31 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6aabe91
Added tasts
mszylkowski Dec 21, 2021
dc1fa87
Undo
mszylkowski Dec 21, 2021
d707e5b
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Dec 28, 2021
0e3df75
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Dec 28, 2021
a3f7bd0
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 4, 2022
8c5119c
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 6, 2022
77f8435
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 10, 2022
16e712e
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 19, 2022
8088eb7
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 25, 2022
3858b2a
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 28, 2022
e12d2f6
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 31, 2022
2a29105
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Feb 1, 2022
a5b781f
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Feb 10, 2022
b8006ee
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 8, 2022
b570e86
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 10, 2022
6b7e456
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 22, 2022
50bdff8
Merge branch 'ampproject:main' into main
mszylkowski Mar 24, 2022
267ae0e
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 29, 2022
c7edd8c
Merge branch 'main' of github.com:mszylkowski/amphtml
mszylkowski Mar 29, 2022
9842a23
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 29, 2022
83e25bb
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Apr 4, 2022
9ded8f1
Merge branch 'main' of github.com:mszylkowski/amphtml; branch 'main' …
mszylkowski Apr 5, 2022
4f7b975
Merge branch 'ampproject:main' into main
mszylkowski Apr 6, 2022
cf38c3f
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Apr 29, 2022
fe714b6
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski May 16, 2022
6c5dede
Merge branch 'ampproject:main' into main
mszylkowski May 24, 2022
bf0d69f
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski May 24, 2022
ef38e6b
Merge branch 'main' of github.com:mszylkowski/amphtml
mszylkowski May 24, 2022
8dcd16e
Added support for bodymovin
mszylkowski May 26, 2022
d355b6d
Rename to BodymovinAnimationRunner
mszylkowski May 26, 2022
c075f35
Simplified executeAction params
mszylkowski May 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions examples/amp-story/amp-story-animation.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,13 @@
<meta charset="utf-8" />
<title>amp-animation inside amp-story</title>
<link rel="canonical" href="." />
<meta
name="viewport"
content="width=device-width,minimum-scale=1,initial-scale=1"
/>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"/>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script
async
custom-element="amp-story"
src="https://cdn.ampproject.org/v0/amp-story-1.0.js"
></script>
<script
async
custom-element="amp-video"
src="https://cdn.ampproject.org/v0/amp-video-0.1.js"
></script>
<script
async
custom-element="amp-animation"
src="https://cdn.ampproject.org/v0/amp-animation-0.1.js"
></script>
<script async custom-element="amp-story" src="https://cdn.ampproject.org/v0/amp-story-1.0.js"></script>
<script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script>
<script async custom-element="amp-animation" src="https://cdn.ampproject.org/v0/amp-animation-0.1.js"></script>
<script async custom-element="amp-bodymovin-animation" src="https://cdn.ampproject.org/v0/amp-bodymovin-animation-0.1.js"></script>
<style amp-custom>
body {
font-family: sans-serif;
Expand Down Expand Up @@ -160,6 +146,12 @@
</div>
</amp-story-grid-layer>
</amp-story-page>
<amp-story-page id="bodymovin">
<amp-story-grid-layer template="vertical">
<amp-bodymovin-animation layout="responsive" width="200" height="200" src="https://nainar.github.io/loader.json" loop>
</amp-bodymovin-animation>
</amp-story-grid-layer>
</amp-story-page>
</amp-story>
</body>
</html>
4 changes: 4 additions & 0 deletions extensions/amp-story/1.0/amp-story.css
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,7 @@ amp-story .amp-video-eq,
.i-amphtml-story-page-play-icon {
background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 48 48" fill="#FFF"><path d="M0 0h48v48H0z" fill="none"/><path d="M24 4a20 20 0 1 0 0 40 20 20 0 0 0 0-40zm-4 29V15l12 9-12 9z"/></svg>') !important;
}

amp-bodymovin-animation, amp-bodymovin-animation * {
pointer-events: none !important;
}
82 changes: 81 additions & 1 deletion extensions/amp-story/1.0/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const DEFAULT_EASING = 'cubic-bezier(0.4, 0.0, 0.2, 1)';
* TODO(alanorozco): maybe memoize?
*/
export function hasAnimations(element) {
const selector = `${ANIMATABLE_ELEMENTS_SELECTOR},>amp-story-animation`;
const selector = `${ANIMATABLE_ELEMENTS_SELECTOR},>amp-story-animation,amp-bodymovin-animation`;
return !!scopedQuerySelector(element, selector);
}

Expand Down Expand Up @@ -700,6 +700,12 @@ export class AnimationManager {
})
)
)
.concat(
Array.prototype.map.call(
this.page_.querySelectorAll('amp-bodymovin-animation'),
(el) => new BodymovinAnimationRunner(el)
)
)
.filter(Boolean);
}
return devAssert(this.runners_);
Expand Down Expand Up @@ -881,3 +887,77 @@ export class AnimationSequence {
return this.subscriptionPromises_[id];
}
}

export class BodymovinAnimationRunner {
/**
* @param {!Element} bodymovinAnimationEl
*/
constructor(bodymovinAnimationEl) {
this.bodymovinAnimationEl_ = bodymovinAnimationEl;
this.pause();
}

/**
* Pauses the bodymovin animation.
*/
pause() {
this.executeAction_({method: 'pause', satisfiesTrust: () => true});
}

/**
* Plays the bodymovin animation.
*/
resume() {
this.executeAction_({method: 'play', satisfiesTrust: () => true});
}

/**
* Starts the bodymovin animation.
*/
start() {
this.resume();
}

/**
* Seeks the bodymovin animation to the first frame.
*/
applyFirstFrame() {
this.executeAction_({
method: 'seekTo',
satisfiesTrust: () => true,
args: {
percent: 0,
},
});
}

/**
* Seeks the bodymovin animation to the last frame.
*/
applyLastFrame() {
this.executeAction_({
method: 'seekTo',
satisfiesTrust: () => true,
args: {
percent: 1,
},
});
}

/**
* Cancels the bodymovin animation by pausing it.
*/
cancel() {
this.pause();
}

/**
* @param {!any} action
* @private
*/
executeAction_(action) {
this.bodymovinAnimationEl_.getImpl().then((impl) => {
impl.executeAction(action);
});
}
}
1 change: 1 addition & 0 deletions extensions/amp-story/validator-amp-story.protoascii
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ descendant_tag_list: {
tag: "ADDRESS"
tag: "AMP-ANALYTICS"
tag: "AMP-AUDIO"
tag: "AMP-BODYMOVIN-ANIMATION"
tag: "AMP-DATE-COUNTDOWN"
tag: "AMP-DATE-DISPLAY"
tag: "AMP-EXPERIMENT"
Expand Down