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

Remove vsync guards to fx presets #19197

Merged
merged 2 commits into from Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
139 changes: 36 additions & 103 deletions extensions/amp-fx-collection/0.1/providers/amp-fx-presets.js
Expand Up @@ -46,20 +46,11 @@ export const Presets = {
const offset = (fxElement.adjustedViewportHeight - top) * adjustedFactor;
fxElement.setOffset(offset);

if (fxElement.isMutateScheduled()) {
return;
}

// If above the threshold of trigger-position
fxElement.setIsMutateScheduled(true);
fxElement.getResources().mutateElement(fxElement.getElement(),
function() {
fxElement.setIsMutateScheduled(false);
// Translate the element offset pixels.
setStyles(fxElement.getElement(),
{transform:
`translateY(${fxElement.getOffset().toFixed(0)}px)`});
});
// Translate the element offset pixels.
setStyles(fxElement.getElement(),
{transform:
`translateY(${fxElement.getOffset().toFixed(0)}px)`});
},
},
'fly-in-bottom': {
Expand All @@ -84,10 +75,6 @@ export const Presets = {
return;
}

if (fxElement.isMutateScheduled()) {
return;
}

// only do this on the first element
if (!fxElement.initialTrigger) {
fxElement.getResources().mutateElement(
Expand All @@ -103,17 +90,12 @@ export const Presets = {
}

// If above the threshold of trigger-position
fxElement.setIsMutateScheduled(true);
fxElement.getResources().mutateElement(
fxElement.getElement(), function() {
fxElement.setIsMutateScheduled(false);
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {
'transition-duration': fxElement.getDuration(),
'transition-timing-function': fxElement.getEasing(),
'transform': `translateY(-${fxElement.getFlyInDistance()}vh)`,
});
});
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {
'transition-duration': fxElement.getDuration(),
'transition-timing-function': fxElement.getEasing(),
'transform': `translateY(-${fxElement.getFlyInDistance()}vh)`,
});
},
},
'fly-in-left': {
Expand All @@ -136,10 +118,6 @@ export const Presets = {
return;
}

if (fxElement.isMutateScheduled()) {
return;
}

// only do this on the first element
if (!fxElement.initialTrigger) {
fxElement.getResources().mutateElement(
Expand All @@ -156,17 +134,12 @@ export const Presets = {
}

// If above the threshold of trigger-position
fxElement.setIsMutateScheduled(true);
fxElement.getResources().mutateElement(
fxElement.getElement(), function() {
fxElement.setIsMutateScheduled(false);
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {
'transition-duration': fxElement.getDuration(),
'transition-timing-function': fxElement.getEasing(),
'transform': `translateX(${fxElement.getFlyInDistance()}vw)`,
});
});
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {
'transition-duration': fxElement.getDuration(),
'transition-timing-function': fxElement.getEasing(),
'transform': `translateX(${fxElement.getFlyInDistance()}vw)`,
});
},
},
'fly-in-right': {
Expand All @@ -189,10 +162,6 @@ export const Presets = {
return;
}

if (fxElement.isMutateScheduled()) {
return;
}

// only do this on the first element
if (!fxElement.initialTrigger) {
fxElement.getResources().mutateElement(
Expand All @@ -209,17 +178,12 @@ export const Presets = {
}

// If above the threshold of trigger-position
fxElement.setIsMutateScheduled(true);
fxElement.getResources().mutateElement(
fxElement.getElement(), function() {
fxElement.setIsMutateScheduled(false);
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {
'transition-duration': fxElement.getDuration(),
'transition-timing-function': fxElement.getEasing(),
'transform': `translateX(-${fxElement.getFlyInDistance()}vw)`,
});
});
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {
'transition-duration': fxElement.getDuration(),
'transition-timing-function': fxElement.getEasing(),
'transform': `translateX(-${fxElement.getFlyInDistance()}vw)`,
});
},
},
'fly-in-top': {
Expand All @@ -244,10 +208,6 @@ export const Presets = {
return;
}

if (fxElement.isMutateScheduled()) {
return;
}

// only do this on the first element
if (!fxElement.initialTrigger) {
fxElement.getResources().mutateElement(
Expand All @@ -263,17 +223,12 @@ export const Presets = {
}

// If above the threshold of trigger-position
fxElement.setIsMutateScheduled(true);
fxElement.getResources().mutateElement(
fxElement.getElement(), function() {
fxElement.setIsMutateScheduled(false);
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {
'transition-duration': fxElement.getDuration(),
'transition-timing-function': fxElement.getEasing(),
'transform': `translateY(${fxElement.getFlyInDistance()}vh)`,
});
});
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {
'transition-duration': fxElement.getDuration(),
'transition-timing-function': fxElement.getEasing(),
'transform': `translateY(${fxElement.getFlyInDistance()}vh)`,
});
},
},
'fade-in': {
Expand All @@ -296,22 +251,13 @@ export const Presets = {
return;
}

if (fxElement.isMutateScheduled()) {
return;
}

// If above the threshold of trigger-position
fxElement.setIsMutateScheduled(true);
fxElement.getResources().mutateElement(
fxElement.getElement(), function() {
fxElement.setIsMutateScheduled(false);
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {
'transition-duration': fxElement.getDuration(),
'transition-timing-function': fxElement.getEasing(),
'opacity': 1,
});
});
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {
'transition-duration': fxElement.getDuration(),
'transition-timing-function': fxElement.getEasing(),
'opacity': 1,
});
},
},
'fade-in-scroll': {
Expand Down Expand Up @@ -343,10 +289,6 @@ export const Presets = {
return;
}

if (fxElement.isMutateScheduled()) {
return;
}

// Early exit if the animation doesn't need to repeat and it is fully
// opaque.
if (!fxElement.hasRepeat() && fxElement.getOffset() >= 1) {
Expand All @@ -361,18 +303,9 @@ export const Presets = {
(marginDelta * fxElement.viewportHeight);
fxElement.setOffset(offset);

if (fxElement.isMutateScheduled()) {
return;
}

// If above the threshold of trigger-position
fxElement.setIsMutateScheduled(true);
fxElement.getResources().mutateElement(fxElement.getElement(),
function() {
fxElement.setIsMutateScheduled(false);
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {opacity: fxElement.getOffset()});
});
// Translate the element offset pixels.
setStyles(fxElement.getElement(), {opacity: fxElement.getOffset()});
},
},
};
17 changes: 0 additions & 17 deletions extensions/amp-fx-collection/0.1/providers/fx-provider.js
Expand Up @@ -103,9 +103,6 @@ export class FxElement {
/** @private @const {!Element} */
this.element_ = element;

/** @private {boolean} */
this.mutateScheduled_ = false;

/** @private {number} */
this.offset_ = 0;

Expand Down Expand Up @@ -294,13 +291,6 @@ export class FxElement {
this.offset_ = offset;
}

/**
* @return {boolean}
*/
isMutateScheduled() {
return this.mutateScheduled_;
}

/**
* Boolean dictating whether or not the amp-fx preset has the `repeat`
* attribute set. The `repeat` attribute allows the animation to be fully
Expand All @@ -310,11 +300,4 @@ export class FxElement {
hasRepeat() {
return this.hasRepeat_;
}

/**
* @param {boolean} mutateScheduled
*/
setIsMutateScheduled(mutateScheduled) {
this.mutateScheduled_ = mutateScheduled;
}
}