public final class iOS extends Object implements Executor, Fn.Presenter, Fn.KeepAlive, Flushable
To use this presenter in your RoboVM based project, please specify following dependency:
<dependency> <groupId>com.dukescript.presenters</groupId> <artifactId>ios</artifactId> <!-- gives you RoboVM version --> <version>1.x</version> </dependency>
If you are using Multi OS Engine, just change the dependency to refer to moe artifact:
<dependency> <groupId>com.dukescript.presenters</groupId> <artifactId>moe</artifactId> <!-- gives you Multi OS Engine version --> <version>1.x</version> <-- at least 1.4 --> </dependency>both of these versions use the same API and thus they are covered by the same Javadoc of this
iOS
class.
Embedding
Read more about embedding DukeScript technology into existing
Multi OS Engine or RoboVM iOS application. Start by reading javadoc
of the
configure
method.
Cross-Platform
Learn how to build fully portable (iOS, browser, desktop) Java applications
in DukeScript getting
started tutorial. The great value of the tutorial is that it
helps you set your project up correctly - getting the classpath right may be
tough for the first time.
Launching the presenter
is a matter of a few BrowserBuilder
calls and then running your initialization code when
page load is finished.
Constructor and Description |
---|
iOS()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
static <WebView> Executor |
configure(String licenseKey,
WebView view,
String page)
Configures an instance of
WebView to give you easy access to
HTML features from Java. |
Fn |
defineFn(String code,
String... args) |
Fn |
defineFn(String code,
String[] args,
boolean[] keep) |
void |
displayPage(URL page,
Runnable onPageLoad) |
void |
execute(Runnable command)
Executes the command in the
context of this presenter. |
void |
flush() |
void |
loadScript(Reader reader) |
public iOS()
ServiceLoader.load(java.lang.Class)
to lookup instance of presenter registered on the classpath of the
application.public static <WebView> Executor configure(String licenseKey, WebView view, String page)
Configures an instance of WebView
to give you easy access to
HTML features from Java. Use this method to embed HTML components
into your existing application. By configuring your apple.uikit.UIWebView
(in case of Multi OS Engine) or org.robovm.apple.uikit.UIWebView
(in case of RoboVM version of this library)
you can use all the DukeScript
goodies like:
and still code in the same language that you use for the rest of your application - e.g. in Java or Kotlin.
Accessing the HTML Content
There can be multiple WebView
components in your application
and it is thus essential to always identify the one you are working with.
As such the HTML content of your WebView
needs to be accessed from
a dedicated Executor
provided to you as a return value of the
configure
method. Use Executor.execute(java.lang.Runnable)
to switch
into the context of the WebView
and perform an action.
Here is an example to display an alert in your view
and
its associated executor
created as a result of
The example is usingExecutor
executor =iOS.configure
(null, view, null);executor
.execute(newRunnable
{ public void run() { alert("Hello World!"); }@JavaScriptBody
(args = { "msg" }, body = "alert(msg);") native void alert(String msg); });
JavaScriptBody
annotation (you can read
more about this building block of DukeScript system here
),
but in most cases you are likely to use one of the predefined Java wrappers. For example there
are
JQuery bindings which you may consider to use instead.
Threading
The HTML content of your WebView
needs to be accessed from a single
UI thread. The same UI thread is also making callbacks
to your Java code. To post a task into such thread use the returned
Executor
's execute(java.lang.Runnable)
method. When
inside of the executor you can access the HTML as well as native components
of your iOS application.
This presenter is licensed under GPLv3 license - visit DukeScript website for commercial licenses and support.
WebView
- either apple.uikit.UIWebView
or org.robovm.apple.uikit.UIWebView
depending on
the version of the JVM you are usinglicenseKey
- ignoredview
- the WebView
to configure and make ready for access from Java codepage
- the initial page to load - usually read from assets - e.g. the URL looks like: file:///android_asset/mypage.html
public final void execute(Runnable command)
context
of this presenter.
The behavior is specified by BrwsrCtx.execute(java.lang.Runnable)
method - e.g. if we are on the right thread, let's execute the
command
synchronously, otherwise pass the command to the queue
in the right UI thread and execute it asynchronously later.public void displayPage(URL page, Runnable onPageLoad)
displayPage
in interface Fn.Presenter
public Fn defineFn(String code, String... args)
defineFn
in interface Fn.Presenter
public void loadScript(Reader reader) throws Exception
loadScript
in interface Fn.Presenter
Exception
public Fn defineFn(String code, String[] args, boolean[] keep)
defineFn
in interface Fn.KeepAlive
public void flush() throws IOException
flush
in interface Flushable
IOException
Copyright © 2020. All rights reserved.