【发布时间】:2018-12-17 09:26:47
【问题描述】:
我发现 react native 可以扩展父类并覆盖某些功能。我想知道是否有可能或有其他方法。
export default class AppTextInput extends TextInput {
constructor(props){
super(props);
}
//here is some code I want to do
style(value){
var fontSize = value.fontSize;
//change fontSize
fontSize = fontSize*2;
value.fontSize = fontSize;
//call parent set style function
}
}
在actionscript 3中,我可以这样做
//do something when visible was set
override public function set visible(value:Boolean):void
{
}
编辑
hasTriggleFontSizeChange = false;
realFontSize = 12;
componentWillMount() {
var tempStyle = this.props.style;
if (!this.hasTriggleFontSizeChange) {
this.hasTriggleFontSizeChange = true;
var tempFontSize = 6;
if (tempStyle.hasOwnProperty('fontSize')) {
tempFontSize = tempStyle['fontSize'];
}
tempFontSize = 12;
var style = {fontSize: tempFontSize};
let styles = this.props.style;
//this line can change styles fontSize Value
styles = {...styles, fontSize: tempFontSize};
//but this line can't change styles fontSize Value
this.props.style = styles//{...this.props.style, fontSize: tempFontSize};
}
}
【问题讨论】:
标签: react-native styles textinput