From 68f3d003d6e841c864330fd5e7bcecadcc9b9178 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Wed, 6 Feb 2019 20:04:39 +0100 Subject: [PATCH] Refactor intersection observer article code --- .../intersection_observer_article.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/app/javascript/flavours/glitch/components/intersection_observer_article.js b/app/javascript/flavours/glitch/components/intersection_observer_article.js index 03d8f17c6b2..900c986380b 100644 --- a/app/javascript/flavours/glitch/components/intersection_observer_article.js +++ b/app/javascript/flavours/glitch/components/intersection_observer_article.js @@ -103,24 +103,23 @@ export default class IntersectionObserverArticle extends ImmutablePureComponent const { children, id, index, listLength, cachedHeight } = this.props; const { isIntersecting, isHidden } = this.state; + const style = {}; + if (!isIntersecting && (isHidden || cachedHeight)) { - return ( -
- {children && React.cloneElement(children, { hidden: true })} -
- ); + style.height = `${this.height || cachedHeight || 150}px`; + style.opacity = 0; + style.overflow = 'hidden'; } return ( -
- {children && React.cloneElement(children, { hidden: false })} +
+ {children && React.cloneElement(children, { hidden: !isIntersecting && (isHidden || cachedHeight) })}
); }