diff --git a/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNSandBoxContext.java b/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNSandBoxContext.java
index 5f739b4..950c54f 100644
--- a/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNSandBoxContext.java
+++ b/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNSandBoxContext.java
@@ -25,6 +25,8 @@ public interface HNSandBoxContext extends VariablePool {
void executeFun(String funName);
+ void executeUIFun(String funName);
+
/**
* Looking for View by Id set in .layout file
*
diff --git a/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNSandBoxContextImpl.java b/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNSandBoxContextImpl.java
index f17e34a..fec2803 100644
--- a/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNSandBoxContextImpl.java
+++ b/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNSandBoxContextImpl.java
@@ -124,9 +124,26 @@ public void execute(final String script) {
HNScriptRunnerThread.runScript(this, this.mRunner, script);
}
+
+ @Override
+ public void executeFun(final String funName) {
+ HNScriptRunnerThread.post(new Runnable() {
+ @Override
+ public void run() {
+ mRunner.runFunction(funName);
+ }
+ });
+
+ }
+
@Override
- public void executeFun(String funName) {
- mRunner.runFunction(funName);
+ public void executeUIFun(final String funName) {
+ HNScriptRunnerThread.postAtFront(new Runnable() {
+ @Override
+ public void run() {
+ mRunner.runFunction(funName);
+ }
+ });
}
@NonNull
diff --git a/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNScriptRunnerThread.java b/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNScriptRunnerThread.java
index 282d674..7c1b537 100644
--- a/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNScriptRunnerThread.java
+++ b/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/HNScriptRunnerThread.java
@@ -34,6 +34,10 @@ public static void post(Runnable r) {
mHandler.post(r);
}
+ public static void postAtFront(Runnable r) {
+ mHandler.postAtFrontOfQueue(r);
+ }
+
private static class ScriptRunTask implements Runnable {
WeakReference mContextRef;
diff --git a/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/css/Styles.java b/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/css/Styles.java
index 64fce31..850897b 100644
--- a/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/css/Styles.java
+++ b/HtmlNativeAndroid/htmlnative-lib/src/main/java/com/mozz/htmlnative/css/Styles.java
@@ -400,7 +400,8 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
- sandBoxContext.executeFun(functionName);
+ // to make sure the ui function is executed as fast as possible
+ sandBoxContext.executeUIFun(functionName);
}
});