无法添加没有YogaNode的孩子-SVG和动画

时间:2018-12-23 09:24:30

标签: javascript react-native

我想用svg处理一个Animated组件。但我收到此错误消息:

  

如果没有父节点,则无法将没有YogaNode的子节点添加到父节点   测量功能! (尝试将RNSVGCircle添加到RCTView)。

这是我的代码:

import { PanResponder, View, Dimensions, TouchableOpacity,Animated } from 'react-native'
import Svg, { Path, Circle, G, Text, Image } from 'react-native-svg'

        <Animated.View
          style={{transform: [{translateX: translateX}],width:widthHeight, height: widthHeight}} {...this._panResponderTwo.panHandlers}>
              <Circle
                r={widthHeight}
                cx={widthHeight}
                cy={widthHeight}
                fill="#ff0000"
                {...this._panResponderTwo.panHandlers}
              />
        </Animated.View>

1 个答案:

答案 0 :(得分:0)

您可以使用createAnimatedComponent函数:

const AnimatedCircle = Animated.createAnimatedComponent(Circle);
const AnimatedG = Animated.createAnimatedComponent(G);

<AnimatedCircle
          r={widthHeight}
          cx={widthHeight}
          cy={widthHeight}
          fill="#ff0000"
          {...this._panResponderTwo.panHandlers}
          />