No Description

App.tsx 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import React, {Component} from 'react';
  2. import {
  3. StyleSheet,
  4. SafeAreaView,
  5. Text,
  6. TouchableOpacity,
  7. View,
  8. Keyboard,
  9. Button,
  10. Platform,
  11. } from 'react-native';
  12. import Alerts from './examples/Alerts';
  13. import Scrolling from './examples/Scrolling';
  14. import Background from './examples/Background';
  15. import Downloads from './examples/Downloads';
  16. import Uploads from './examples/Uploads';
  17. import Injection from './examples/Injection';
  18. import LocalPageLoad from './examples/LocalPageLoad';
  19. import WebGL from './examples/WebGL';
  20. const TESTS = {
  21. WebGL: {
  22. title: 'WebGL',
  23. testId: 'webgl',
  24. description: 'WebGL for Windows',
  25. render() {
  26. return <WebGL />;
  27. },
  28. },
  29. Alerts: {
  30. title: 'Alerts',
  31. testId: 'alerts',
  32. description: 'Alerts tests',
  33. render() {
  34. return <Alerts />;
  35. },
  36. },
  37. Scrolling: {
  38. title: 'Scrolling',
  39. testId: 'scrolling',
  40. description: 'Scrolling event test',
  41. render() {
  42. return <Scrolling />;
  43. },
  44. },
  45. Background: {
  46. title: 'Background',
  47. testId: 'background',
  48. description: 'Background color test',
  49. render() {
  50. return <Background />;
  51. },
  52. },
  53. Downloads: {
  54. title: 'Downloads',
  55. testId: 'downloads',
  56. description: 'File downloads test',
  57. render() {
  58. return <Downloads />;
  59. },
  60. },
  61. Uploads: {
  62. title: 'Uploads',
  63. testId: 'uploads',
  64. description: 'Upload test',
  65. render() {
  66. return <Uploads />;
  67. },
  68. },
  69. Injection: {
  70. title: 'Injection',
  71. testId: 'injection',
  72. description: 'Injection test',
  73. render() {
  74. return <Injection />;
  75. },
  76. },
  77. PageLoad: {
  78. title: 'LocalPageLoad',
  79. testId: 'LocalPageLoad',
  80. description: 'Local Page load test',
  81. render() {
  82. return <LocalPageLoad />;
  83. },
  84. },
  85. };
  86. type Props = {};
  87. type State = {restarting: boolean; currentTest: Object};
  88. export default class App extends Component<Props, State> {
  89. state = {
  90. restarting: false,
  91. currentTest: TESTS.Alerts,
  92. };
  93. _simulateRestart = () => {
  94. this.setState({restarting: true}, () => this.setState({restarting: false}));
  95. };
  96. _changeTest = (testName) => {
  97. this.setState({currentTest: TESTS[testName]});
  98. };
  99. render() {
  100. const {restarting, currentTest} = this.state;
  101. return (
  102. <SafeAreaView style={styles.container}>
  103. <TouchableOpacity
  104. style={styles.closeKeyboardView}
  105. onPress={() => Keyboard.dismiss()}
  106. testID="closeKeyboard"
  107. />
  108. <TouchableOpacity
  109. testID="restart_button"
  110. onPress={this._simulateRestart}
  111. style={styles.restartButton}
  112. activeOpacity={0.6}>
  113. <Text>Simulate Restart</Text>
  114. </TouchableOpacity>
  115. <View style={styles.testPickerContainer}>
  116. <Button
  117. testID="testType_alerts"
  118. title="Alerts"
  119. onPress={() => this._changeTest('Alerts')}
  120. />
  121. <Button
  122. testID="testType_scrolling"
  123. title="Scrolling"
  124. onPress={() => this._changeTest('Scrolling')}
  125. />
  126. <Button
  127. testID="testType_background"
  128. title="Background"
  129. onPress={() => this._changeTest('Background')}
  130. />
  131. <Button
  132. testID="testType_injection"
  133. title="Injection"
  134. onPress={() => this._changeTest('Injection')}
  135. />
  136. <Button
  137. testID="testType_pageLoad"
  138. title="LocalPageLoad"
  139. onPress={() => this._changeTest('PageLoad')}
  140. />
  141. {Platform.OS == 'ios' && (
  142. <Button
  143. testID="testType_downloads"
  144. title="Downloads"
  145. onPress={() => this._changeTest('Downloads')}
  146. />
  147. )}
  148. {Platform.OS === 'android' && (
  149. <Button
  150. testID="testType_uploads"
  151. title="Uploads"
  152. onPress={() => this._changeTest('Uploads')}
  153. />
  154. )}
  155. {Platform.OS === 'windows' && (
  156. <Button
  157. testID="testType_webGl"
  158. title="WebGL"
  159. onPress={() => this._changeTest('WebGL')}
  160. />
  161. )}
  162. </View>
  163. {restarting ? null : (
  164. <View
  165. testID={`example-${currentTest.testId}`}
  166. key={currentTest.title}
  167. style={styles.exampleContainer}>
  168. <Text style={styles.exampleTitle}>{currentTest.title}</Text>
  169. <Text style={styles.exampleDescription}>
  170. {currentTest.description}
  171. </Text>
  172. <View style={styles.exampleInnerContainer}>
  173. {currentTest.render()}
  174. </View>
  175. </View>
  176. )}
  177. </SafeAreaView>
  178. );
  179. }
  180. }
  181. const styles = StyleSheet.create({
  182. container: {
  183. flex: 1,
  184. backgroundColor: '#F5FCFF',
  185. padding: 8,
  186. },
  187. exampleContainer: {
  188. padding: 16,
  189. backgroundColor: '#FFF',
  190. borderColor: '#EEE',
  191. borderTopWidth: 1,
  192. borderBottomWidth: 1,
  193. flex: 1,
  194. },
  195. exampleTitle: {
  196. fontSize: 18,
  197. },
  198. exampleDescription: {
  199. color: '#333333',
  200. marginBottom: 16,
  201. },
  202. exampleInnerContainer: {
  203. borderColor: '#EEE',
  204. borderTopWidth: 1,
  205. paddingTop: 10,
  206. flex: 1,
  207. },
  208. restartButton: {
  209. padding: 6,
  210. fontSize: 16,
  211. borderRadius: 5,
  212. backgroundColor: '#F3F3F3',
  213. alignItems: 'center',
  214. justifyContent: 'center',
  215. alignSelf: 'flex-end',
  216. },
  217. closeKeyboardView: {
  218. width: 5,
  219. height: 5,
  220. },
  221. testPickerContainer: {
  222. flexDirection: 'row',
  223. flexWrap: 'wrap',
  224. },
  225. });