-
- All Implemented Interfaces:
public final class WebviewKo
The High level binding to webview in Kotlin
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enum
WebviewKo.WindowHint
The window size hints used by
WebviewKo.size
A Wrapper of WEBVIEW_HINT_NONE, WEBVIEW_HINT_MIN, WEBVIEW_HINT_MAX and WEBVIEW_HINT_FIXED
-
Method Summary
Modifier and Type Method Description final Unit
title(String v)
Updates the title of the native window. final Unit
url(String v)
Navigates webview to the given URLURL may be a data URI, i.e. final Unit
navigate(String v)
Navigates webview to the given URLURL may be a data URI, i.e. final Unit
html(String v)
Set webview HTML directly. final Unit
size(Integer width, Integer height, WebviewKo.WindowHint hints)
Updates the size of the native window. final Unit
initJS(String js)
Injects JavaScript code at the initialization of the new page. final Unit
init(String js)
Injects JavaScript code at the initialization of the new page. final Unit
eval(String js)
Evaluates arbitrary JavaScript code. final Unit
bind(String name, Function2<WebviewKo, String, String> fn)
Binds a native Kotlin/Java callback so that it will appear under the given name as a global JavaScript function. final Unit
unbind(String name)
Removes a callback that was previously set by webview_bind
.final Unit
dispatch(Function1<WebviewKo, Unit> fn)
Posts a function to be executed on the main thread. final Unit
show()
Runs the main loop and destroy it when terminated. final Unit
terminate()
Stops the main loop. -
-
Constructor Detail
-
WebviewKo
WebviewKo(Integer debug)
-
-
Method Detail
-
title
final Unit title(String v)
Updates the title of the native window.
Must be called from the UI thread.
- Parameters:
v
- the new title
-
url
final Unit url(String v)
Navigates webview to the given URL
URL may be a data URI, i.e. "data:text/text,...". It is often ok not to url-encode it properly, webview will re-encode it for you. Same as navigate
- Parameters:
v
- the URL or URI
-
navigate
final Unit navigate(String v)
Navigates webview to the given URL
URL may be a data URI, i.e. "data:text/text,...". It is often ok not to url-encode it properly, webview will re-encode it for you. Same as url
- Parameters:
v
- the URL or URI
-
size
final Unit size(Integer width, Integer height, WebviewKo.WindowHint hints)
Updates the size of the native window.
Accepts a WEBVIEW_HINT
- Parameters:
hints
- can be one ofWEBVIEW_HINT_NONE
,WEBVIEW_HINT_MIN
,WEBVIEW_HINT_MAX
orWEBVIEW_HINT_FIXED
-
initJS
final Unit initJS(String js)
Injects JavaScript code at the initialization of the new page.
Every time the webview will open a new page - this initialization code will be executed. It is guaranteed that code is executed before window.onload.
- Parameters:
js
- the JS code
-
init
final Unit init(String js)
Injects JavaScript code at the initialization of the new page.
Same as
initJS
. Every time the webview will open a new page - this initialization code will be executed. It is guaranteed that code is executed before window.onload.- Parameters:
js
- the JS code
-
eval
final Unit eval(String js)
Evaluates arbitrary JavaScript code.
Evaluation happens asynchronously, also the result of the expression is ignored. Use the
webview_bind
function if you want to receive notifications about the results of the evaluation.- Parameters:
js
- the JS code
-
bind
final Unit bind(String name, Function2<WebviewKo, String, String> fn)
Binds a native Kotlin/Java callback so that it will appear under the given name as a global JavaScript function.
Callback receives a request string. Request string is a JSON array of all the arguments passed to the JavaScript function.
- Parameters:
name
- the name of the global JavaScript functionfn
- the callback function which receives the request parameter in JSON as input and return the response to JS in JSON.
-
unbind
final Unit unbind(String name)
Removes a callback that was previously set by
webview_bind
.- Parameters:
name
- the name of JS function used inwebview_bind
-
dispatch
final Unit dispatch(Function1<WebviewKo, Unit> fn)
Posts a function to be executed on the main thread.
It safely schedules the callback to be run on the main thread on the next main loop iteration. Like
invokeLater
in Swing- Parameters:
fn
- the function to be executed on the main thread.
-
show
final Unit show()
Runs the main loop and destroy it when terminated.
This will block the thread.
-
-
-
-