Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 无法使用组件道具将不透明度值传递给图像样式_React Native - Fatal编程技术网

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}

卸下支架卸下红色屏幕,谢谢