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

tapping on iOS status bar should scroll inverted ScrollViews to their top #27574

Conversation

emilioicai
Copy link
Contributor

Summary

React Native ScrollViews are flipped upside down when the prop inverted is set to true. This is the root of a bug: tapping on the status bar in iOS should scroll the Flatlist up to the top but currently it does to the bottom.

The solution proposed is to detect natively if the ScrollView is inverted, on such case, prevent it from scrolling it to the beginning of the ScrollView (as a non-inverted ScrollView would do) and force a scroll to the end of it.

I've been careful enough not to force the scroll if the user explicitly selected not to do it or if it's happening in a nested ScrollView, as it is the default behaviour in iOS.

Fixes #21126

Changelog

[iOS] [Fixed] - Inverted ScrollViews scroll to their bottom when the status bar is pressed

Test Plan

  • on iOS, add a ScrollView and put enough content to overflow the screen size so it can be scrolled
  • add the prop inverted={true} to the ScrollView
  • go to the screen the Scrollview is in and press the status bar
  • it should scroll to top (previously it scrolled to the bottom)

v

@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 Dec 19, 2019
Copy link
Contributor

@hramos hramos left a comment

Choose a reason for hiding this comment

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

Approved, with some minor nits on code style.

@@ -829,6 +829,10 @@ - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
return NO;
}
}
if(self.inverted) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if(self.inverted) {
if (self.inverted) {

React/Views/ScrollView/RCTScrollView.m Show resolved Hide resolved
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.

@hramos 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 @emilioicai in 7a4753d.

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 Dec 19, 2019
alloy pushed a commit to alloy/react-native that referenced this pull request Apr 3, 2020
… top (facebook#27574)

Summary:
React Native ScrollViews are flipped upside down when the prop inverted is set to true. This is the root of a bug: tapping on the status bar in iOS should scroll the Flatlist up to the top but currently it does to the bottom.

The solution proposed is to detect natively if the ScrollView is inverted, on such case, prevent it from scrolling it to the beginning of the ScrollView (as a non-inverted ScrollView would do) and force a scroll to the end of it.

I've been careful enough not to force the scroll if the user explicitly selected not to do it or if it's happening in a nested ScrollView, as it is the default behaviour in iOS.

Fixes facebook#21126

## Changelog

[iOS] [Fixed] - Inverted ScrollViews scroll to their bottom when the status bar is pressed
Pull Request resolved: facebook#27574

Test Plan:
- on iOS, add a ScrollView and put enough content to overflow the screen size so it can be scrolled
- add the prop `inverted={true}` to the ScrollView
- go to the screen the Scrollview is in and press the status bar
- it should scroll to top (previously it scrolled to the bottom)

![v](https://user-images.githubusercontent.com/807710/71188640-a0ac6680-2281-11ea-91a7-d1e46aba8b14.gif)

Differential Revision: D19185270

Pulled By: hramos

fbshipit-source-id: 5445093ff38f4ba4082f1d883d8ed087e9565eaf
@hirbod
Copy link

hirbod commented Jun 25, 2020

@emilioicai sorry for commenting an "old" ticket, but Expo SDK just released with RN 0.62.2 and that fix is included there so its the first time I can test it. Your change works fine so far, the direction works, but only when I scroll "up" at least 1px. If my chat scroll position is "0" a tap on the statusbar won't do anything for me now. If I just scroll up a bit, scroll to top (or here: to bottom since its inverted) works.

@hirbod
Copy link

hirbod commented Jun 25, 2020

Here is a video (listen to audio please)
https://streamable.com/5pkkko

@PAJoeInc
Copy link

@hirbod were you ever able to find a solution to this issue? I am also experiencing the same thing in RN 0.63.2

@hirbod
Copy link

hirbod commented Aug 13, 2020

@PAJoeInc no - unfortunately not, since nobody responded to my message here.

@hirbod
Copy link

hirbod commented Aug 13, 2020

I think I will have to write a new ticket (which will prob. take a year or two before it gets resolved :D)

@jake-stewart
Copy link

very annoying. i want the old behaviour as how discord handles it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Component: ScrollView Merged This PR has been merged. Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inverted scrollsToTop scrolls to bottom
7 participants