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