-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Add a prop to toggle ListView sticky section headers #11700
Add a prop to toggle ListView sticky section headers #11700
Conversation
@@ -472,9 +476,12 @@ var ListView = React.createClass({ | |||
if (props.removeClippedSubviews === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semi: Missing semicolon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👍 This comment was on the wrong line
* is pushed off the screen by the next section header. | ||
* @platform ios | ||
*/ | ||
stickySectionHeaders: React.PropTypes.bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like an array. Maybe stickySectionHeadersEnabled
is a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see what you mean. I was attempting to follow the convention set by removeClippedSubviews
, but I guess it would be clearer as stickySectionHeadersEnabled
. Should I make that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this extra flag? I believe it's possible to check sectionHeaderIndices
length instead. something like
if (sectionHeaderIndices.length) {
stickyHeaderIndices.concat(sectionHeaderIndices);
}
Does it make any sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kureev an extra flag is needed if we implement the sticky section header on Android as they have the different behavior by default
There is a discussion here #9957 and @janicduplessis did the same thing as @matto1990 did, though that PR was reverted then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked the code (sorry for not doing it before writing my previous comment): it seems you can flag stickySectionHeadersEnabled
(as @satya164 suggested) on line 419 and increment an index only if it's enabled. Then 479-484 won't be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the helpful insight, @nihgwu. It seems you knows more about this issue. I saw the last update on the followup PR has been made 28 days ago. Is there any work in progress?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kureev Previously the code would add in the indexes of all the sections headers whatever you set stickyHeaderIndices
to. It did this by sending this.props.stickyHeaderIndices.concat(sectionHeaderIndices)
to the ScrollView
which the ListView
uses. Because this happened within the ListView
, there didn't seem to be a way to not have the headers sticky. The documentation also suggested this with the way it was worded. stickyHeaderIndices
then essentially becomes the indexes of any additional views which you want to be sticky. Without this flag, section headers are always passed to the underlying ScrollView
.
This flag basically makes that single line of logic run conditionally only if you want the headers to be sticky.
I can't see how that block of code would disable the sticky headers. Where are you proposing using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kureev can you take a look too? |
Let's rename the prop and do what @Kureev suggested. Then we can merge. |
I think |
|
@matto1990 I think what @Kureev is suggesting is at https://github.com/matto1990/react-native/blob/a10602a83c5ea420db098985f329e22ca9326f7d/Libraries/CustomComponents/ListView/ListView.js#L419, instead of sectionHeaderIndices.push(totalIndex++); we can do if (this.props.stickySectionHeadersEnabled !== false) {
sectionHeaderIndices.push(totalIndex++);
} |
I've just updated the name of the flag. Sorry. I didn't see your reply @Kureev. the page had your first comment, but hadn't refreshed to show the subsequent ones 👍 I've made that change to conditionally add to the array on line 419, however, I have also renamed the array variable to |
LGTM. @Kureev ? |
@@ -229,6 +223,14 @@ var ListView = React.createClass({ | |||
*/ | |||
removeClippedSubviews: React.PropTypes.bool, | |||
/** | |||
* Makes the sections headers sticky. The sticky behavior means that it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two spaces after the dot :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the style that I saw in the comment above (https://github.com/facebook/react-native/pull/11700/files#diff-b4c8e4c7b175f06ffa084d8dca28e86aL185), but I can see now that the double spacing is not consistent.
Should I change just my misuse or all double spaces in this face?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matto1990 sure 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking through the files in Library/CustomCompnents
there are lots of instances of .<space><space>
. I don't think it's appropriate for this pull request to fix all of them. I will change the 10 instances in the ListView.js
property comments, but I'll leave the copyright header with the double spaces so it is the same as the other headers in this folder.
It's not a big deal, but I don't want to muddy up this PR with unrelated style changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@facebook-github-bot shipit |
@Kureev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
What's the next step of the process with getting this merged in? |
@matto1990 seems this failed to import. I'll import it again. Can you rebase it against master? I merged master, but it'll then porbably show my name in commit after merged. |
@satya164 I have rebased and removed the merge commit. |
@facebook-github-bot shipit |
@satya164 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Perfect. Thanks @satya164! |
Can you confirm this will make it into 0.41? I can't see it on the changelog for the beta release. |
@matto1990 it'll probably be in |
@satya164 Thanks! Is there a way to see the status of this? I assumed that once this had been closed it was merged in. |
@matto1990 yes it's merged. |
Hello,
This PR adds a property to the
ListView
to enable and disable to sticky sections headers behaviour. Current this is enabled by default and there is no way to disable it. It has been previously discussed in #1974 where there was a suggestion to add theListView
insideScrollView
. This is bad for performance, but some people were using that as a workaround. @satya164 suggested someone submitting a PR, which is why I'm here 😉I have tested the property manually by adding
stickySectionHeaders={false}
to the<ListView> Paging
example inUIExplorer
. I have also tested that the current behaviour still stands, so this is a non-breaking change.I have also checked that the website displays the new documentation.
I couldn't see anywhere to add automated tests to this, but if there is feel free to point it out and I'll update this PR.
I tried running
npm run lint
to check the code style, but it spat out loads and loads of errors. I presume I have something set up incorrectly. Feel free to let me know if there's anything I need to fix.Thanks,
Matt