React native 如何在Android上使用react原生svg在屏幕上绘图?

React native 如何在Android上使用react原生svg在屏幕上绘图?,react-native,react-native-android,React Native,React Native Android,我希望圆圈在移动时留下痕迹,但到目前为止它没有。圆圈会四处移动,但svg不会呈现在屏幕上。我似乎找不出哪里出了问题 代码如下: export default class App extends Component { constructor(props){ super(props); this._panResponder={}; this._previousLeft = 0; this._previousTop = 0; this._circleSty

我希望圆圈在移动时留下痕迹,但到目前为止它没有。圆圈会四处移动,但svg不会呈现在屏幕上。我似乎找不出哪里出了问题

代码如下:

export default class App extends Component {
  constructor(props){
    super(props);
    this._panResponder={};
    this._previousLeft = 0;
    this._previousTop = 0;
    this._circleStyles = {};
    this.circle = null;
    this.state={
      coordinates: []      
    }
}
  draw(x,y){
     this.state.coordinates.push([x,y]);
     var moves = "V" + this._previousLeft + " " + x + " H" + this._previousTop + " " + y;
    console.log(moves)
    return(
      <Svg height={200} width={200}>
        <Path 
        d = {moves}
        fill = "blue"
        stroke ="red"
        strokeWidth={2}
        />
      </Svg>
    )
  }

  componentWillMount(){
    this._panResponder = PanResponder.create({
      onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder,
      onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,
      onPanResponderGrant: this._handlePanResponderGrant,
      onPanResponderMove: this._handlePanResponderMove,
      onPanResponderRelease: this._handlePanResponderEnd,
      onPanResponderTerminate: this._handlePanResponderEnd,
    });
    this._previousLeft = 20;
    this._previousTop = 84;
    this._circleStyles = {
      style: {
        left: this._previousLeft,
        top: this._previousTop,
        backgroundColor: 'green',
      }
    };
  }
  componentDidMount() {
    this._updateNativeStyles();
  }
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.circle}
          ref={(circle) => {
            this.circle = circle;
          }}
          { ...this._panResponder.panHandlers }
        />
      </View>
    );
  }

  _highlight = () => {
    this._circleStyles.style.backgroundColor = 'blue';
    this._updateNativeStyles();
  }

  _unHighlight = () => {
    this._circleStyles.style.backgroundColor = 'green';
    this._updateNativeStyles();
  }

  _updateNativeStyles() {
    this.circle && this.circle.setNativeProps(this._circleStyles);
  }

  _handleStartShouldSetPanResponder() {
    return true;
  }

  _handleMoveShouldSetPanResponder() {
    return true;
  }

  _handlePanResponderGrant = () => {
    this._highlight();
  }

    _handlePanResponderMove = (e, gestureState) => {
    this._circleStyles.style.left = this._previousLeft + gestureState.dx;
    this._circleStyles.style.top = this._previousTop + gestureState.dy;
    this.draw(this._circleStyles.style.left, this._circleStyles.style.top)     
    this._updateNativeStyles();
   }

  _handlePanResponderEnd = (e, gestureState) => {
    this._unHighlight();       
    this._previousLeft += gestureState.dx;
    this._previousTop += gestureState.dy;
    }
}
const styles = StyleSheet.create({
  circle: {
    width: CIRCLE_SIZE,
    height: CIRCLE_SIZE,
    borderRadius: CIRCLE_SIZE / 2,
    position: 'absolute',
    left: 0,
    top: 0,
  },
  container: {
    flex: 1,
    paddingTop: 64,
  },
});
导出默认类应用程序扩展组件{
建造师(道具){
超级(道具);
这个._panResponder={};
这个。_previousLeft=0;
这是.\u previousTop=0;
这个。_circleStyles={};
this.circle=null;
这个州={
坐标:[]
}
}
绘制(x,y){
这个.state.coordinates.push([x,y]);
var moves=“V”+此._previousLeft+“”+x+“H”+此._previousTop+“”+y;
console.log(移动)
返回(
)
}
组件willmount(){
这是.\u panResponder=panResponder.create({
onStartShouldSetPanResponder:这个。\你的手应该是SetPanResponder,
onMoveShouldSetPanResponder:此.\u handleMoveShouldSetPanResponder,
onPanResponderGrant:这个,
onPanResponderMove:这个。_handlePanResponderMove,
onPanResponderRelease:这个。\u handlePanResponderRend,
onPanResponderTerminate:这个。\u handlePanResponderRend,
});
这个。_先前左=20;
这个._previousTop=84;
这._circleStyles={
风格:{
左:这个,
上图:这个,
背景颜色:“绿色”,
}
};
}
componentDidMount(){
这是。_updatenavivestyles();
}
render(){
返回(
{
这个圆=圆;
}}
{…这个。_panResponder.panHandlers}
/>
);
}
_突出显示=()=>{
这个._circleStyles.style.backgroundColor='蓝色';
这是。_updatenavivestyles();
}
_不高亮度=()=>{
这个._circleStyles.style.backgroundColor='绿色';
这是。_updatenavivestyles();
}
_updateNativeStyles(){
this.circle&&this.circle.setNativeProps(this.\u circleStyles);
}
_handleStartShouldSetPanResponder(){
返回true;
}
_handleMoveShouldSetPanResponder(){
返回true;
}
_handlePanResponderGrant=()=>{
这个;
}
_handlePanResponderMove=(e,手势状态)=>{
this.\u circleStyles.style.left=this.\u previousLeft+gestureState.dx;
this.\u circleStyles.style.top=this.\u previousTop+gestureState.dy;
this.draw(this.\u circleStyles.style.left,this.\u circleStyles.style.top)
这是。_updatenavivestyles();
}
_HandlePanResponseRend=(e,手势状态)=>{
这个。_unHighlight();
这._previousLeft+=gestureState.dx;
这._previousTop+=gestureState.dy;
}
}
const styles=StyleSheet.create({
圆圈:{
宽度:圆圈大小,
高度:圆形尺寸,
边界半径:圆圈大小/2,
位置:'绝对',
左:0,,
排名:0,
},
容器:{
弹性:1,
paddingTop:64,
},
});