-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.1.html
More file actions
78 lines (71 loc) · 2.54 KB
/
Copy pathindex.1.html
File metadata and controls
78 lines (71 loc) · 2.54 KB
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
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>test</title>
<style>
.status {
font-size: 12px;
text-align: center;
}
.input {
width: 100%;
box-sizing: border-box;
line-height: 25px;
margin: 5px 0;
}
button {
display: block;
width: 100%;
box-sizing: border-box;
margin: 5px 0;
}
</style>
</head>
<body>
<h1>Web Side:</h1>
<p class="status">[Loading] Waiting for bridge ready</p>
<input class="input" type="text" placeholder="Some..." />
<button class="set" label="Send To RN">Send To RN</button>
<button class="get" label="Get From RN">Get From RN</button>
<script src="https://cdn.bootcss.com/es6-promise/4.0.5/es6-promise.auto.min.js"></script>
<script src="https://tb1.bdstatic.com/tb/libs/rnwi-browser.js"></script>
<!-- DEV
<script src="http://localhost:8080/browser.js"></script>
-->
<script>
(function () {
var $input = document.querySelector('.input')
var $status = document.querySelector('.status')
var getFromNative = window.WebViewInvoke.bind('get')
var setToNative = window.WebViewInvoke.bind('set')
var webReady = window.WebViewInvoke.bind('init')
function nativeWannaGet() {
return $input.value
}
function nativeWannaSet(data) {
$status.innerText = '[Receive From RN] "' + data + '"'
}
window.WebViewInvoke.define('get', nativeWannaGet)
window.WebViewInvoke.define('set', nativeWannaSet)
webReady().then(function() {
$status.innerText = '[Ready] Done!'
})
document.querySelector('.set').addEventListener('click', function(){
$status.innerText = '[Set To RN] Sending'
setToNative($input.value)
.then(function () {
$status.innerText = '[Set To RN] Success'
})
})
document.querySelector('.get').addEventListener('click', function(){
getFromNative()
.then(function (data) {
$status.innerText = '[Get From RN] "' + data + '"'
})
})
})()
</script>
</body>
</html>