Search code examples
javascriptcssreact-nativereact-native-scrollview

ScrollView height does not update when deleting items inside


I have a ScrollView in my app which can contain enough content where I need to scroll to get at the bottom.

However if I scroll to the bottom and then delete some items, while the content inside the ScrollView gets smaller then ScrollView height stays the same as there is some space left under the last elements.

Only after I scroll the ScrollView for just a bit does the height of the ScrollView adapt to the content.

I tried to put a ref on ScrollView and then using

onContentSizeChange={()=> scrollViewRef.current.scrollToEnd()}

However that also scrolls scrollview to the end when the Screen is mounted and also once I delete an element for some reason I am not able to delete any of the other elements.

Like...something breaks.

Any idea what else I could do for the height of the ScrollView to resize before I do any movement of the ScrollView?


Solution

  • Adding this prop seems to solve the problem for me:

    maintainVisibleContentPosition={{ minIndexForVisible: 0 }}