Skip to content

Commit

Permalink
Clear scrollable timer when component unmounts (#219)
Browse files Browse the repository at this point in the history
Fixes "null is not an object (evaluating 'n.rlv.scrollToIndex') in Scroller.js:155"
  • Loading branch information
cc-matthias-m authored Aug 7, 2020
1 parent cc0b690 commit 8a26651
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8a26651

Please sign in to comment.