我有几个关于react-native的问题。我在开发一个计算器。在计算器中有两个文本视图,负责输入行(从按钮输入)和显示结果。我需要按下"=“按钮将输入行转移到android-module,解析此字符串,并将数值结果返回到text-view,结果在result-view中。我该怎么做呢?
我读到我需要创建一个本机模块,但不知道如何从js获取文本。据我所知,我需要一个回调函数来设置结果视图中的文本。
我的代码:
<View style={{backgroundColor:'#282828',height:50}}>
<View style={{flex:1,justifyContent:'center'}}>
<Text style={[styles.resultText,{fontSize:(30-(this.state.result.toString().length))}]}>
{this.state.result}
</Text> //It's a result text-view
</View>
</View>
<View style={{flex:1,flexDirection:'column',justifyContent:'flex-end'}}>
<View style={{flex:1,backgroundColor:'#494949'}}>
<View style={{flex:1,alignItems:'center',flexDirection:'row'}}>
<Text style={styles.formulaText}>
{this.state.formula}
</Text> //It's a input text-view
</View>
</View>//Below is another code
<Button style={styles.equalButton} titleStyle = {styles.titleOperationStyle} onPress={this.onPressSubmitResult} title="="/>//Equals button提前谢谢你。另外,我的英语很抱歉。
发布于 2018-01-17 03:30:09
您不必从本地调用getText setText。所有你想要的都可以通过React-Native来完成。在Js文件中自己编写代码,在那里进行计算,更新状态,并以文本形式显示结果!
https://stackoverflow.com/questions/48276568
复制相似问题