react-native-swiper icon indicating copy to clipboard operation
react-native-swiper copied to clipboard

ScrollView inside Swiper not works

Open 1fabiopereira opened this issue 4 years ago • 13 comments

Which OS ?

Android

Version

Which versions are you using:

  • react-native-swiper: ^1.6.0-nightly.5
  • react-native: 0.61.5

Expected behaviour

Have horizontal scroll on ScrollView inside slide on Android and IOS

Actual behaviour

Horizontal scroll on ScrollView inside slide works only on IOS

I need put a chart inside of the slide and this chart have a horizontal scroll, this work perfectly on IOS, but on Android isn't works. The chart are inside a ScrollView, but Scrollview not work 'cause swipe event is consume by Swiper, any ideia how can fix that?

1fabiopereira avatar Apr 01 '20 14:04 1fabiopereira

same issue

jmy10241024 avatar May 08 '20 10:05 jmy10241024

This bug is related to nested Horizontal ScrollView in React Native, since React Native Swiper is using ScrollView and you are nesting another ScrollView, there is no fix until now, even if you use the new prop nestedScrollEnabled it will not work, there is an easy workaround, just use import { ScrollView } from 'react-native-gesture-handler' instead of import { ScrollView } from 'react-native'

myhamdaoui avatar May 09 '20 16:05 myhamdaoui

@myhamdaoui Swipe is working but after 2-3 attempts it scrolls to next slide, any luck to resolve this

Prashantrao331 avatar May 10 '20 21:05 Prashantrao331

@Prashantrao331 did you tried my solution ? because it should work perfectly

myhamdaoui avatar May 11 '20 03:05 myhamdaoui

@myhamdaoui Yes its working but have to swipe twice to move to next slide

Prashantrao331 avatar May 11 '20 12:05 Prashantrao331

I fixed this using a workaround, I disabled the scroll scrollEnabled={false} and added a wrapper on slide, I created a function that detect gestures over wrapper and I change programmatically the slide index to left or right.

const [index, setIndex] = useState(() => 0);
function Slides(data): Node {
  return data.map(slide => {
   return (
      <GestureRecognizer onSwipe={(e) => OnSwipe(e, length)}>
        <Slide data={slide}/>
      </GestureRecognizer>
     )
  })
}
function OnSwipe(gestureName, size): void {
    const {SWIPE_LEFT, SWIPE_RIGHT} = swipeDirections;
    
     switch (gestureName) {
      case SWIPE_LEFT: {
        if (index < size && swiper) {
          swiper.current.scrollBy(1, true);
          const position = index + 1;
          setIndex(position);
        }
        break;
      }

      case SWIPE_RIGHT: {
        if (index > 0 && swiper) {
          swiper.current.scrollBy(-1, true);
          const position = index - 1;
          setIndex(position);
        }
        break;
      }
    }
  }
<Swiper
  ref={swiper}
  index={index}
  scrollEnabled={false}
  loop={false}
  dotStyle={Styles.Dot}
  activeDotStyle={Styles.ActiveDot}
  dotColor={Colors.Mercury}
  activeDotColor={Colors.Mercury}>
  {Slides(items)}
 </Swiper>

1fabiopereira avatar May 18 '20 20:05 1fabiopereira

@myhamdaoui it is good

tudiantuan avatar Sep 18 '20 02:09 tudiantuan

@myhamdaoui unfortunately this solution did not work, did you try anything else?

RicardoBrito1938 avatar Jan 07 '21 18:01 RicardoBrito1938

GestureRecognizer

Fabio, what is this GestureRecognizer component?

RicardoBrito1938 avatar Jan 07 '21 19:01 RicardoBrito1938

@RicardoBrito1938 is this react-native-swipe-gestures

1fabiopereira avatar Jan 07 '21 19:01 1fabiopereira

I tried to use scrollview vertically inside swiper but it didn't work. Property nestedScrollEnabled of ScrollView solved my issue.

<Swiper showsButtons={false}>
    <ScrollView nestedScrollEnabled={true}>
         <Text>Meat</Text>
    </ScrollView>  
</Swiper>

mrtkprc avatar Feb 28 '21 07:02 mrtkprc

Yup nestedScrollEnabled enabled worked for me thanks :)

jamesmcn1 avatar Mar 11 '21 16:03 jamesmcn1

@myhamdaoui thanks! It worked :)

losheredos avatar Jan 04 '24 00:01 losheredos