Sin descripción

App.tsx 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 Messaging from './examples/Messaging';
  20. const TESTS = {
  21. Messaging: {
  22. title: 'Messaging',
  23. testId: 'messaging',
  24. description: 'js-webview postMessage messaging test',
  25. render() {
  26. return <Messaging />;
  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. <Button
  156. testID="testType_messaging"
  157. title="Messaging"
  158. onPress={() => this._changeTest('Messaging')}
  159. />
  160. </View>
  161. {restarting ? null : (
  162. <View
  163. testID={`example-${currentTest.testId}`}
  164. key={currentTest.title}
  165. style={styles.exampleContainer}>
  166. <Text style={styles.exampleTitle}>{currentTest.title}</Text>
  167. <Text style={styles.exampleDescription}>
  168. {currentTest.description}
  169. </Text>
  170. <View style={styles.exampleInnerContainer}>
  171. {currentTest.render()}
  172. </View>
  173. </View>
  174. )}
  175. </SafeAreaView>
  176. );
  177. }
  178. }
  179. const styles = StyleSheet.create({
  180. container: {
  181. flex: 1,
  182. backgroundColor: '#F5FCFF',
  183. padding: 8,
  184. },
  185. exampleContainer: {
  186. padding: 16,
  187. backgroundColor: '#FFF',
  188. borderColor: '#EEE',
  189. borderTopWidth: 1,
  190. borderBottomWidth: 1,
  191. flex: 1,
  192. },
  193. exampleTitle: {
  194. fontSize: 18,
  195. },
  196. exampleDescription: {
  197. color: '#333333',
  198. marginBottom: 16,
  199. },
  200. exampleInnerContainer: {
  201. borderColor: '#EEE',
  202. borderTopWidth: 1,
  203. paddingTop: 10,
  204. flex: 1,
  205. },
  206. restartButton: {
  207. padding: 6,
  208. fontSize: 16,
  209. borderRadius: 5,
  210. backgroundColor: '#F3F3F3',
  211. alignItems: 'center',
  212. justifyContent: 'center',
  213. alignSelf: 'flex-end',
  214. },
  215. closeKeyboardView: {
  216. width: 5,
  217. height: 5,
  218. },
  219. testPickerContainer: {
  220. flexDirection: 'row',
  221. flexWrap: 'wrap',
  222. },
  223. });