react-native-webview.git

App.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow
  9. */
  10. import React, {Component} from 'react';
  11. import {
  12. StyleSheet,
  13. SafeAreaView,
  14. Text,
  15. TouchableOpacity,
  16. View,
  17. Keyboard,
  18. Button,
  19. } from 'react-native';
  20. import InlineWebView from './examples/InlineWebView';
  21. import Alerts from './examples/Alerts';
  22. const TESTS = {
  23. InlineWebView: {
  24. title: 'Inline HTML WebView',
  25. testId: 'inline-webview',
  26. description: 'Inline HTML WebView',
  27. render() {
  28. return <InlineWebView />;
  29. },
  30. },
  31. Alerts: {
  32. title: 'Alerts',
  33. testId: 'alerts',
  34. description: 'Alerts tests',
  35. render() {
  36. return <Alerts />;
  37. },
  38. },
  39. };
  40. type Props = {};
  41. type State = {restarting: boolean, currentTest: Object};
  42. export default class App extends Component<Props, State> {
  43. state = {
  44. restarting: false,
  45. currentTest: TESTS.InlineWebView,
  46. };
  47. _simulateRestart = () => {
  48. this.setState({restarting: true}, () => this.setState({restarting: false}));
  49. };
  50. _changeTest = testName => {
  51. this.setState({currentTest: TESTS[testName]});
  52. };
  53. render() {
  54. const {restarting, currentTest} = this.state;
  55. return (
  56. <SafeAreaView style={styles.container}>
  57. <TouchableOpacity
  58. style={styles.closeKeyboardView}
  59. onPress={() => Keyboard.dismiss()}
  60. testID="closeKeyboard"
  61. />
  62. <TouchableOpacity
  63. testID="restart_button"
  64. onPress={this._simulateRestart}
  65. style={styles.restartButton}
  66. activeOpacity={0.6}>
  67. <Text>Simulate Restart</Text>
  68. </TouchableOpacity>
  69. <View style={styles.testPickerContainer}>
  70. <Button
  71. testID="testType_inlineWebView"
  72. title="InlineWebView"
  73. onPress={() => this._changeTest('InlineWebView')}
  74. />
  75. <Button
  76. testID="testType_alerts"
  77. title="Alerts"
  78. onPress={() => this._changeTest('Alerts')}
  79. />
  80. </View>
  81. {restarting ? null : (
  82. <View
  83. testID={`example-${currentTest.testId}`}
  84. key={currentTest.title}
  85. style={styles.exampleContainer}>
  86. <Text style={styles.exampleTitle}>{currentTest.title}</Text>
  87. <Text style={styles.exampleDescription}>
  88. {currentTest.description}
  89. </Text>
  90. <View style={styles.exampleInnerContainer}>
  91. {currentTest.render()}
  92. </View>
  93. </View>
  94. )}
  95. </SafeAreaView>
  96. );
  97. }
  98. }
  99. const styles = StyleSheet.create({
  100. container: {
  101. flex: 1,
  102. backgroundColor: '#F5FCFF',
  103. padding: 8,
  104. },
  105. exampleContainer: {
  106. padding: 16,
  107. backgroundColor: '#FFF',
  108. borderColor: '#EEE',
  109. borderTopWidth: 1,
  110. borderBottomWidth: 1,
  111. flex: 1,
  112. },
  113. exampleTitle: {
  114. fontSize: 18,
  115. },
  116. exampleDescription: {
  117. color: '#333333',
  118. marginBottom: 16,
  119. },
  120. exampleInnerContainer: {
  121. borderColor: '#EEE',
  122. borderTopWidth: 1,
  123. paddingTop: 10,
  124. flex: 1,
  125. },
  126. restartButton: {
  127. padding: 6,
  128. fontSize: 16,
  129. borderRadius: 5,
  130. backgroundColor: '#F3F3F3',
  131. alignItems: 'center',
  132. justifyContent: 'center',
  133. alignSelf: 'flex-end',
  134. },
  135. closeKeyboardView: {
  136. width: 5,
  137. height: 5,
  138. },
  139. testPickerContainer: {
  140. flexDirection: 'row',
  141. flexWrap: 'wrap',
  142. },
  143. });