【问题标题】:Icon color not changed on press in react native按下本机反应时图标颜色未更改
【发布时间】:2018-11-10 07:27:22
【问题描述】:

这是我的代码

import React, {
    Component
} from 'react'

import {
Body,
Text,
View
} from 'native-base'
import {
Icon
} from 'react-native-elements'

export default class App extends Component {
    constructor(props) {
    super(props);
    this.state = {
        iconColour: "red"
      }
  }

   func() {
    console.warn("changed")
    this.setState({
        iconColor: "blue"
    })
  }

 render() {
    return (
        <View>
    <Text> textInComponent </Text>
    <Icon name='map' color={this.state.iconColour} onPress= 
       {()=>this.func()}/>
    </View>
       )
     } 
 }

我想在按下时改变图标的​​颜色

但是颜色没有更新

功能有效,状态改变,但视图未更新

我想我错过了一件简单的事情

我搜索了但我找不到类似的情况

我认为应该运行一个命令来渲染具有新属性的视图

感谢您的帮助

【问题讨论】:

    标签: react-native


    【解决方案1】:

    只需将iconColor: "blue" 更改为iconColour: "blue":))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-23
      • 2023-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 2012-11-17
      相关资源
      最近更新 更多