React native 无法使用组件道具将不透明度值传递给图像样式
我试图根据道具中传递的值更改组件的不透明度。 这是我的密码:React native 无法使用组件道具将不透明度值传递给图像样式,react-native,React Native,我试图根据道具中传递的值更改组件的不透明度。 这是我的密码: class Sourate extends React.Component{ render(){ let opacity = this.props.bookmarkOpacity; return( <View style={styles.sourate}> <View style={{flexDirection:'
class Sourate extends React.Component{
render(){
let opacity = this.props.bookmarkOpacity;
return(
<View style={styles.sourate}>
<View style={{flexDirection:'row'}}>
<Text style={styles.sourateNum}>{this.props.sourateNumber}.</Text>
<Text style={styles.enName}>{this.props.sourateNammeEN}</Text>
</View>
<Image source={require('../Resources/bookmark.png')}
style={{
height: 30,
width: 25,
margin:15,
tintColor:"#d24141",
opacity:{opacity},
}}
/>
<Text style={styles.arName}>{this.props.sourateNameAR}</Text>
);
};
}
<Sourate
sourateNameAR={souratesData[i].ArName}
sourateNammeEN={souratesData[i].EnName}
sourateNumber={souratesData[i].SourateNumber}
SouratePage= {souratesData[i].pageNum}
bookmarkOpacity={0.0}
/>
类Sourate扩展React.Component{
render(){
让不透明度=this.props.bookmark不透明度;
报税表(
{this.props.sourateNumber}。
{this.props.souratenameen}
{this.props.sourateNameAR}
);
};
}
我看到一个红色屏幕,上面写着“更新由以下管理的视图的属性‘不透明度’时出错:RTCMageView”
不透明度的值不能从ReadableNativeMap转换为双“您正在传递一个对象
{opacity}
。您的Sourate
组件应为:
class Sourate extends React.Component{
render(){
let opacity = this.props.bookmarkOpacity;
return(
<View style={styles.sourate}>
<View style={{flexDirection:'row'}}>
<Text style={styles.sourateNum}>{this.props.sourateNumber}.</Text>
<Text style={styles.enName}>{this.props.sourateNammeEN}</Text>
</View>
<Image source={require('../Resources/bookmark.png')}
style={{height: 30,
width: 25,
margin:15,
tintColor:"#d24141",
opacity, // <----- CHANGED HERE!
}}
类Sourate扩展React.Component{
render(){
让不透明度=this.props.bookmark不透明度;
返回(
{this.props.sourateNumber}。
{this.props.souratenameen}
卸下支架卸下红色屏幕,谢谢