1 | import { android as androidHelper } from './native-helper';
|
2 | export function dispatchToMainThread(func) {
|
3 | const runOnMainThread = global.__runOnMainThread;
|
4 | if (runOnMainThread) {
|
5 | runOnMainThread(() => {
|
6 | func();
|
7 | });
|
8 | }
|
9 | else {
|
10 | new android.os.Handler(android.os.Looper.getMainLooper()).post(new java.lang.Runnable({
|
11 | run: func,
|
12 | }));
|
13 | }
|
14 | }
|
15 | export function isMainThread() {
|
16 | return android.os.Looper.myLooper() === android.os.Looper.getMainLooper();
|
17 | }
|
18 | export function dispatchToUIThread(func) {
|
19 | const activity = androidHelper.getCurrentActivity();
|
20 | if (activity && func) {
|
21 | activity.runOnUiThread(new java.lang.Runnable({
|
22 | run() {
|
23 | func();
|
24 | },
|
25 | }));
|
26 | }
|
27 | }
|
28 |
|
\ | No newline at end of file |