Skip to content

Commit

Permalink
fix an lua script bug, that onClick function should also run in Scrip…
Browse files Browse the repository at this point in the history
…tThread
  • Loading branch information
hsllany committed May 30, 2017
1 parent 7000870 commit 19f3485
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HNSandBoxContext> mContextRef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down

0 comments on commit 19f3485

Please sign in to comment.