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

[0.57][iOS][Android] ScrollView pagingEnabled doesn't work for iOS or Android #21302

Closed
fierysolid opened this issue Sep 24, 2018 · 11 comments
Closed
Labels
Bug Platform: Android Android applications. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@fierysolid
Copy link

fierysolid commented Sep 24, 2018

Environment

React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 48.02 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.9.0 - ~/.nvm/versions/node/v10.9.0/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.9.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
Android SDK:
Build Tools: 23.0.1, 23.0.2, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 27.0.2, 27.0.3, 28.0.0
API Levels: 22, 23, 24, 25, 26, 27
IDEs:
Android Studio: 3.1 AI-173.4819257
Xcode: 10.0/10A255 - /usr/bin/xcodebuild
npmPackages:
react: 16.5.2 => 16.5.2
react-native: 0.57.1 => 0.57.1
npmGlobalPackages:
react-native-cli: 2.0.1

Description

There is a commit e0170a9 in master that is supposed to fix this, but it doesn't work. This issue happens when using snapToInterval instead of pagingEnabled on iOS and 100% of the time on Android whether you use pagingEnabled or snapToInterval.

before:
This code used to only allow them to scroll one item (each item is screen width) at a time. Here is what it looked like:

ezgif com-video-to-gif

after:
Since upgrading to 0.57.1 it allows the user to completely scroll past the items in the middle. You can see it in the following:
ezgif com-video-to-gif

Reproducible Demo

Can't use 0.57.1 in expo, but here is the code I'm using:

<ScrollView
  horizontal
  pagingEnabled
  snapToInterval={SCREEN_WIDTH}
  showsHorizontalScrollIndicator={false}
  contentContainerStyle={{ width: SCREEN_WIDTH }}
>
    <View style={{width: SCREEN_WIDTH }}>
        <Text style={swiperTitleTextStyle}>{trend.title}</Text>
        <Text style={swiperTextStyle}>{trend.description}</Text>
    </View>
    <View style={{width: SCREEN_WIDTH }}>
        <Text style={swiperTitleTextStyle}>{trend.title}</Text>
        <Text style={swiperTextStyle}>{trend.description}</Text>
    </View>
    <View style={{width: SCREEN_WIDTH }}>
        <Text style={swiperTitleTextStyle}>{trend.title}</Text>
        <Text style={swiperTextStyle}>{trend.description}</Text>
    </View>
</ScrollView>
@fierysolid fierysolid changed the title ScrollView pagingEnabled skips ov ScrollView pagingEnabled doesn't work for iOS or Android Sep 24, 2018
@fierysolid fierysolid changed the title ScrollView pagingEnabled doesn't work for iOS or Android [0.57][iOS][Android] ScrollView pagingEnabled doesn't work for iOS or Android Sep 24, 2018
@react-native-bot react-native-bot added Platform: iOS iOS applications. Platform: Android Android applications. 🔶Components labels Sep 24, 2018
@fierysolid fierysolid changed the title [0.57][iOS][Android] ScrollView pagingEnabled doesn't work for iOS or Android [0.57][Android] ScrollView pagingEnabled doesn't work for iOS or Android Sep 24, 2018
@fierysolid fierysolid changed the title [0.57][Android] ScrollView pagingEnabled doesn't work for iOS or Android [0.57][iOS][Android] ScrollView pagingEnabled doesn't work for iOS or Android Sep 24, 2018
@mjmasn
Copy link
Contributor

mjmasn commented Sep 26, 2018

@fierysolid that commit isn't in 0.57.1 (although I've requested it for 0.57.2 if they end up doing another minor release). Are you saying you've built RN from source and it's still not working? It's an important one for us too so I'm really hoping it does work...

@fierysolid
Copy link
Author

@mjmasn I manually added that code to the files in my node_modules, cleaned and rebuilt and it maybe slightly snapped into place better, but you can still scroll all the way to the end. It doesn't paginate like it should.

@fierysolid
Copy link
Author

Also, I tried building from master and it fails to even build

@mjmasn
Copy link
Contributor

mjmasn commented Sep 26, 2018

@fierysolid ah ok, I think that's expected... I don't think modifying the code in node_modules does anything unless you set up the build properly. Pre-compiled libraries are used by default.

@fierysolid
Copy link
Author

I've changed iOS files directly in the past with a TextInput fix that took months to get into a release and it worked great.

@gusgard
Copy link
Contributor

gusgard commented Oct 7, 2018

@fierysolid Fixed in version 0.57.2 👍

@soumyamishra89
Copy link

When the paging is enabled and the item width is equal to width of scrollview, the issue does not exist.
But when the width of the item is less than scrollview width and we use snapToInterval, then the scrollview does a smooth scroll. This issue did not exist in RN 0.56. The issue was worse in 0.57 where even full width item had a smooth scroll. But with the fix in 0.57.2 the full width items worked properly but not with items smaller in width than the scrollview.

@sunho
Copy link

sunho commented Oct 28, 2018

Seems like the fix doesn't work on IOS.

@Taylor123
Copy link
Contributor

Running into the same issue. Even with the following ScrollView props it will over scroll the next or previous item in the list.

decelerationRate={0}
snapToInterval={customItemWidth}
snapToAlignment="start"

Is there any plan to allow pagingEnabled with a custom snap interval? Or would that be a welcomed PR from the community?

@Taylor123
Copy link
Contributor

Taylor123 commented Mar 19, 2019

Made a custom release for my current needs: https://github.com/Taylor123/react-native/tree/release/v0.57.7-disable-interval-momentum

This doesn't force a single page, but disables the predictive scrolling behavior when using snapToInterval and disableIntervalMomentum={true}. So when scrolling, it'll snap to whatever the closest interval is to the last scroll offset rather than flinging past it based on velocity. If i find more time, I will work on a release that enforces the single page

facebook-github-bot pushed a commit that referenced this issue Apr 15, 2019
Summary:
Would like feedback from the community as this may not be the best solution for all

I would like to restrict (or paginate) the fling of a horizontal ScrollView when `snapToInterval` is set. This is not currently possible with `pagingEnabled`, since the pagination works only when items are the entire width of the ScrollView.

This implementation simply restricts the predicted `targetOffset` found from the `x` velocity and replaces it with the offset when the pan gesture ended.

To get pagination working, I may paginate based on the interval by calculating the offset delta from the beginning of the gesture to current offset and restricting the scrolling behavior to the `snapToInterval`. If this is preferred, I can update this PR or make a new one, but wanted to start a discussion since it seems like there are many in the community that would like this feature  #21302 .

[General] [Added] - add prop `disableIntervalMomentum` to disable the predictive scrolling behavior of horizontal ScrollViews
Pull Request resolved: #24045

Differential Revision: D14939754

Pulled By: sahrens

fbshipit-source-id: 26be19c47dfb8eed4d7e6035df53a77451e23081
@stale
Copy link

stale bot commented Aug 2, 2019

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.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 2, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Aug 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Android Android applications. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

8 participants