msand / zoomable-svg

Pinch to pan-n-zoom react-native-svg components using a render prop.
38 stars 14 forks source link

Any way to pass properties to SVGROOT? #10

Open MozilaIP opened 5 years ago

MozilaIP commented 5 years ago

Hi, In my app I need to pass some variable data to be drawn.

Example:

<Ellipse cy={this.state.y} cx={this.state.x} />

But I am unable to do this since svgRoot does not inherit properties from parent component. Moreover, I want svgRoot to execute render on state change, but, as written above, I can't pass any state to it, hence this component is not reactive.

Is there any workaround for my issue?

msand commented 5 years ago

Check how the onToggle handler is passed in the readme example:

In App component

  childProps = { onToggle: this.onToggle };

In App render / ZoomableSvg element props

          childProps={this.childProps}

In SvgRoot onPress event handler:

    const { onToggle } = this.props;
    if (onToggle) {
      onToggle();
    }