mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
refact(utils): Resolve circular dependency without duplicating any code
This commit is contained in:
10
tns-core-modules/utils/mainthread-helper.android.ts
Normal file
10
tns-core-modules/utils/mainthread-helper.android.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export function dispatchToMainThread(func: () => void) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
10
tns-core-modules/utils/mainthread-helper.d.ts
vendored
Normal file
10
tns-core-modules/utils/mainthread-helper.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Dispatches the passed function for execution on the main thread
|
||||||
|
* @param func The function to execute on the main thread.
|
||||||
|
*/
|
||||||
|
export function dispatchToMainThread(func: Function);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns Boolean value indicating whether the current thread is the main thread
|
||||||
|
*/
|
||||||
|
export function isMainThread(): boolean
|
||||||
7
tns-core-modules/utils/mainthread-helper.ios.ts
Normal file
7
tns-core-modules/utils/mainthread-helper.ios.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export function dispatchToMainThread(func: () => void) {
|
||||||
|
NSOperationQueue.mainQueue.addOperationWithBlock(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isMainThread(): Boolean {
|
||||||
|
return NSThread.isMainThread;
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import * as types from "./types";
|
import * as types from "./types";
|
||||||
import { dispatchToMainThread, isMainThread } from "./utils"
|
import { dispatchToMainThread, isMainThread } from "./mainthread-helper"
|
||||||
|
|
||||||
|
export * from "./mainthread-helper"
|
||||||
|
|
||||||
export const RESOURCE_PREFIX = "res://";
|
export const RESOURCE_PREFIX = "res://";
|
||||||
export const FILE_PREFIX = "file:///";
|
export const FILE_PREFIX = "file:///";
|
||||||
|
|||||||
@@ -372,14 +372,3 @@ Please ensure you have your manifest correctly configured with the FileProvider.
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dispatchToMainThread(func: () => void) {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|||||||
13
tns-core-modules/utils/utils.d.ts
vendored
13
tns-core-modules/utils/utils.d.ts
vendored
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
import { dip, px } from "../ui/core/view";
|
import { dip, px } from "../ui/core/view";
|
||||||
|
|
||||||
|
export * from "./mainthread-helper"
|
||||||
|
|
||||||
export const RESOURCE_PREFIX: string;
|
export const RESOURCE_PREFIX: string;
|
||||||
export const FILE_PREFIX: string;
|
export const FILE_PREFIX: string;
|
||||||
|
|
||||||
@@ -269,12 +271,6 @@ export function GC();
|
|||||||
*/
|
*/
|
||||||
export function releaseNativeObject(object: any /*java.lang.Object | NSObject*/);
|
export function releaseNativeObject(object: any /*java.lang.Object | NSObject*/);
|
||||||
|
|
||||||
/**
|
|
||||||
* Dispatches the passed function for execution on the main thread
|
|
||||||
* @param func The function to execute on the main thread.
|
|
||||||
*/
|
|
||||||
export function dispatchToMainThread(func: Function);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the current thread is the main thread. Directly calls the passed function
|
* Checks if the current thread is the main thread. Directly calls the passed function
|
||||||
* if it is, or dispatches it to the main thread otherwise.
|
* if it is, or dispatches it to the main thread otherwise.
|
||||||
@@ -291,11 +287,6 @@ export function executeOnMainThread(func: Function);
|
|||||||
*/
|
*/
|
||||||
export function mainThreadify(func: Function): (...args: any[]) => void
|
export function mainThreadify(func: Function): (...args: any[]) => void
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns Boolean value indicating whether the current thread is the main thread
|
|
||||||
*/
|
|
||||||
export function isMainThread(): boolean
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the specified path points to a resource or local file.
|
* Returns true if the specified path points to a resource or local file.
|
||||||
* @param path The path.
|
* @param path The path.
|
||||||
|
|||||||
@@ -159,14 +159,6 @@ export function openUrl(location: string): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dispatchToMainThread(func: () => void) {
|
|
||||||
NSOperationQueue.mainQueue.addOperationWithBlock(func);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isMainThread(): Boolean {
|
|
||||||
return NSThread.isMainThread;
|
|
||||||
}
|
|
||||||
|
|
||||||
class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
|
class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
|
||||||
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
|
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user