From 3f5ef5ce33aa3981f753910fe8c1000664934c16 Mon Sep 17 00:00:00 2001 From: Hamed Baatour Date: Thu, 30 Apr 2020 22:00:58 +0300 Subject: [PATCH 1/2] add checks before applying any styling Fixes #261 --- src/Plugins/SwapAnimation/SwapAnimation.js | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Plugins/SwapAnimation/SwapAnimation.js b/src/Plugins/SwapAnimation/SwapAnimation.js index d8900278..0fba3c7e 100644 --- a/src/Plugins/SwapAnimation/SwapAnimation.js +++ b/src/Plugins/SwapAnimation/SwapAnimation.js @@ -108,24 +108,30 @@ export default class SwapAnimation extends AbstractPlugin { */ function animate(from, to, {duration, easingFunction, horizontal}) { for (const element of [from, to]) { - element.style.pointerEvents = 'none'; + if (element && element.style) { + element.style.pointerEvents = 'none'; + } } - if (horizontal) { - const width = from.offsetWidth; - from.style.transform = `translate3d(${width}px, 0, 0)`; - to.style.transform = `translate3d(-${width}px, 0, 0)`; - } else { - const height = from.offsetHeight; - from.style.transform = `translate3d(0, ${height}px, 0)`; - to.style.transform = `translate3d(0, -${height}px, 0)`; + if (from && to && from.style && to.style) { + if (horizontal) { + const width = from.offsetWidth; + from.style.transform = `translate3d(${width}px, 0, 0)`; + to.style.transform = `translate3d(-${width}px, 0, 0)`; + } else { + const height = from.offsetHeight; + from.style.transform = `translate3d(0, ${height}px, 0)`; + to.style.transform = `translate3d(0, -${height}px, 0)`; + } } - + requestAnimationFrame(() => { for (const element of [from, to]) { - element.addEventListener('transitionend', resetElementOnTransitionEnd); - element.style.transition = `transform ${duration}ms ${easingFunction}`; - element.style.transform = ''; + if (element && element.style && element.addEventListener) { + element.addEventListener('transitionend', resetElementOnTransitionEnd); + element.style.transition = `transform ${duration}ms ${easingFunction}`; + element.style.transform = ''; + } } }); } From c1caff7a98f9938a25dfa55f61fe9da49094abba Mon Sep 17 00:00:00 2001 From: Hamed Baatour Date: Thu, 30 Apr 2020 22:14:55 +0300 Subject: [PATCH 2/2] fix styling - prettier --- src/Plugins/SwapAnimation/SwapAnimation.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Plugins/SwapAnimation/SwapAnimation.js b/src/Plugins/SwapAnimation/SwapAnimation.js index 0fba3c7e..fcf78206 100644 --- a/src/Plugins/SwapAnimation/SwapAnimation.js +++ b/src/Plugins/SwapAnimation/SwapAnimation.js @@ -110,7 +110,7 @@ function animate(from, to, {duration, easingFunction, horizontal}) { for (const element of [from, to]) { if (element && element.style) { element.style.pointerEvents = 'none'; - } + } } if (from && to && from.style && to.style) { @@ -124,14 +124,14 @@ function animate(from, to, {duration, easingFunction, horizontal}) { to.style.transform = `translate3d(0, -${height}px, 0)`; } } - + requestAnimationFrame(() => { for (const element of [from, to]) { if (element && element.style && element.addEventListener) { element.addEventListener('transitionend', resetElementOnTransitionEnd); element.style.transition = `transform ${duration}ms ${easingFunction}`; element.style.transform = ''; - } + } } }); }