React-Native 将样式传递给 props.children
React-Native passing style to props.children
我正在尝试将样式传递给 children,我的代码是:
render() {
const RotateData = this.RotateValueHolder.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg']
});
Object.assign(this.props.children.props.style,{'transform': [{'rotate': RotateData}] });
return (
<View style={{flex:1}}>
{this.props.children}
</View>
);
}
我收到此错误:
Invariant Violation: Transform with key of "rotate" must be a string:
{"rotate":"0deg"}
旋转只能由动画组件使用,因此您需要将样式应用于 Animated.View 或任何动画元素。所以尝试将它与动画组件一起使用。
我正在尝试将样式传递给 children,我的代码是:
render() {
const RotateData = this.RotateValueHolder.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg']
});
Object.assign(this.props.children.props.style,{'transform': [{'rotate': RotateData}] });
return (
<View style={{flex:1}}>
{this.props.children}
</View>
);
}
我收到此错误:
Invariant Violation: Transform with key of "rotate" must be a string:
{"rotate":"0deg"}
旋转只能由动画组件使用,因此您需要将样式应用于 Animated.View 或任何动画元素。所以尝试将它与动画组件一起使用。