Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: Optimized SectionList does not rerender after scrollToLocation

I built an alphabet scrubber that scrolls a SectionList. The SectionList is optimized through the use of getItemLayout. If I scrub over the alphabet, the scrolling happens as planned, but the SectionList does not rerender until I release my finger from the screen.

See this expo snack

Anyone ideas on how to solve this?

Screenshot of example

like image 271
Gersom Avatar asked Nov 21 '17 10:11

Gersom


1 Answers

Solved it by going through the source code of PanResponder. PanResponder sets an interaction handle through the InteractionManager. You can access this handle through this.panResponder.getInteractionHandle() (undocumented feature), and then clear it everytime you scroll to a location in the SectionList:

if (this.panResponder.getInteractionHandle()) {
    InteractionManager.clearInteractionHandle(
        this.panResponder.getInteractionHandle()
    );
}

This will move the SectionList up in the queue for doing its visibility calculations and renders.

I advice to heavily optimize this by clearing the interaction handle as few times as possible, since the InteractionManager is used for performance reasons.

like image 151
Gersom Avatar answered Nov 02 '22 05:11

Gersom