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

Issue with dragging when <Draggable> in <ScrollView>

Open Nuss93 opened this issue 3 years ago • 6 comments

The <Draggable> component works well when it's wrapped in a <View> element.

But when I insert it in a <ScrollView> element, the page scrolls, but my draggable component does not drag. Is there a way to use draggable within ScrollView?

Nuss93 avatar Oct 12 '21 10:10 Nuss93

same here: I used <Draggable> inside package react-native-zoomable-view <ReactNativeZoomableView> and it doesn't allow to move.

rameshparajuli avatar Oct 26 '21 12:10 rameshparajuli

any fix yet?

muammadibal avatar Apr 26 '22 04:04 muammadibal

same here

MohsinaliEMed avatar Aug 16 '22 11:08 MohsinaliEMed

same here

allysonfield avatar Aug 17 '22 15:08 allysonfield

@MohsinaliEMed @allysonfield @muammadibal @Nuss93 @rameshparajuli

I have fixed it

This is because of gesture conflict of ScrollView and Draggable. And due to that conflict, ScrollView is responding to your clicks and gestures because ScrollView is parent and its gesture is dominant on gesture of Draggable. To make Draggable dominant You have to disable ScrollView when you attract with Draggable

If u want to fix it please follow the steps below

first of all I have created a state named as scroll and initially it is true

const [scroll, setScroll] = useState(true);

use this state to enable and disable scroll view as I did

<ScrollView
        ref={scrollRef}
        scrollEnabled={scroll}  //when scroll false scroll view gesture will be disable and vice versa 
        showsHorizontalScrollIndicator={false}
        showsVerticalScrollIndicator={false}>
....
</ScrollView>

now change value of scroll to achieve drag and scrolling together

const {width, height} = Dimensions.get('screen'); // height width from screen dimensions

<Draggable
            x={width - 70}
            y={height - 210}
            minX={5}
            minY={20}
            maxX={width - 5}
            maxY={height - 150}
            isCircle={true}
            renderColor={'red'}
            renderSize={63}
            onLongPress={() => {
              Vibration.vibrate(); // Vibration from react-native, i.e vibrate to make it easy to understand for user
              setScroll(false); // important step to disable scroll when long press this button
            }}
            onRelease={() => {
              setScroll(true); // important step to enable scroll when release or stop drag
            }}
            children={<View>
// children according to your requirements
</View>  }>
          </Draggable>

rajAmukhliS avatar Sep 19 '22 11:09 rajAmukhliS

This workaround works for iOS but not for Android unfortunately

stefandbd avatar Jul 03 '23 08:07 stefandbd