garblovians / react-native-svg-pan-zoom

Pan-zoom via two-finger "Google Maps"-style pinch and drag gestures
MIT License
26 stars 23 forks source link

Have a feature to update zoom and center x, y coordinates through props. #5

Open adam-s opened 6 years ago

adam-s commented 6 years ago

There is an unused method public zoomToPoint = (x: number, y: number, scale: number, duration: number = 700). It would be nice to be able to pass an object that is updated from the parent component with the { x, y, zoom } so the element can be panned and zoomed automatically.

adam-s commented 6 years ago

Solved it. The zoomToPoint method is public and available through setting a ref on the parent.

  constructor(props) {
    super(props);

    this.svgPanZoom = null;
    this.setSvgPanZoom = (element) => {
      this.svgPanZoom = element;
    };
  }
  componentDidUpdate(prevProps) {
    const { bounds } = this.props;
    if (R.not(R.equals(prevProps.bounds, bounds))) {
      this.svgPanZoom.zoomToPoint(100, 100, 1.2);
      console.log('bound changed');
    }
  }