Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Add a prop to toggle ListView sticky section headers #11700

wants to merge 1 commit into from

Conversation

matt-oakes
Copy link
Contributor

@matt-oakes matt-oakes commented Jan 2, 2017

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 the ListView inside ScrollView. 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 in UIExplorer. 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

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @jaredly and @nihgwu to be potential reviewers.

@@ -472,9 +476,12 @@ var ListView = React.createClass({
if (props.removeClippedSubviews === undefined) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semi: Missing semicolon.

Copy link
Contributor Author

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

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 2, 2017
* is pushed off the screen by the next section header.
* @platform ios
*/
stickySectionHeaders: React.PropTypes.bool,
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

@Kureev Kureev Jan 2, 2017

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?

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kureev there is another implementation #11315 but still in working

@satya164
Copy link
Contributor

satya164 commented Jan 2, 2017

@Kureev can you take a look too?

@satya164
Copy link
Contributor

satya164 commented Jan 2, 2017

Let's rename the prop and do what @Kureev suggested. Then we can merge.

@nihgwu
Copy link
Contributor

nihgwu commented Jan 2, 2017

I think stickySectionHeaders is OK 😄

@Kureev
Copy link
Contributor

Kureev commented Jan 2, 2017

stickySectionHeaders doesn't sound like a flag. It sounds like array.

@satya164
Copy link
Contributor

satya164 commented Jan 2, 2017

@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++);
}

@matt-oakes
Copy link
Contributor Author

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 stickySectionHeaderIndices from sectionHeaderIndices to make it clear that it's not the index of all of the headers.

@satya164
Copy link
Contributor

satya164 commented Jan 2, 2017

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
Copy link
Contributor

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 :)

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matto1990 sure 👍

Copy link
Contributor Author

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.

Copy link
Contributor

@Kureev Kureev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Kureev
Copy link
Contributor

Kureev commented Jan 4, 2017

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

@Kureev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@matt-oakes
Copy link
Contributor Author

What's the next step of the process with getting this merged in?

@satya164
Copy link
Contributor

satya164 commented Jan 9, 2017

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

@matt-oakes
Copy link
Contributor Author

@satya164 I have rebased and removed the merge commit.

@satya164
Copy link
Contributor

satya164 commented Jan 9, 2017

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

@satya164 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@matt-oakes
Copy link
Contributor Author

Perfect. Thanks @satya164!

@matt-oakes
Copy link
Contributor Author

Can you confirm this will make it into 0.41? I can't see it on the changelog for the beta release.

@satya164
Copy link
Contributor

@matto1990 it'll probably be in 0.42

@matt-oakes
Copy link
Contributor Author

@satya164 Thanks! Is there a way to see the status of this? I assumed that once this had been closed it was merged in.

@satya164
Copy link
Contributor

@matto1990 yes it's merged.

@matt-oakes matt-oakes deleted the listview__sticky_headers_prop branch February 9, 2017 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants