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

Cannot drag when child component has onPress - ReactNativeZoomableView #101

Open
aaydin29 opened this issue May 7, 2024 · 5 comments
Open

Comments

@aaydin29
Copy link

aaydin29 commented May 7, 2024

Hello, as seen in the code I shared below, there is an onPress in the Path in ReactNativeZoomableView. The dragging function works successfully from areas not covered by this path, but if I try to do this on the Path, the dragging does not work. I have no other way than having the two work together for the project I'm developing.

<ReactNativeZoomableView
  ref={zoomableViewRef}
  maxZoom={maxZoom}
  minZoom={minZoom}
  zoomStep={0.5}
  initialZoom={1}
  bindToBorders={false}
  contentWidth={2000}
  contentHeight={857}
>
  <Svg width={2000} height={857}>
    {data.map((item, index) => (
      <Path
        key={index}
        d={item.path}
        fill={'#fff'}
        stroke="black"
        strokeWidth={0.75}
        onPress={() => {
          console.log(`${item.name} clicked!`);
        }}
      />
    ))}
  </Svg>
</ReactNativeZoomableView>
@aaydin29 aaydin29 changed the title Cannot drag when child component has onPress Cannot drag when child component has onPress - ReactNativeZoomableView May 7, 2024
@bumjin1013
Copy link

did you solve it?

@CozeaRaluca
Copy link

Any updates on this? 😄

@DanielKuhn
Copy link

I also have this problem. The solution seems to be related to the onStartShouldSetPanResponderCapture prop (discussion: #91 , PR: #93), but I don't understand how to use it. Can anyone explain?

@bumjin1013
Copy link

bumjin1013 commented Nov 14, 2024

@DanielKuhn
@CozeaRaluca

import React, {useState} from "react";
import {StyleSheet, View} from "react-native";
import {gestureHandlerRootHOC} from "react-native-gesture-handler";
import {ReactNativeZoomableView} from "@openspacelabs/react-native-zoomable-view";

function ZoomView({children, size}) {
  return (
    <View style={styles.container}>
      <ReactNativeZoomableView
        maxZoom={2.0}
        minZoom={0.3}
        zoomStep={0.5}
        initialZoom={0.6}
        bindToBorders={true}
        onMoveShouldSetPanResponderCapture={(evt, gestureState) => Math.abs(gestureState.dx) > 3 || Math.abs(gestureState.dy) > 3} //add this
        contentWidth={size.width + 100}
        contentHeight={size.height + 200}>
        <View style={styles.content}>{children}</View>
      </ReactNativeZoomableView>
    </View>
  );
}

export default gestureHandlerRootHOC(ZoomView);

const styles = StyleSheet.create({
  container: {
    overflow: "hidden",
    width: "100%",
    height: "100%",
  },
  content: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
  },
  contentWindow: {
    alignSelf: "flex-start",
  },
});

@DanielKuhn
Copy link

Awesome, thanks @bumjin1013 !

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

4 participants