Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. import React from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. TouchableOpacity
  7. } from 'react-native';
  8.  
  9.  
  10.  
  11. export default class App extends React.Component {
  12. constructor(props) {
  13. super(props)
  14. this.state = { x: '' }
  15. this.onPress = this.onPress.bind(this)
  16. }
  17.  
  18. onPress = (param) => {
  19. // alert(param)
  20. var wartosc = this.state.x
  21. switch (param) {
  22. case 1:
  23. wartosc = wartosc + "1"
  24. break
  25. case 2:
  26. wartosc = wartosc + "2"
  27. break
  28. case 3:
  29. wartosc = wartosc + "3"
  30. break
  31. case 4:
  32. wartosc = wartosc + "4"
  33. break
  34. case 5:
  35. wartosc = wartosc + "5"
  36. break
  37. case 6:
  38. wartosc = wartosc + "6"
  39. break
  40. case 7:
  41. wartosc = wartosc + "7"
  42. break
  43. case 8:
  44. wartosc = wartosc + "8"
  45. break
  46. case 9:
  47. wartosc = wartosc + "9"
  48. break
  49. case 0:
  50. wartosc = wartosc + "0"
  51. break
  52. case "+":
  53. if (wartosc[wartosc.length - 1] == '+' || wartosc[wartosc.length - 1] == '/')
  54. wartosc[wartosc.length - 1] = '+'
  55. else
  56. wartosc = wartosc + "+"
  57. break
  58. case "/":
  59. if (wartosc[wartosc.length - 1] == '/')
  60. break
  61. wartosc = wartosc + "/"
  62. break
  63. case "C":
  64. wartosc = ""
  65. break
  66. case "-":
  67. wartosc = wartosc + "-"
  68. break
  69. case "*":
  70. wartosc = wartosc + "*"
  71. break
  72. case "=":
  73. wartosc = wartosc + "=" + eval(wartosc)
  74. break
  75.  
  76. }
  77. this.setState({ x: wartosc })
  78.  
  79.  
  80. }
  81. render() {
  82. console.log("App") // tą konsolę zobacz w przeglądarce
  83. return (
  84. <View style={[styles.container, styles.horizontal]}>
  85. <View style={{ flex: 1, backgroundColor: "aqua" }}><Text style={styles.czcionka1}>{this.state.x}</Text>
  86.  
  87. </View>
  88.  
  89. <View style={{ flex: 2, flexDirection: "row" }}>
  90. <View style={{ flex: 3, backgroundColor: "darkslategrey", flexDirection: "row", flexWrap: "wrap" }}>
  91. <TouchableOpacity onPress={() => this.onPress(1)} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>1</Text></View></TouchableOpacity>
  92. <TouchableOpacity onPress={() => this.onPress(2)} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>2</Text></View></TouchableOpacity>
  93. <TouchableOpacity onPress={() => this.onPress(3)} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>3</Text></View></TouchableOpacity>
  94. <TouchableOpacity onPress={() => this.onPress(4)} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>4</Text></View></TouchableOpacity>
  95. <TouchableOpacity onPress={() => this.onPress(5)} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>5</Text></View></TouchableOpacity>
  96. <TouchableOpacity onPress={() => this.onPress(6)} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>6</Text></View></TouchableOpacity>
  97. <TouchableOpacity onPress={() => this.onPress(7)} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>7</Text></View></TouchableOpacity>
  98. <TouchableOpacity onPress={() => this.onPress(8)} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>8</Text></View></TouchableOpacity>
  99. <TouchableOpacity onPress={() => this.onPress(9)} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>9</Text></View></TouchableOpacity>
  100. <TouchableOpacity onPress={() => this.onPress(".")} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>.</Text></View></TouchableOpacity>
  101. <TouchableOpacity onPress={() => this.onPress(0)} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>0</Text></View></TouchableOpacity>
  102. <TouchableOpacity onPress={() => this.onPress("=")} style={{ flexDirection: 'column', height: "25%", width: "33.33%", justifyContent: "center" }}><View><Text style={styles.czcionka}>=</Text></View></TouchableOpacity>
  103.  
  104. </View>
  105. <View style={{ flex: 1, backgroundColor: "silver" }}>
  106. <TouchableOpacity onPress={() => this.onPress("C")} style={{ flex: 1, justifyContent: "center" }}><View><Text style={styles.czcionka}>C</Text></View></TouchableOpacity>
  107. <TouchableOpacity onPress={() => this.onPress("/")} style={{ flex: 1, justifyContent: "center" }}><View><Text style={styles.czcionka}>/</Text></View></TouchableOpacity>
  108. <TouchableOpacity onPress={() => this.onPress("*")} style={{ flex: 1, justifyContent: "center" }}><View><Text style={styles.czcionka}>*</Text></View></TouchableOpacity>
  109. <TouchableOpacity onPress={() => this.onPress("-")} style={{ flex: 1, justifyContent: "center" }}><View><Text style={styles.czcionka}>-</Text></View></TouchableOpacity>
  110. <TouchableOpacity onPress={() => this.onPress("+")} style={{ flex: 1, justifyContent: "center" }}><View><Text style={styles.czcionka}>+</Text></View></TouchableOpacity>
  111.  
  112. </View>
  113.  
  114. </View>
  115.  
  116. </View>
  117. );
  118. }
  119. }
  120.  
  121. const styles = StyleSheet.create({
  122. container: {
  123. flex: 1,
  124. justifyContent: "center",
  125.  
  126. },
  127. horizontal: {
  128. flexDirection: "column",
  129. justifyContent: "space-around",
  130.  
  131. },
  132. czcionka: {
  133. fontSize: 25, color: "white", textAlign: "center",
  134. },
  135. czcionka1: {
  136. fontSize: 50, color: "white", position:"absolute", bottom:0, right:0
  137. },
  138.  
  139. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement