question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[V2] Disable content touches when ViewPager is scrolling on iOS

See original GitHub issue

Bug

On Android when ViewPager is scrolling with swipe gesture all content(including all Touchables) are disabled. On iOS it’s not - all touchables are interactable while swiping so when viewpager content has button or other clickable components they are clicked.

I tried to fix it with setUserInteractioEnabled and with UIGestureRecognizer, but haven’t come up with any idea how to fix. Problem is to cancel all currently tapped touchables events when scroll begins.

Environment info

React native info output:

info
  React Native Environment Info:
    System:
      OS: macOS 10.15
      CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
      Memory: 1.36 GB / 16.00 GB
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 10.16.3 - /usr/local/bin/node
      Yarn: 1.19.0 - /usr/local/bin/yarn
      npm: 6.11.3 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
      Android SDK:
        API Levels: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 7, 8, 9
        Build Tools: 27.0.3, 28.0.2, 28.0.3, 29.0.2
        System Images: android-16 | Intel x86 Atom, android-18 | Google APIs Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-21 | Intel x86 Atom, android-22 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom, android-24 | Google Play Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Android TV Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.5 AI-191.8026.42.35.5900203
      Xcode: 11.0/11A420a - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.6 => 16.8.6
      react-native: 0.59.10 => 0.59.10
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7
      react-native-rename: 2.4.1

Library version: 2.0.1

Steps To Reproduce

Use ViewPager on iOS with any touchable components inside

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
ljsalm089commented, Dec 8, 2019

I add onMoveShouldSetResponderCapture method to ViewPager to prevent the touch event pass to the child view when viewpager is scrolling:


    onPageScroll(evt) {
        this.setState({pageScrolling: true});
    }

    onPageScrollStateChanged(evt) {
        if ('idle' == evt.nativeEvent.pageScrollState) {
            this.setState({pageScrolling: false});
        } else {
            this.setState({pageScrolling: true});
        }
    }

    moveShouldSetResponderCapture(evt) {
        return this.state.pageScrolling;
    }

    render() {
        return (
                <ViewPager style={styles.viewPager}
                    initialPage={0}
                    scrollEnabled={this.state.scrollEnabled}
                    onPageSelected={this.onPageSelected}
                    orientation="horizontal"
                    transitionStyle="scroll"
                    showPageIndicator={false}
                    animationsAreEnabled={animationsAreEnabled}
                    onPageScroll={(evt) => this.onPageScroll(evt)}
                    onPageScrollStateChanged={(evt) => this.onPageScrollStateChanged(evt)}
                    onMoveShouldSetResponderCapture={(evt) => this.moveShouldSetResponderCapture(evt)}
                    ref={this.viewPager}
                >
                    {pages.map(p => this.renderPage(p))}
                </ViewPager>
        )
    }
2reactions
troZeecommented, Dec 9, 2019

I have created PR for it. Thank you @ljsalm089 for providing above example. It helped me a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[V2] Disable content touches when ViewPager is scrolling on ...
On Android when ViewPager is scrolling with swipe gesture all content(including all Touchables) are disabled. On iOS it's not - all touchables ...
Read more >
How do disable paging by swiping with finger in ViewPager ...
Enable or disable user initiated scrolling. This includes touch input (scroll and fling gestures) and accessibility input. Disabling keyboard input is not yet ......
Read more >
Stop Swipe Action in Android Viewpager - Oodles Technologies
To create a viewpager without default swipe action . We have to stop the swipe actions. You can use following code to create...
Read more >
Prevent Touch Event Theft in Android | mobiarch
The View passed to the disableTouchTheft() method is the child (such as a viewPager) that doesn't want its parent to steal its touch...
Read more >
Animate a scroll gesture - Android Developers
Implement the stretch overscroll effect · When the stretch animation is in effect when the user touches the contents, register the touch as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found