facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.09k stars 24.19k forks source link

[SectionList][inverted] SectionList headers are sticky-at-the-top-footers if the list is inverted #18945

Open terrysahaidak opened 6 years ago

terrysahaidak commented 6 years ago

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:

kapture 2018-04-19 at 13 46 22

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:

kapture 2018-04-19 at 13 43 42

almorak commented 6 years ago

try: set sectionlist stickySectionHeadersEnabled={false}
use renderSectionFooter instead of renderSectionHeader with inverted case

terrysahaidak commented 6 years ago

@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

terrysahaidak commented 6 years ago

Hi @janicduplessis, you have worked on support of inverted sticky headers, but there are some issues, could you please look at them?

stale[bot] commented 5 years ago

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.

terrysahaidak commented 5 years ago

Still there is no any workaround or fix for that, so it can't be closed.

iamolegga commented 5 years ago

Any workaround on this?

terrysahaidak commented 5 years ago

@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.

brunoro commented 5 years ago

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?

die20 commented 5 years ago

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>
terrysahaidak commented 5 years ago

Could you please provide an example with that fix applied to my repro?

Here is what I've got:

image

stale[bot] commented 4 years ago

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.

terrysahaidak commented 4 years ago

This hasn't been fixed yet.

stepupithubapp commented 4 years ago

just simple use renderSectionFooter then header and make inverted true simple

je7ov commented 4 years ago

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

ydv0121 commented 4 years ago

+1

djhr commented 4 years ago

opened this issue on 19 Apr 2018

irfaan commented 4 years ago

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.

terrysahaidak commented 4 years ago

I just checked this issue on 0.62 and seems like it's still there.

deniscreamer commented 4 years ago

Please provide us a new param stickySectionFooterEnabled

franciscosolla commented 4 years ago

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.

stale[bot] commented 4 years ago

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.

terrysahaidak commented 4 years ago

Still an issue.

vibinjoby commented 3 years ago

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 👍🏻

SrBrahma commented 3 years ago

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.

icecapp commented 2 years ago

Still an issue on stock installs

fangpenlin commented 2 years ago

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.

sergeymild commented 2 years ago

Still an issue on stock installs

github-actions[bot] commented 1 year ago

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.

SrBrahma commented 1 year ago

Up

adidoes commented 1 year ago

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.

jailsonpaca commented 1 year ago

up

mtnt commented 1 year ago

still an issue... "After all this time? - Always" =)

iamolegga commented 1 year ago

image

Ilyxxxaa commented 1 year ago

Please repair it

timothyerwin commented 1 year ago

how is this still an issue? is it bc all resources are on the metaverse?

ayushneekhar commented 1 year ago

Is it that hard to implement stickySectionFooterEnabled?

github-actions[bot] commented 8 months ago

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.

SimpleCreations commented 8 months ago

Still an issue

VadymVashchuk commented 6 months ago

After 6 years still an issue

adsalihac commented 6 months ago

😀

eljonathas commented 4 months ago

24/04/2024 and still an issue

MrQazi665 commented 3 months ago

Hello,

I'm interested in making the 'renderSectionFooter' sticky. Is this possible?

image
HuziMuzi commented 1 week ago

28/08/2024 still an issue