Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. AppRegistry,
  4. StyleSheet,
  5. Text,
  6. View,
  7. TextInput,
  8. TouchableOpacity,
  9. Navigator,
  10. TouchableHighlight
  11. } from 'react-native';
  12.  
  13. export default class calu extends Component {
  14. constructor(props){
  15. super(props);
  16. this.state={f2:null, height:null,result:0};
  17. this.compute=this.compute.bind(this);
  18. }
  19. compute(){
  20. console.log('pressed');
  21. let f1=(this.state.f1);
  22. let f2=parseInt(this.state.f2);
  23.  
  24. this.setState({result: f1 + f2 });
  25. }
  26.  
  27. render() {
  28.  
  29. return (
  30. <View>
  31.  
  32. <TextInput
  33. keyboardType='numeric' onChangeText={(text) => this.setState({f1: parseInt(text)})} placeholder='enter second number' />
  34.  
  35.  
  36. <TextInput
  37. keyboardType='numeric' onChangeText={(text) => this.setState({f2: parseInt(text)})} placeholder='enter second number' />
  38.  
  39.  
  40.  
  41.  
  42. <Text> result: {this.state.result.toFixed(2)} </Text>
  43. <TouchableOpacity
  44. onPress={this.compute}>
  45. <Text> compute </Text>
  46. </TouchableOpacity>
  47. </View>
  48. );
  49. }
  50. }
  51.  
  52.  
  53.  
  54. AppRegistry.registerComponent('calu', () => calu);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement