Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Nuss93 opened this issue Oct 12, 2021 · 6 comments
Open

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

Nuss93 opened this issue Oct 12, 2021 · 6 comments

Comments

@Nuss93
Copy link

Nuss93 commented Oct 12, 2021

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
Copy link

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

@muammadibal
Copy link

any fix yet?

@MohsinaliEMed
Copy link

same here

1 similar comment
@allysonfield
Copy link

same here

@rajAmukhliS
Copy link

rajAmukhliS commented Sep 19, 2022

@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
Copy link

This workaround works for iOS but not for Android unfortunately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants