Hos*_*eeb 6 reactjs react-native
我是ReactNative的新手,并且具有以下组件:
<View style={{flex: 1}}>
<View style={styles.container}>
<Animated.Image style= {styles.photo}
source={{uri: this.props.user.picture.large}}/>
</View>
<View style={{backgroundColor:'whitesmoke', flex: 1}}></View>
</View>
Run Code Online (Sandbox Code Playgroud)
在样式中,我具有以下内容:
const styles = StyleSheet.create({
container: {
flex: 0.5,
backgroundColor: '#4dbce9',
alignItems: 'center',
},
photo: {
height: 150,
width: 150,
borderRadius: 75,
borderWidth: 3,
borderColor: 'white',
transform: [ // `transform` is an ordered array
{scale: this.state.profileImgBounceVal},
]
}
});
Run Code Online (Sandbox Code Playgroud)
this.state.profileImgBounceVal
在我知道的组件外部进行访问时,出现错误。除了在Animated.Image
标记内包含样式外,是否有其他解决方法?
您可以用来Stylesheet.flatten()
在组件中创建可重用的样式对象:
var animatedImageStyle = StyleSheet.flatten([
styles.photo,
{
transform: [{scale:this.state.profileImgBounceVal}]
}
])
<View style={{flex: 1}}>
<View style={styles.container}>
<Animated.Image style={animatedImageStyle}
source={{uri: this.props.user.picture.large}}/>
</View>
<View style={{backgroundColor:'whitesmoke', flex: 1}}></View>
</View>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1946 次 |
最近记录: |