這是我的代碼的對象:不確定是不是(評估「this.state.starSide」)
class StarListScrollViewCell extends Component{
static propTypes = {
dateSource : React.PropTypes.array
}
constructor(props){
super(props);
this.state = {
starSide : 20,
}
}
addStar(){
LayoutAnimation.spring();
this.setState({starSide: this.state.starSide + 10});
}
componentWillMount() {
LayoutAnimation.spring();
}
render(){
return(
<View style={{backgroundColor: 'white' , height: 70 , width : Dimensions.get('window').width,flexDirection:'row'}}>
<TouchableOpacity style={{backgroundColor: 'red' ,width:Dimensions.get('window').width/7,justifyContent:'center',alignItems:'center'}}
onPress = {this.addStar()}>
<Image source={require('./star-gray.png')}
style ={{width:this.state.starSide,
height:this.state.starSide,
justifyContent:'center',alignItems:'center'}}>
</Image>
</TouchableOpacity>
</View>
);
}
}
我遇到了一個錯誤,當我點擊button.And我把它寫引用https://facebook.github.io/react-native/releases/next/docs/animations.html
正如@ owaishanif786提到你需要綁定的方法到當前組件,而且當你調用它的時候:'onPress = {this.addStar}'沒有括號 – Hosar
[this.state在反應原生中的onPress事件期間未定義]的可能重複(https://stackoverflow.com/questions/37123387/this-state-is-undefined-during-onpress-event-in-react-native) – kas