2016-01-13 82 views
0

我已經創建了一個React Native組件,併爲它添加了一些動畫。現在,當我用該元素包圍其他元素(例如:文本)時,文本也會獲取動畫。如何避免這種情況?我想讓我的組件具有動畫,但它的內部組件保持靜止。在反應本機組件中有獨立的內容

MYIMAGE組件代碼:

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

實現:

<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> 

如何實現這一目標?

回答

0

而不是讓您的自定義組件兒童的圖像,他們必須在同一水平,絕對定位。 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> 
相關問題