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

[Android] Implement fading edges for ScrollView and it's dependent FlatList #26163

Conversation

andre-krueger
Copy link

Summary

This should add props for enabling horizontal and vertical fading
edges for Scrollview and FlatList.
These fading edges are used to communicate to the user that there is more content to see.

Changelog

[Android] [Added] - fading edges props to the FlatList and ScrollView components

Test Plan

Open the React Native test app and navigate to the FlatList section.
Enable the useFadingEdges switch and insert a number into Fading edge length.

device-2019-08-23-123745
device-2019-08-23-123844

@react-native-bot react-native-bot added Platform: Android Android applications. Type: Enhancement A new feature or enhancement of an existing feature. labels Aug 23, 2019
@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

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

Code analysis results:

  • eslint found some issues. Run yarn lint --fix to automatically fix problems.

@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 Aug 23, 2019
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@andre-krueger andre-krueger force-pushed the implement-scrollview-fading-edges branch from 1979c1f to f1213a1 Compare August 23, 2019 11:00
@andre-krueger andre-krueger changed the title [Android] Implement fading edges for Scrollview and it's dependent FlatList [Android] Implement fading edges for ScrollView and it's dependent FlatList Aug 23, 2019
@andre-krueger andre-krueger force-pushed the implement-scrollview-fading-edges branch from f1213a1 to 3bae7cc Compare August 23, 2019 11:03
@sahrens
Copy link
Contributor

sahrens commented Aug 23, 2019

Oh man that options list is getting pretty large...can you make it slightly larger by adding "android-only" to this new option so people don't get confused on iOS and this it's a bug when nothing happens? Also, could you or someone you work with implement support for iOS as well? It would be awesome to have platform parity on as many features as possible. This is a bit old, but is probably still relevant: https://www.cocoanetics.com/2011/08/adding-fading-gradients-to-uitableview/

Copy link
Contributor

@sahrens sahrens left a comment

Choose a reason for hiding this comment

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

nevermind, your OS === android check is probably fine.

@@ -124,11 +135,29 @@ class FlatListExample extends React.PureComponent<Props, State> {
{renderSmallSwitchOption(this, 'empty')}
{renderSmallSwitchOption(this, 'debug')}
{renderSmallSwitchOption(this, 'useFlatListItemComponent')}
{Platform.OS === 'android' && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see you added an android check - that's fine.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@sahrens is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by André Krüger in f8a64f9.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Aug 23, 2019
@elicwhite
Copy link
Member

Is there a need to have a distinction between horizontalFadingEdgesEnabled and verticalFadingEdgesEnabled? Could we just have fadingEdgesEnabled that fades the edges depending on which direction the scrollview is? And if we do that we only need fadingEdgeLength, since that defaults to 0 which is off that handles the option being enabled or disabled too.

That would make this go from needing three props, to only one. :)

@sahrens
Copy link
Contributor

sahrens commented Aug 23, 2019

I agree, let's only have a single edge length prop. I'm reverting now.

facebook-github-bot pushed a commit that referenced this pull request Aug 24, 2019
…ollView and it's dependent FlatList"

Summary:
After some thought, we decided we don't need the flexibility of
separate horizontal and vertical props - it would be much nicer
to just have a single prop for the edge length and then the native
code can enable the booleans as appropriate.

Original PR: #26163

Original commit changeset: f72a9a890d90

Reviewed By: TheSavior

Differential Revision: D16997468

fbshipit-source-id: 7973262287a7ec2cee5957f8dc1806a0f28c1432
@elicwhite elicwhite reopened this Aug 24, 2019
@andre-krueger andre-krueger force-pushed the implement-scrollview-fading-edges branch from 3bae7cc to 51acd31 Compare August 24, 2019 13:44
@andre-krueger
Copy link
Author

I did combine the props to a single one, but unfortunately, I don't feel too confident to also implement the feature for iOS (I might be able to do that in a follow-up, though).

*
* @platform android
*/
fadingEdgesEnabled?: ?boolean,
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this Boolean? Or can we just check whether the length is 0 for disabled, non zero for enabled?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, you're right. Fixed.

@andre-krueger andre-krueger force-pushed the implement-scrollview-fading-edges branch from 51acd31 to 841b6df Compare August 24, 2019 16:47
Copy link
Member

@elicwhite elicwhite left a comment

Choose a reason for hiding this comment

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

Thanks for the update, this is really close! Two more small nits.

@@ -51,6 +58,8 @@ type State = {|
virtualized: boolean,
empty: boolean,
useFlatListItemComponent: boolean,
useFadingEdges: boolean,
Copy link
Member

Choose a reason for hiding this comment

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

This isn’t needed here anymore, right?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, fixed.

@@ -335,6 +335,13 @@ type AndroidProps = $ReadOnly<{|
* @platform android
*/
persistentScrollbar?: ?boolean,
/**
* The amount of fading.
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a bit more description here? Assume that what you put here will be the sentence describing what this prop does in our websites api documentation.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I added more description.

@andre-krueger andre-krueger force-pushed the implement-scrollview-fading-edges branch from 841b6df to de33eb8 Compare August 25, 2019 16:38
Copy link
Member

@elicwhite elicwhite left a comment

Choose a reason for hiding this comment

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

Looks good! Approved for someone to land on Monday

if (value > 0) {
view.setHorizontalFadingEdgeEnabled(true);
view.setFadingEdgeLength(value);
}
Copy link
Member

@elicwhite elicwhite Aug 27, 2019

Choose a reason for hiding this comment

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

Ah, just checking this one last time made me realize that if the prop is set to 0 it should become disabled again.

I think this needs the following, right?

else {
  view.setHorizontalFadingEdgeEnabled(false);
}

In both files

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, you're right, this might apply to dev environments where the prop is changed quite often. Maybe the fading edge length should also be reset?

@elicwhite
Copy link
Member

Found one more thing that stood out to me. Sorry for the churn and the back and forth! We'll get this in!

@andre-krueger andre-krueger force-pushed the implement-scrollview-fading-edges branch from de33eb8 to df6bb8a Compare August 27, 2019 07:11
@sahrens
Copy link
Contributor

sahrens commented Aug 27, 2019

Did you verify that toggling the fade switch in the example correctly shows and hides the fade?

This should add props for enabling horizontal and vertical fading
edges for Scrollview and FlatList.
These fading edges are used to communicate to the user that there is more content to see.
@andre-krueger andre-krueger force-pushed the implement-scrollview-fading-edges branch from df6bb8a to b86efed Compare August 27, 2019 15:59
@andre-krueger
Copy link
Author

Yes, it works correctly. I'm now also resetting the fading edge length to zero if the fading edges are disabled, just in case.

@sahrens
Copy link
Contributor

sahrens commented Aug 27, 2019

Ok great.

@elicwhite
Copy link
Member

We are having some trouble landing this PR due to some internal tooling issues around having previously reverting this. I reached out to our Open Source team for support.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@TheSavior is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

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. Component: FlatList Component: ScrollView Merged This PR has been merged. Platform: Android Android applications. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants