From 8a26651203839095ad70df0433bb443543d66db2 Mon Sep 17 00:00:00 2001 From: cc-matthias-m <66009541+cc-matthias-m@users.noreply.github.com> Date: Fri, 7 Aug 2020 20:48:29 +0200 Subject: [PATCH] Clear scrollable timer when component unmounts (#219) Fixes "null is not an object (evaluating 'n.rlv.scrollToIndex') in Scroller.js:155" --- src/Scroller.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Scroller.js b/src/Scroller.js index b765342..faa22ef 100644 --- a/src/Scroller.js +++ b/src/Scroller.js @@ -32,6 +32,8 @@ export default class CalendarScroller extends Component { constructor(props) { super(props); + this.timeoutResetPositionId = null; + this.updateLayout = renderDayParams => { const itemHeight = renderDayParams.size; const itemWidth = itemHeight + renderDayParams.marginHorizontal * 2; @@ -67,6 +69,13 @@ export default class CalendarScroller extends Component { }; } + componentWillUnmount() { + if (this.timeoutResetPositionId !== null) { + clearTimeout(this.timeoutResetPositionId); + this.timeoutResetPositionId = null; + } + } + componentDidUpdate(prevProps, prevState) { let newState = {}; let updateState = false; @@ -151,7 +160,8 @@ export default class CalendarScroller extends Component { this.rlv.scrollToIndex(i, false); // RecyclerListView sometimes returns position to old index after // moving to the new one. Set position again after delay. - setTimeout(() => { + this.timeoutResetPositionId = setTimeout(() => { + this.timeoutResetPositionId = null; this.rlv.scrollToIndex(i, false); this.shifting = false; // debounce }, 800);