refact(utils): Resolve circular dependency without duplicating any code

This commit is contained in:
Martin Bektchiev
2019-05-08 17:28:29 +03:00
parent a2ef6cbb4b
commit 7aed770871
7 changed files with 32 additions and 31 deletions

View 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();
}

View 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

View File

@@ -0,0 +1,7 @@
export function dispatchToMainThread(func: () => void) {
NSOperationQueue.mainQueue.addOperationWithBlock(func);
}
export function isMainThread(): Boolean {
return NSThread.isMainThread;
}

View File

@@ -1,5 +1,7 @@
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 FILE_PREFIX = "file:///";

View File

@@ -372,14 +372,3 @@ Please ensure you have your manifest correctly configured with the FileProvider.
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();
}

View File

@@ -4,6 +4,8 @@
import { dip, px } from "../ui/core/view";
export * from "./mainthread-helper"
export const RESOURCE_PREFIX: string;
export const FILE_PREFIX: string;
@@ -269,12 +271,6 @@ export function GC();
*/
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
* 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
/**
* @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.
* @param path The path.

View File

@@ -159,14 +159,6 @@ export function openUrl(location: string): boolean {
return false;
}
export function dispatchToMainThread(func: () => void) {
NSOperationQueue.mainQueue.addOperationWithBlock(func);
}
export function isMainThread(): Boolean {
return NSThread.isMainThread;
}
class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];