Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. import React, {Component} from 'react'
  2. import{
  3. StyleSheet,
  4. View,
  5. TouchableOpacity,
  6. Text
  7. } from 'react-native';
  8.  
  9. export default class TestScreen extends Component<Props> {
  10. state = {
  11. x: 0,
  12. y: 5,
  13. duration: tasks[0].duration,
  14. currentQuestion: tasks[0].question,
  15. answers: tasks[0].answers
  16.  
  17. };
  18.  
  19. nextQuestion = () => {
  20. this.setState({
  21. x: this.state.x + 1,
  22. })
  23. };
  24.  
  25.  
  26.  
  27.  
  28. tasks = [
  29. {
  30. "question" : "Pytanie 1",
  31. answers: [
  32. {
  33. "content": "Odpowiedz 1",
  34. "isCorrect" : true
  35. },
  36. {
  37. "content": "Odpowiedz 2",
  38. "isCorrect" : false
  39. },
  40. {
  41. "content": "Odpowiedz 3",
  42. "isCorrect" : false
  43. },
  44. {
  45. "content": "Odpowiedz 4",
  46. "isCorrect" : false
  47. },
  48. ],
  49. "duration": 30,
  50. },
  51. {
  52. "question" : "Pytanie 2",
  53. answers: [
  54. {
  55. "content": "Odpowiedz 1",
  56. "isCorrect" : false
  57. },
  58. {
  59. "content": "Odpowiedz 2",
  60. "isCorrect" : false
  61. },
  62. {
  63. "content": "Odpowiedz 3",
  64. "isCorrect" : true
  65. },
  66. {
  67. "content": "Odpowiedz 4",
  68. "isCorrect" : false
  69. },
  70. ],
  71. "duration": 40,
  72. },
  73. {
  74. "question" : "Pytanie 3",
  75. answers: [
  76. {
  77. "content": "Odpowiedz 1",
  78. "isCorrect" : false
  79. },
  80. {
  81. "content": "Odpowiedz 2",
  82. "isCorrect" : false
  83. },
  84. {
  85. "content": "Odpowiedz 3",
  86. "isCorrect" : true
  87. },
  88. {
  89. "content": "Odpowiedz 4",
  90. "isCorrect" : false
  91. },
  92. ],
  93. "duration": 40,
  94. },
  95. {
  96. "question" : "Pytanie 4",
  97. answers: [
  98. {
  99. "content": "Odpowiedz 1",
  100. "isCorrect" : false
  101. },
  102. {
  103. "content": "Odpowiedz 2",
  104. "isCorrect" : false
  105. },
  106. {
  107. "content": "Odpowiedz 3",
  108. "isCorrect" : true
  109. },
  110. {
  111. "content": "Odpowiedz 4",
  112. "isCorrect" : false
  113. },
  114. ],
  115. "duration": 40,
  116. },
  117. {
  118. "question" : "Pytanie 5",
  119. answers: [
  120. {
  121. "content": "Odpowiedz 1",
  122. "isCorrect" : false
  123. },
  124. {
  125. "content": "Odpowiedz 2",
  126. "isCorrect" : true
  127. },
  128. {
  129. "content": "Odpowiedz 3",
  130. "isCorrect" : true
  131. },
  132. {
  133. "content": "Odpowiedz 4",
  134. "isCorrect" : false
  135. },
  136. ],
  137. "duration": 75,
  138. },
  139.  
  140. ];
  141.  
  142.  
  143.  
  144. render() {
  145. return (
  146. <View style={styles.container}>
  147. <View style={{flexDirection: 'row', justifyContent: 'space-between', marginBottom: 20, fontSize: 15}}>
  148. <Text>Question {this.state.x+1} of {this.state.y}</Text>
  149. <Text>Time: {this.state.duration} sec</Text>
  150. </View>
  151. <Text style={{fontSize: 18, textAlign: 'center', marginBottom: 25}}>{this.state.currentQuestion}</Text>
  152. <View style={styles.answers}>
  153. <TouchableOpacity style={styles.answer} onPress={() => this.nextQuestion()}>
  154. <Text>{this.state.answers[0]}</Text>
  155. </TouchableOpacity>
  156. <TouchableOpacity style={styles.answer}>
  157. <Text>{this.state.answers[1]}</Text>
  158. </TouchableOpacity>
  159. <TouchableOpacity style={styles.answer}>
  160. <Text>{this.state.answers[2]}</Text>
  161. </TouchableOpacity>
  162. <TouchableOpacity style={styles.answer}>
  163. <Text>{this.state.answers[3]}</Text>
  164. </TouchableOpacity>
  165. </View>
  166. </View>
  167. )
  168. }
  169.  
  170.  
  171. };
  172.  
  173.  
  174. const styles = StyleSheet.create({
  175. container: {
  176. flex: 1,
  177.  
  178. },
  179. answers: {
  180. flex: 1,
  181. alignItems: 'center',
  182. justifyContent: 'space-around',
  183. borderStyle: 'solid',
  184. borderWidth: 1.7,
  185. },
  186. answer: {
  187. borderStyle: 'solid',
  188. borderRadius: 4,
  189. borderWidth: 1.2,
  190. alignItems: 'center',
  191. paddingTop: 18,
  192. paddingBottom: 18,
  193. width: '80%',
  194. }
  195. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement