mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 18:12:09 +08:00

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); ```
34 lines
738 B
TypeScript
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();
|
|
},
|
|
})
|
|
);
|
|
}
|
|
}
|