bamlab / react-tv-space-navigation

A React Native module to handle spatial navigation for a TV application in a 100% cross-platform way
https://bamlab.github.io/react-tv-space-navigation/
MIT License
205 stars 18 forks source link

SpatialNavigationVirtualizedList removing items on scroll with scrollBehavior #119

Open jonp-iversoft opened 5 months ago

jonp-iversoft commented 5 months ago

Describe the bug When a SpatialNavigationVirtualizedList has a scrollBehavior of stick-to-end or jump-on-scroll, as the items are scrolled before it reaches the end, previous items are removed from the render list and are no longer shown when they should still be on screen.

It seems the behavior of stick-to-start is still applied as the items are moved and removed in the same way in that view. The only difference is in stick-to-start the list is scrolled

To Reproduce

<View style={styles.listContainer}>
        <SpatialNavigationVirtualizedList
          scrollBehavior="stick-to-end"
          orientation="vertical"
          data={data}
          renderItem={({ item }) => (
           <SpatialNavigationNode isFocusable>
              {({ isFocused }) => (
                <View
                  style={[styles.row, isFocused ? styles.rowFocused : null]}
                  aria-label={`rowItem_${index}`}>
                  <Text>{index}</Text>
                </View>
              )}
            </SpatialNavigationNode>
          )}
          itemSize={100}
          numberOfRenderedItems={15}
          numberOfItemsVisibleOnScreen={10}
        />
      </View>

const styles = StyleSheet.create({
  listContainer: {
    width: 1920,
    height: 1080,
  },
  row: {
    height: 100,
    width: 1920,
    backgroundColor: 'red,
  },
  rowFocused: {
    backgroundColor: 'hotpink'
  },
});

Expected behavior Items should continue to be rendered until the end of the visible list is hit, the items move, and then any items not shown on the screen can be removed.

Screenshots image image

Version and OS

pierpo commented 5 months ago

Hey!

I think we have a little bug with some scrollBehaviours. Can you try doubling numberOfRenderedItems={15} to numberOfRenderedItems={30}?

Thanks 😊

jonp-iversoft commented 5 months ago

In that case, the scroll works mostly as expected, but the top item disappears / is removed as the animation is happening. Setting numberOfRenderedItems={32} resolves the issue completely in my example. However that does affect lazy loading data and could impact performance

pierpo commented 5 months ago

OK, then it's a bug we are aware of but needs fixing indeed. That could affect performance indeed!

I can't give any ETA yet for this one, sorry 🙈

jonp-iversoft commented 5 months ago

sounds good! Thanks for looking into it!

pierpo commented 3 weeks ago

Hey! We had a first fix for the stick-to-end behaviour. Not published yet 😄

https://github.com/bamlab/react-tv-space-navigation/pull/148