From 068a4b73123440dada8f587175f1fe17e123f63b Mon Sep 17 00:00:00 2001 From: Harald Fassler Date: Thu, 30 May 2019 18:25:20 +0200 Subject: [PATCH 1/3] follow-up fix to #2871 --- .../render-dom/wrappers/Element/index.ts | 2 ++ src/runtime/internal/animations.ts | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/compiler/compile/render-dom/wrappers/Element/index.ts b/src/compiler/compile/render-dom/wrappers/Element/index.ts index 41db1c03a0..712fab3eca 100644 --- a/src/compiler/compile/render-dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render-dom/wrappers/Element/index.ts @@ -763,6 +763,7 @@ export default class ElementWrapper extends Wrapper { if (!this.node.animation) return; const { component } = this.renderer; + const { outro } = this.node; const rect = block.get_unique_name('rect'); const stop_animation = block.get_unique_name('stop_animation'); @@ -777,6 +778,7 @@ export default class ElementWrapper extends Wrapper { block.builders.fix.add_block(deindent` @fix_position(${this.var}); ${stop_animation}(); + ${outro && `@prepare_outro(${this.var}, ${rect});`} `); const params = this.node.animation.expression ? this.node.animation.expression.render(block) : '{}'; diff --git a/src/runtime/internal/animations.ts b/src/runtime/internal/animations.ts index 5a055ba6d2..b1b4a0cf8a 100644 --- a/src/runtime/internal/animations.ts +++ b/src/runtime/internal/animations.ts @@ -77,6 +77,10 @@ export function create_animation(node: Element & ElementCSSInlineStyle, from: Po return stop; } +export function prepare_outro(node: Element & ElementCSSInlineStyle, rect: PositionRect) { + add_transform(node, rect); +} + export function fix_position(node: Element & ElementCSSInlineStyle) { const style = getComputedStyle(node); @@ -86,13 +90,17 @@ export function fix_position(node: Element & ElementCSSInlineStyle) { node.style.position = 'absolute'; node.style.width = width; node.style.height = height; - const b = node.getBoundingClientRect(); + add_transform(node, a); + } +} - if (a.left !== b.left || a.top !== b.top) { - const style = getComputedStyle(node); - const transform = style.transform === 'none' ? '' : style.transform; +function add_transform(node: Element & ElementCSSInlineStyle, a: PositionRect) { + const b = node.getBoundingClientRect(); - node.style.transform = `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`; - } + if (a.left !== b.left || a.top !== b.top) { + const style = getComputedStyle(node); + const transform = style.transform === 'none' ? '' : style.transform; + + node.style.transform = `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`; } } From ef74838e1e68fce489f6a7cab8526dee38b253c5 Mon Sep 17 00:00:00 2001 From: Harald-1 <51047840+Harald-1@users.noreply.github.com> Date: Mon, 3 Jun 2019 21:42:30 +0200 Subject: [PATCH 2/3] Apply suggestions from code review call add_transform directly instead of wrapping it into prepare_outro Co-Authored-By: Rich Harris --- src/compiler/compile/render-dom/wrappers/Element/index.ts | 2 +- src/runtime/internal/animations.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/compile/render-dom/wrappers/Element/index.ts b/src/compiler/compile/render-dom/wrappers/Element/index.ts index 712fab3eca..65d008278f 100644 --- a/src/compiler/compile/render-dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render-dom/wrappers/Element/index.ts @@ -778,7 +778,7 @@ export default class ElementWrapper extends Wrapper { block.builders.fix.add_block(deindent` @fix_position(${this.var}); ${stop_animation}(); - ${outro && `@prepare_outro(${this.var}, ${rect});`} + ${outro && `@add_transform(${this.var}, ${rect});`} `); const params = this.node.animation.expression ? this.node.animation.expression.render(block) : '{}'; diff --git a/src/runtime/internal/animations.ts b/src/runtime/internal/animations.ts index b1b4a0cf8a..6a7f9e7828 100644 --- a/src/runtime/internal/animations.ts +++ b/src/runtime/internal/animations.ts @@ -94,7 +94,7 @@ export function fix_position(node: Element & ElementCSSInlineStyle) { } } -function add_transform(node: Element & ElementCSSInlineStyle, a: PositionRect) { +export function add_transform(node: Element & ElementCSSInlineStyle, a: PositionRect) { const b = node.getBoundingClientRect(); if (a.left !== b.left || a.top !== b.top) { From 2b1ff3f487e7c88c33b51f62fa50511a373aac40 Mon Sep 17 00:00:00 2001 From: Harald Fassler Date: Mon, 3 Jun 2019 21:54:48 +0200 Subject: [PATCH 3/3] remove prepare_outro --- src/runtime/internal/animations.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/runtime/internal/animations.ts b/src/runtime/internal/animations.ts index 6a7f9e7828..b0357647f5 100644 --- a/src/runtime/internal/animations.ts +++ b/src/runtime/internal/animations.ts @@ -77,10 +77,6 @@ export function create_animation(node: Element & ElementCSSInlineStyle, from: Po return stop; } -export function prepare_outro(node: Element & ElementCSSInlineStyle, rect: PositionRect) { - add_transform(node, rect); -} - export function fix_position(node: Element & ElementCSSInlineStyle) { const style = getComputedStyle(node);