react-native-webview.git

App.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. const TESTS = {
  22. InlineWebView: {
  23. title: 'Inline HTML WebView',
  24. testId: 'inline-webview',
  25. description: 'Inline HTML WebView',
  26. render() {
  27. return <InlineWebView />;
  28. },
  29. },
  30. };
  31. type Props = {};
  32. type State = {restarting: boolean, currentTest: Object};
  33. export default class App extends Component<Props, State> {
  34. state = {
  35. restarting: false,
  36. currentTest: TESTS.InlineWebView,
  37. };
  38. _simulateRestart = () => {
  39. this.setState({restarting: true}, () => this.setState({restarting: false}));
  40. };
  41. _changeTest = testName => {
  42. this.setState({currentTest: TESTS[testName]});
  43. };
  44. render() {
  45. const {restarting, currentTest} = this.state;
  46. return (
  47. <SafeAreaView style={styles.container}>
  48. <TouchableOpacity
  49. style={styles.closeKeyboardView}
  50. onPress={() => Keyboard.dismiss()}
  51. testID="closeKeyboard"
  52. />
  53. <TouchableOpacity
  54. testID="restart_button"
  55. onPress={this._simulateRestart}
  56. style={styles.restartButton}
  57. activeOpacity={0.6}>
  58. <Text>Simulate Restart</Text>
  59. </TouchableOpacity>
  60. <View style={styles.testPickerContainer}>
  61. <Button
  62. testID="testType_getSetClear"
  63. title="Get/Set/Clear"
  64. onPress={() => this._changeTest('GetSetClear')}
  65. />
  66. <Button
  67. testID="testType_mergeItem"
  68. title="Merge Item"
  69. onPress={() => this._changeTest('MergeItem')}
  70. />
  71. </View>
  72. {restarting ? null : (
  73. <View
  74. testID={`example-${currentTest.testId}`}
  75. key={currentTest.title}
  76. style={styles.exampleContainer}>
  77. <Text style={styles.exampleTitle}>{currentTest.title}</Text>
  78. <Text style={styles.exampleDescription}>
  79. {currentTest.description}
  80. </Text>
  81. <View style={styles.exampleInnerContainer}>
  82. {currentTest.render()}
  83. </View>
  84. </View>
  85. )}
  86. </SafeAreaView>
  87. );
  88. }
  89. }
  90. const styles = StyleSheet.create({
  91. container: {
  92. flex: 1,
  93. backgroundColor: '#F5FCFF',
  94. padding: 8,
  95. },
  96. exampleContainer: {
  97. padding: 16,
  98. backgroundColor: '#FFF',
  99. borderColor: '#EEE',
  100. borderTopWidth: 1,
  101. borderBottomWidth: 1,
  102. flex: 1,
  103. },
  104. exampleTitle: {
  105. fontSize: 18,
  106. },
  107. exampleDescription: {
  108. color: '#333333',
  109. marginBottom: 16,
  110. },
  111. exampleInnerContainer: {
  112. borderColor: '#EEE',
  113. borderTopWidth: 1,
  114. paddingTop: 10,
  115. flex: 1,
  116. },
  117. restartButton: {
  118. padding: 6,
  119. fontSize: 16,
  120. borderRadius: 5,
  121. backgroundColor: '#F3F3F3',
  122. alignItems: 'center',
  123. justifyContent: 'center',
  124. alignSelf: 'flex-end',
  125. },
  126. closeKeyboardView: {
  127. width: 5,
  128. height: 5,
  129. },
  130. testPickerContainer: {
  131. flexDirection: 'row',
  132. flexWrap: 'wrap',
  133. },
  134. });