question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android: Svg elements are inside of a PanResponder don't update event.nativeEvent.location

See original GitHub issue

This may be related to https://github.com/react-native-community/react-native-svg/issues/363, but I wasn’t sure so I’ll file a separate issue.

When Svg elements are inside of a PanResponder, onPanResponderMove’s event.nativeEvent.locationX (and Y) do not change for Android, but do for iOS. Demo:

import React from 'react';
import { StyleSheet, Text, View, PanResponder } from 'react-native';
import Svg, { Rect } from "react-native-svg";

class Container extends React.Component {
  constructor(props) {
    super(props);
    this.panResponder = this.getResponder();
  }

  getResponder() {
    const yes = () => true;
    const no = () => false;
    return PanResponder.create({
      onStartShouldSetPanResponder: yes,

      onStartShouldSetPanResponderCapture: no,

      onMoveShouldSetPanResponder: yes,

      onMoveShouldSetPanResponderCapture: yes,

      onShouldBlockNativeResponder: yes,

      onPanResponderTerminationRequest: yes,
      // Active touch or touches have moved
      onPanResponderMove: this.props.onPanResponderMove.bind(this),
      onPanResponderGrant: this.props.onPanResponderMove.bind(this),
    });
  }

  render() {
    return (
      <View {...this.panResponder.panHandlers}>
        {this.props.children}
      </View>
    );
  }
};

export default class App extends React.Component {
  render() {
    return (
      <View>
        <Container
          onPanResponderMove={
            (event) => {
              console.log(
                event.nativeEvent.locationX,
                event.nativeEvent.locationY
              );
            }
          }
        >
          <Svg
            height="100"
            width="100"
          >
            <Rect
              width={100}
              height={100}
              fill="blue"
            />
          </Svg>
        </Container>
      </View>
    );
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:10

github_iconTop GitHub Comments

1reaction
macrozonecommented, Sep 2, 2017

I have a similar issue. I have a panresponder on a View which contains an SVG.

in onMoveShouldSetPanResponderCapture, dx and dy start with a big value even on the first press. I think this is because mutlipe elements inside the svg report different locations. Also movement speeds (vx, vy) get messed up because of this. I tried to work around it, but without any success.

0reactions
aditya1711commented, Apr 13, 2020

Can you make a repro?

This is a repr code.

import React from 'react';
import {
  StyleSheet,
  View,
} from 'react-native';

import {
  VictoryLine,
  VictoryChart,
  VictoryZoomContainer,
} from 'victory-native';

const App: () => React$Node = () => {
  return (
    <View style={styles.container}>
      <VictoryChart
        containerComponent={
          <VictoryZoomContainer
            zoomDimension="x"
            // minimumZoom={{x: 1, y: 0.01}}
          />
        }>
        <VictoryLine
          data={data1.frst}
          style={{data: {stroke: 'red'}}}
          interpolation="natural"
        />
      </VictoryChart>
    </View>
  );
};

const data1 = {
  frst: [
    {x: 'Mon', y: 6},
    {x: 'Tue', y: 2},
    {x: 'Wed', y: 3},
    {x: 'Thu', y: 2},
    {x: 'Fri', y: 5},
    {x: 'Sat', y: 1},
    {x: 'Sun', y: 6},
    {x: 'Mon2', y: 6},
    {x: 'Tue2', y: 2},
    {x: 'Wed2', y: 3},
    {x: 'Thu2', y: 2},
    {x: 'Fri2', y: 5},
    {x: 'Sat2', y: 1},
    {x: 'Sun2', y: 6},
    {x: 'Mon3', y: 6},
    {x: 'Tue3', y: 2},
    {x: 'Wed3', y: 3},
    {x: 'Thu3', y: 2},
    {x: 'Fri3', y: 5},
    {x: 'Sat3', y: 1},
    {x: 'Sun3', y: 6},
  ],
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    // padding: 10,
    justifyContent: 'center',
  }
});

export default App;

Were you able to reproduce the issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android: Svg elements are inside of a PanResponder don't ...
When Svg elements are inside of a PanResponder, onPanResponderMove 's event.nativeEvent.locationX (and Y) do not change for Android, ...
Read more >
Update state from inside a PanResponder - Stack Overflow
I have a < Svg > element with a < Circle > in it. The < Circle >'s position is relative to a...
Read more >
[Solved]-Limit PanResponder movements React Native-React ...
Coding example for the question Limit PanResponder movements React Native-React ... ( <View style={styles.holder} onLayout={event => { const layout = event.
Read more >
PanResponder - React Native
A native event is a synthetic touch event with form of PressEvent. A gestureState object has the following:
Read more >
What Sets Apart ReactJS with React Native - Flyoutsourcing
In-app rendering, React Native never employs HTML. However, it has optional elements that have a similar approach. Using the React-Native components, they can ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found