react-native
react-native copied to clipboard
[SectionList][inverted] SectionList headers are sticky-at-the-top-footers if the list is inverted
- [x] I have reviewed the documentation
- [x] I have searched existing issues
- [x] I am using the latest React Native version
Environment
Environment: OS: macOS High Sierra 10.13.1 Node: 8.6.0 Yarn: 1.5.1 npm: 4.6.1 Watchman: 4.9.0 Xcode: Xcode 9.0.1 Build version 9A1004 Android Studio: Not Found
Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: 0.55.3 => 0.55.3
Steps to Reproduce
Clone this repository and run it via react-native run-ios.
Observe the section separators are in wrong (randomly?) places.
Expected Behavior
The section list headers should be in the top of the section instead of the bottom like section footers do with an inverted list (but they aren't sticky).
Expected gif:

Actual Behavior
The section headers are footers instead of headers. They are sticky because of https://github.com/facebook/react-native/pull/17762 but still footers, not headers.
Sample code:
export default class App extends React.Component {
render() {
return (
<View style={s.container}>
<SectionList
inverted
sections={mock.sections}
maxToRenderPerBatch={10}
initialNumToRender={10}
style={{ flex: 1 }}
keyExtractor={(item) => item.messageId}
renderSectionHeader={sectionProps => (
<SectionHeader
{...sectionProps}
/>
)}
renderItem={({ item }) => (
<ListItem
item={item}
/>
)}
ItemSeparatorComponent={ItemSeparator}
/>
/>
</View>
);
}
}
Problem Gif:

try:
set sectionlist stickySectionHeadersEnabled={false}
use renderSectionFooter instead of renderSectionHeader with inverted case
@almorak thanks for your advice, but it won't fix the bug at all. Sticky headers are common behavior for chat date headers, I still need them.
Also, see my second issue: https://github.com/facebook/react-native/issues/18943
Hi @janicduplessis, you have worked on support of inverted sticky headers, but there are some issues, could you please look at them?
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.
Still there is no any workaround or fix for that, so it can't be closed.
Any workaround on this?
@iamolegga I just don't use section list with sticky headers currently. Just simply FlatList with custom functions for creating sections and then render it.
Also struggling with this here, I'm implementing infinite scroll to the top and need sticky headers (or inverted footers, apparently). Any solutions so far?
I've been able to use this as a workaround:
<SectionList>
renderSectionFooter={<View style={{transform: [{ scaleY: -1 }]}}>...</View>}
renderItem={<View style={{transform: [{ scaleY: -1 }]}}>...</View>}
inverted={true}
</SectionList>
Could you please provide an example with that fix applied to my repro?
Here is what I've got:

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.
This hasn't been fixed yet.
just simple use renderSectionFooter then header and make inverted true simple
I'm having the same issue with inverted sticky headers.
just simple use renderSectionFooter then header and make inverted true simple
This doesn't address the issue. We're looking to have sticky section headers on inverted lists
+1
opened this issue on 19 Apr 2018
Not able to find a good solution here. What we really need is the ability to make sticky footers a possibility. Then, when a list is inverted, you can switch stickyFooters on to keep it sticky at the top and start above the content of the section.
I just checked this issue on 0.62 and seems like it's still there.
Please provide us a new param stickySectionFooterEnabled
If someone is still stuck on it, Medium has posted a workaround: https://medium.com/@smali.kazmi/react-native-sticky-date-like-whatsapp-using-inverted-sectionlist-c141f5933d55
in which I've made some changes to make it desappear when not needed anymore: just setting it to null when lastItem is the sectionHeader (sectionFooter)
function updateCurrentDate({ viewableItems, changed }: { viewableItems: Array<ViewToken>; changed: Array<ViewToken> }) {
if (viewableItems && viewableItems.length) {
const lastItem = viewableItems.pop()
if (lastItem && lastItem.item.title && lastItem.item.title === currentDate) setCurrentDate(null)
else if (lastItem && lastItem.section) setCurrentDate(lastItem.section.title)
else setCurrentDate(null)
}
else setCurrentDate(null)
}
also, changed the style of the date header to be absolute, so it appears over the list.
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.
Still an issue.
If someone is still stuck on it, Medium has posted a workaround: https://medium.com/@smali.kazmi/react-native-sticky-date-like-whatsapp-using-inverted-sectionlist-c141f5933d55
in which I've made some changes to make it desappear when not needed anymore: just setting it to null when lastItem is the sectionHeader (sectionFooter)
function updateCurrentDate({ viewableItems, changed }: { viewableItems: Array<ViewToken>; changed: Array<ViewToken> }) { if (viewableItems && viewableItems.length) { const lastItem = viewableItems.pop() if (lastItem && lastItem.item.title && lastItem.item.title === currentDate) setCurrentDate(null) else if (lastItem && lastItem.section) setCurrentDate(lastItem.section.title) else setCurrentDate(null) } else setCurrentDate(null) }also, changed the style of the date header to be absolute, so it appears over the list.
yo man, this is the solution I was looking for, you're a lifesaver. Thanks, buddy 👍🏻
It is a shame that is hasn't been officially fixed yet.
There should be a new "inverted" prop to make the life of us who make "chat-like" components better. Inverted just sucks.
Still an issue on stock installs
Hey folks 👋
This issue troubled me as I also need the sticky header to work for inverted section list for the app I am building. To solve the problem, I create an InvertedSectionList component for fixing this issue outside of RN code base. I open sourced it here
https://github.com/LaunchPlatform/inverted-section-list
For now I only built it to make it works for my app, didn't test it with other corner cases. My InvertedSectionList component is basically copying source code from RN repo and made critical changes only to make the sticky header (footer actually) works. So in theory, if I port the changes back to RN, it should fix this. I am trying my best to see if I can find time to create PRs to fix this issue. However, if you want, please feel free to port the changes I made and open PRs to RN's repo. In the mean time hopefully the component I made can solve your problem as well before it's fixed in the upstream.
Still an issue on stock installs
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Up
I can't believe this is still an issue after so many years and how common of a design it is in today's apps.