Skip to content

Commit bb2a860

Browse files
committed
improve demo UI
1 parent 9f442c0 commit bb2a860

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

WKWebViewJavascriptBridgeDemo/Demo.html

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
44
<style type='text/css'>
55
html { font-family:Helvetica; color:#222; }
6-
h1 { color:steelblue; font-size:24px; margin-top:24px; }
7-
button { margin:0 3px 10px; font-size:12px; }
8-
.logLine { border-bottom:1px solid #ccc; padding:4px 2px; font-family:courier; font-size:11px; }
6+
h1 { color:#FE8FBD; font-size:24px; margin-top:24px; }
7+
button { margin:0 3px 10px; font-size:14px; border: 2px solid #000000; }
8+
.logLine_Native { border-bottom:1px solid #FFA67C; padding:4px 2px; font-family:courier; font-size:12px; }
9+
.logLine_JS { border-bottom:1px solid #D867D8; padding:4px 2px; font-family:courier; font-size:12px; }
910
</style>
1011
</head><body>
1112
<h1>Demo</h1>
@@ -23,19 +24,19 @@ <h1>Demo</h1>
2324

2425
setupWKWebViewJavascriptBridge(function(bridge) {
2526
var uniqueId = 1
26-
function log(message, data) {
27+
function log(message, data, type) {
2728
var log = document.getElementById('log')
2829
var el = document.createElement('div')
29-
el.className = 'logLine'
30+
el.className = type == 'native' ? 'logLine_Native' : 'logLine_JS'
3031
el.innerHTML = uniqueId++ + '. ' + message + ':<br/>' + JSON.stringify(data)
3132
if (log.children.length) { log.insertBefore(el, log.children[0]) }
3233
else { log.appendChild(el) }
3334
}
3435

3536
bridge.registerHandler('testJavascriptHandler', function(data, responseCallback) {
36-
log('iOS called testJavascriptHandler with', data)
37+
log('iOS called testJavascriptHandler with', data, 'native')
3738
var responseData = { 'Javascript Says':'Right back atcha!' }
38-
log('JS responding with', responseData)
39+
log('JS responding with', responseData, 'native')
3940
responseCallback(responseData)
4041
})
4142

@@ -47,7 +48,7 @@ <h1>Demo</h1>
4748
e.preventDefault()
4849
log('JS calling handler "testiOSCallback"')
4950
bridge.callHandler('testiOSCallback', {'foo': 'bar'}, function(response) {
50-
log('JS got response', response)
51+
log('JS got response', response, 'js')
5152
})
5253
}
5354
})

WKWebViewJavascriptBridgeDemo/ViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class ViewController: UIViewController {
2525
view.addSubview(webView)
2626

2727
// setup btns
28-
callbackBtn.backgroundColor = .purple
28+
callbackBtn.backgroundColor = UIColor(red: 255.0/255, green: 166.0/255, blue: 124.0/255, alpha: 1.0)
2929
callbackBtn.setTitle("Call Handler", for: .normal)
3030
callbackBtn.addTarget(self, action: #selector(callHandler), for: .touchUpInside)
3131
view.insertSubview(callbackBtn, aboveSubview: webView)
3232
callbackBtn.frame = CGRect(x: 10, y: UIScreen.main.bounds.size.height - 80, width: UIScreen.main.bounds.size.width * 0.4, height: 35)
33-
reloadBtn.backgroundColor = .orange
33+
reloadBtn.backgroundColor = UIColor(red: 216.0/255, green: 103.0/255, blue: 216.0/255, alpha: 1.0)
3434
reloadBtn.setTitle("Reload Webview", for: .normal)
3535
reloadBtn.addTarget(self, action: #selector(reloadWebView), for: .touchUpInside)
3636
view.insertSubview(reloadBtn, aboveSubview: webView)

0 commit comments

Comments
 (0)