gorhom / react-native-sticky-item

An interactive sticky item inspired by Facebook Stories.
MIT License
891 stars 48 forks source link

Render Separator should use React.memo #8

Closed hirbod closed 4 years ago

hirbod commented 4 years ago

https://github.com/gorhom/react-native-sticky-item/blob/master/src/StickyItemFlatList.tsx#L194

Since it should be a „Pure Component“. I would also think that the second parameter for „arePropsEqual“ could always return true in this case.

After I memoized this I could finally get rid of this VirtualizedList is large and slow to update message.

@gorhom

hirbod commented 4 years ago

Maybe like so

function separatorPropsEqual() {
  return true;
}
const renderSeparator = React.memo(
  () => <View style={{ width: SEPARATOR_SIZE }} />,
  separatorPropsEqual,
);
gorhom commented 4 years ago

hi @Hirbod , i'll work on it this weekend

hirbod commented 4 years ago

Maybe the separator should also be overwritable? And I am still feeling like decelerationRate should also be overwritable.

gorhom commented 4 years ago

@Hirbod have you tried to optimising the flatlist with windowSize & maxToRenderPerBatch ?

hirbod commented 4 years ago

@gorhom yes, but after diggin through a lot of posts I found out that also separator should be a Pure/Memoized Component

gorhom commented 4 years ago

okay, i can see the importance of this, i'll push it with the next release 👍

hirbod commented 4 years ago

Thanks. You could actually copy over my snippet (and format to your needs). Its working fine. Still thinking if passing own separator is important or not but I don't think that it should be, since the size is adjustable

gorhom commented 4 years ago

hmm i'll investigate it more, however for having a memoized separator, you could submit a pr :)

hirbod commented 4 years ago

Sure.

hirbod commented 4 years ago

PR sent #9

gorhom commented 4 years ago

thanks , i'll review it now :)

hirbod commented 4 years ago

I think the equal function check should be moved outside of the functional component

gorhom commented 4 years ago

released with v1.3.0