react-native-webview.git

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 {Text, View} from 'react-native';
  12. import WebView from 'react-native-webview';
  13. const HTML = `
  14. <!DOCTYPE html>\n
  15. <html>
  16. <head>
  17. <title>Alerts</title>
  18. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  19. <meta name="viewport" content="width=320, user-scalable=no">
  20. <style type="text/css">
  21. body {
  22. margin: 0;
  23. padding: 0;
  24. font: 62.5% arial, sans-serif;
  25. background: #ccc;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <button onclick="showAlert()">Show alert</button>
  31. <button onclick="showConfirm()">Show confirm</button>
  32. <button onclick="showPrompt()">Show prompt</button>
  33. <p id="demo"></p>
  34. <script>
  35. function showAlert() {
  36. alert("Hello! I am an alert box!");
  37. document.getElementById("demo").innerHTML = "Alert dismissed!";
  38. }
  39. function showConfirm() {
  40. var response;
  41. if (confirm("Press a button!")) {
  42. response = "You pressed OK on confirm!";
  43. } else {
  44. response = "You pressed Cancel on confirm!";
  45. }
  46. document.getElementById("demo").innerHTML = response;
  47. }
  48. function showPrompt() {
  49. var message;
  50. const name = prompt("Please enter your name", "Name");
  51. if (name !== null) {
  52. message = "Hello " + name;
  53. } else {
  54. message = "You pressed Cancel on prompt!";
  55. }
  56. document.getElementById("demo").innerHTML = message;
  57. }
  58. </script>
  59. </body>
  60. </html>
  61. `;
  62. type Props = {};
  63. type State = {};
  64. export default class Alerts extends Component<Props, State> {
  65. state = {};
  66. render() {
  67. return (
  68. <View style={{ height: 120 }}>
  69. <WebView
  70. source={{html: HTML}}
  71. automaticallyAdjustContentInsets={false}
  72. />
  73. </View>
  74. );
  75. }
  76. }