recyclerlistview icon indicating copy to clipboard operation
recyclerlistview copied to clipboard

Scrolling to specific item in the recyclelist view

Open farizattamimi opened this issue 4 years ago • 6 comments

I am trying to make the scrollTo specific item in the recyclerlistview. However, the event.nativeEvent.layout in the onLayout returns the y value as 0. Other values such as width and height are returned correctly. I think the y is 0 because the item is relative to the parent view/component from the recyclerlistview library. Is there any other way for me to get a correct y value relative to the scrollview of the recyclerlistview ? Thank you so much

farizattamimi avatar Jun 26 '20 16:06 farizattamimi

Any solution found ?

Megha060199 avatar Nov 24 '20 15:11 Megha060199

hi you should use from external scroll View and ref this worked for me after setting ref you can call any function you want on this same as vanilla scroll view

zarin-maruf avatar Jan 20 '21 05:01 zarin-maruf

Can you elaborate on use of external scroll view ref? Perhaps a snippet of code? Thanks.

glenne avatar Jan 26 '21 00:01 glenne

@MarufSharifi can you show any code please? I have the same problem

Brma1048 avatar Feb 11 '21 13:02 Brma1048

Edit: I have found a solution

const scrollRef = useRef();

const scrollToTop = () => {
    scrollRef?.current._scrollViewRef.scrollTo({ x: 0,
       y: 0,
       animated: true });
 };

...<RecyclerListView
                  layoutProvider={_layoutProvider}
                  dataProvider={dataProvider}
                  rowRenderer={_rowRenderer}
                  scrollViewProps={{
                     ref: scrollRef
                  }}
/>

Brma1048 avatar Feb 11 '21 13:02 Brma1048

Can you share snippet for class based as well. I tried createRef instead of useRef, it didn't work. Also I am using forceNonDeterministic true. @Brma1048

tragicmj avatar Dec 16 '22 06:12 tragicmj