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.

Best way to wrap carousel in a touchable?

See original GitHub issue

Is this a bug report, a feature request, or a question?

Question

I want my entire carousel to be touchable, while at the same letting users go through photos. I basically have a view with a carousel and a card in it, and I want that entire thing to be touchable.

so the code looks like

<TouchableOpacity>
  <View>
    <Carousel />
    <Card />
  </View>
</TouchableOpacity>

As soon as a touchable* is added, panning stops working on the carousel. If I swipe really fast the items are gone through, but otherwise the carousel is unresponsive.

Things I’ve tried:

  1. Setting onMoveShouldSetResponder={ () => false } on my TouchableOpacity
  2. Setting onMoveShouldSetResponder={() => true} on the carousel
  3. Setting onStartShouldSetResponder={() => true} on the carousel

Aside from completely ditching TouchableOpacity and setting up my own gesture detection using PanResponder, is there anything else I can do?

Thanks in advance for any help!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

3reactions
plus-commented, Apr 2, 2020

This is what I’ve found is working for me:

<Carousel
...
renderItem={({ item, index }: { item: any; index: number }) => {
          return (
            <TouchableWithoutFeedback onPress={onPress} disabled={!onPress}>
              <View onStartShouldSetResponder={() => true}>{renderItem(item, index)}</View>
            </TouchableWithoutFeedback>
          )
        }}

Basically you propagate the parent touchable onPress to the child and give it priority so it can be swiped as well

0reactions
dohooocommented, Oct 8, 2021

Sorry, please allow me to advertise for my open source library! ~ I think this library react-native-reanimated-carousel will solve your problem. It is a high performance and very simple component, complete with React-Native reanimated 2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best way to wrap carousel in a touchable? · Issue #423 - GitHub
I want my entire carousel to be touchable, while at the same letting users go through photos. I basically have a view with...
Read more >
Creating responsive, touch-friendly carousels with Flickity
Scrolling through a carousel is less satisfying and more awkward that simply scrolling down a page. Basically, you can't flick through them.
Read more >
Build a Touch Slider with HTML, CSS & JavaScript - YouTube
Build a full screen touch slider with HTML, CSS & JavaScriptFull Screen Touch ... How to OVER Engineer a Website // What is...
Read more >
Creating an Accessible Image Carousel
Our carousel is looking much better! We can scroll the container horizontally either with pointer events (mouse/touch) or by tabbing to the ...
Read more >
Carousel · Bootstrap v5.1
Disable touch swiping. Carousels support swiping left/right on touchscreen devices to move between slides. This can be disabled using the data-bs-touch ...
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