-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for section headers (SectionList?) #25
Comments
Eventually, yes! Currently it already supports See discussion below for more details. |
Hi @cooperka I'm finally getting round to migrating from
it looks like I can't do sectioned lists with Put another way, if I want to migrate my sectioned Thanks for your time! |
Hi @Leeds-eBooks, I too would like to start using the new components with Maps. I'm currently in the process of refactoring to make it easier to support new types of lists. I don't want to promise anything, but I'd love to have it ready this week if things work out well. Feel free to "watch" this repo to get release updates. Thanks! |
@cooperka Thanks very much! I will happily wait, having taken a look at the |
@cooperka I have just finished implementing |
Sure, feel free to post here and I'll try to get back to you as quickly as I can. Are you suggesting we don't support SectionList directly, but instead support Immutable.Map via VirtualizedList? Why wouldn't we just wrap SectionList (and maybe even WindowedList and all the other new lists)? |
Great, thanks. So I tried to make
Further, the docs for
I took a look at the The alternative is that we do wrap |
Hmm, I see what you mean. The API has changed significantly from ListView; I didn't realize SectionList took a totally different input prop. Transcribed here mostly for my own understanding: ListView: data: { section1: [row1, ...], section2: [], ... } SectionList: sections: [{ title: 'section1', data: [row1, ...] }, { title: 'section2', data: [] }, ...] I understand it's more verbose on purpose, but I wouldn't want to store my data that way, I'd rather store it in a map with the keys being the titles (like the original ListView with sectionHeaders). For the sake of API consistency, though, we should probably do the same as I'm starting to like your idea of simply supporting |
To sum up: I see no need to support immutable data with SectionList specifically, because of the aforementioned API changes. What I do see is a need for section headers generally, which can be achieved using |
My thoughts exactly! And yes, my aim in writing my implementation was to only swap my The one obstacle I see however is that the way I've done it, and the way you suggest, using The most important (and controversial?) piece of logic in my implementation is the function that flattens our nested immutable data structure (the // using an arrow function here for clarity but we'd use a method
data={(nestedMap) =>
nestedMap.reduce(
(map, subMap, key) => map.set(key, subMap).merge(subMap),
Map()
)
} As you can see, what we end up with is a flat For comparison, below is what function getItem(sections: ?$ReadOnlyArray<Item>, index: number): ?Item {
if (!sections) {
return null;
}
let itemIdx = index - 1;
for (let ii = 0; ii < sections.length; ii++) {
if (itemIdx === -1 || itemIdx === sections[ii].data.length) {
// We intend for there to be overflow by one on both ends of the list.
// This will be for headers and footers. When returning a header or footer
// item the section itself is the item.
return sections[ii];
} else if (itemIdx < sections[ii].data.length) {
// If we are in the bounds of the list's data then return the item.
return sections[ii].data[itemIdx];
} else {
itemIdx -= sections[ii].data.length + 2; // Add two for the header and footer
}
}
return null;
} Basically, for each index (and it's a 1-dimensional index) up to the total supplied by the |
That sounds about right -- if the list has infinite sections, they couldn't possibly flatten them all. Yay, functional programming! It certainly needs some testing, but I like your solution. Would you mind submitting a PR when you have time? I will likely end up tweaking things to play around with it so don't worry too much about making it perfect. |
Ok great, will do. Might be a few days, but I'll make a start right away. |
Hey @cooperka, I have one more little question now that I've made a (slightly delayed) start on this. We need some way to choose whether to treat if (Map.isMap(immutableData)) if (isImmutable(immutableData.first())) if (this.props.treatAsSections === true) |
See my PR: #34 |
Awesome! I left comments there addressing the above. |
No description provided.
The text was updated successfully, but these errors were encountered: