tongyy / react-native-draggable

Draggable Item
MIT License
312 stars 89 forks source link

Issue with dragging when <Draggable> in <ScrollView> #117

Open Nuss93 opened 2 years ago

Nuss93 commented 2 years ago

The component works well when it's wrapped in a element.

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

rameshparajuli commented 2 years ago

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

muammadibal commented 2 years ago

any fix yet?

MohsinaliEMed commented 2 years ago

same here

allysonfield commented 2 years ago

same here

rajAmukhliS commented 2 years ago

@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>
stefandbd commented 1 year ago

This workaround works for iOS but not for Android unfortunately