Files
NativeScript/packages/core/utils/mainthread-helper.android.ts
Igor Randjelovic f64355ba7a refactor: improved core barrel exports and Application class (#10286)
BREAKING CHANGES:

`Application.orientation` is no longer a function.

Migration: Remove `()` from the `Application.orientation()` call:
```diff
import { Application } from "@nativescript/core";

-console.log(Application.orientation());
+console.log(Application.orientation);
```


`Application.systemAppearance` is no longer a function.

Migration: Remove `()` from the `Application.systemAppearance()` call:
```diff
import { Application } from "@nativescript/core";

-console.log(Application.systemAppearance());
+console.log(Application.systemAppearance);
```
2023-05-25 07:45:39 -07:00

34 lines
738 B
TypeScript

import { android as androidHelper } from './native-helper';
export function dispatchToMainThread(func: () => void) {
const runOnMainThread = (global as any).__runOnMainThread;
if (runOnMainThread) {
runOnMainThread(() => {
func();
});
} else {
new android.os.Handler(android.os.Looper.getMainLooper()).post(
new java.lang.Runnable({
run: func,
})
);
}
}
export function isMainThread(): boolean {
return android.os.Looper.myLooper() === android.os.Looper.getMainLooper();
}
export function dispatchToUIThread(func: () => void) {
const activity = androidHelper.getCurrentActivity();
if (activity && func) {
activity.runOnUiThread(
new java.lang.Runnable({
run() {
func();
},
})
);
}
}