React native 在反应本机组件中具有独立的内部内容

React native 在反应本机组件中具有独立的内部内容,react-native,React Native,我已经创建了一个React原生组件并添加了一些动画。现在,当我用其他元素(例如:Text)包围该元素时,文本也会得到动画。如何避免这种情况?我想让我的组件有动画,但它的内部组件保持静止 MyImage组件代码: return ( <Image defaultSource={{uri: './placeholder.jpg'}} source={this.props.sourceUri} style={imageStyle}>

我已经创建了一个React原生组件并添加了一些动画。现在,当我用其他元素(例如:Text)包围该元素时,文本也会得到动画。如何避免这种情况?我想让我的组件有动画,但它的内部组件保持静止

MyImage组件代码:

return (
    <Image
        defaultSource={{uri: './placeholder.jpg'}}
        source={this.props.sourceUri}
        style={imageStyle}>
        <View>{this.props.children}</View>
    </Image>
);
返回(
{this.props.children}
);
实施:

<MyImage imageWidth={Dimensions.get('window').width} imageHeight={Dimensions.get('window').height / 100 * 30} sourceUri={{uri: item.image}}>
    <View style={styles.nameContainer}>
        <Text style={styles.textMain}>{item.name}</Text>
    </View>
</MyImage>

{item.name}

如何实现这一点?

与其将自定义组件的子级设置为图像的子级,不如将它们设置在同一水平面上,绝对定位。MyImage大致如下所示:

<View style={{ ... apply width and height ..., position: 'relative' }}>
    <Image style={{ top:0, bottom:0, left:0 right: 0, position: 'absolute' }} />
    <View  style={{ top:0, bottom:0, left:0 right: 0, position: 'absolute' }}>this.props.children}</View>
</View>

这个.道具.儿童}