I have an events section which has section headings containing the date. I need to be able to jump to specific dates, as well as have the initial scroll position set to the first date in the future.
In order to jump to specific dates I have tried storing their y positions in state.
renderSectionHeader= (sectionData, sectionID) => (
<View
onLayout={(event) => {
const { y } = event.nativeEvent.layout;
const sectionPosition = { [sectionID]: y };
const sectionPositions = Object.assign({}, this.state.sectionPositions, sectionPosition);
this.setState({ sectionPositions });
}}
...
I ran into problems with this approach though as renderSectionHeader is not called on elements which are further down the list (due to the lazy rendering).
I have then tried calculating the position mathematically , but this then causes the rendering of each section to show on screen while it is moving closer to the given date.
Is there a way of achieving what I need?
RELATED
React Native ListView: How to scroll to a particular row
https://github.com/facebook/react-native/issues/499
UPDATE
In my app I know all the rows are the exact same height.
Using contentOffset={{ y: offsetY }}
rather than setScroll
does not work, since it still needs to render all items up to the given item to work.
Using initialListSize={99999999}
does work, but makes the page very slow, and I have been warned against using it.
UPDATE 2
Is it possible to provide my initial content to datasource, and then update the data to add extra items in before and after the elements currently on screen?
Or is there a library I haven't found which does what I need?
listView
. I assume that even on native (iOS) u'll have this problem. – VasqueslistView
. I think that jump to position isn't the best UX. Maybe instead of jump to... try to add an index screen and push the selected one. But again, It's just my small opinion :) – VasquesinitialListSize={99999999}
you can try setting it to the index of the desired item, plus a screen worth of it. – Entoblast