components/calendar: Fix infinite loop when clicking during animation

Reason for the change

Setting currentIndex while interacting with a ListView does not seem to actually work. The resulted in resetViewPosition calling positionViewAtIndex continuously with a wrong index (0 or 2). Which on its turn resulted in the onAtYBeginningChanged or onAtYEndChanged slots being called again, which then call resetViewPosition again. This would then keep going until the shell is SIGKILL-ed.

The "RangeError: Maximum call stack size exceeded" from the bug report happened for a similar reason. Once the calendar had been dragged far enough, it would call handleDateChange, which calls handleDrag, which then calls resetViewPosition. This would also call positionViewAtIndex with the wrong index and call the slots again, which keeps going until the stack overflows.

Simply always calling positionViewAtIndex with index 1 prevents these loops from happening, without changing any functionality.

Test plan

The freezing issue can be reproduced with the existing calendar by dragging it far enough to go to the next month, and then clicking at least once, but multiple times increase the chance, while the animation plays. Doing the same thing after applying this fix should prevent this freeze from happening.

The error message in the output happens when dragging the calendar all the way to the bottom of the next month (or top of the previous month). Doing the same after applying the fix should not result in the error message anymore.

Bugs fixed

BUG: 511028

Merge request reports

Loading