mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Apply getter check to determine if API is exposed as property or as method for iOS backward compatibility
This commit is contained in:
7
tns-core-modules/utils/utils.d.ts
vendored
7
tns-core-modules/utils/utils.d.ts
vendored
@@ -154,6 +154,13 @@
|
||||
* Module with ios specific utilities.
|
||||
*/
|
||||
module ios {
|
||||
/**
|
||||
* Checks if the property is a function and if it is, calls it on this.
|
||||
* Designed to support backward compatibility for methods that became properties.
|
||||
* Will not work on delegates since it checks if the propertyValue is a function, and delegates are marshalled as functions.
|
||||
* Example: getter(NSRunLoop, NSRunLoop.currentRunLoop).runUntilDate(NSDate.dateWithTimeIntervalSinceNow(waitTime));
|
||||
*/
|
||||
export function getter<T>(_this: any, propertyValue: T | {(): T}): T;
|
||||
export function getTransformedText(view, source: string, transform: string): string;
|
||||
export function setWhiteSpace(view, value: string, parentView?: any);
|
||||
export function setTextAlignment(view, value: string);
|
||||
|
||||
@@ -56,6 +56,14 @@ export module ios {
|
||||
}
|
||||
}
|
||||
|
||||
export function getter<T>(_this: any, property: T | {(): T}): T {
|
||||
if (typeof property === "function") {
|
||||
return (<{(): T}>property).call(_this);
|
||||
} else {
|
||||
return <T>property;
|
||||
}
|
||||
}
|
||||
|
||||
export function getTransformedText(view, source: string, transform: string): string {
|
||||
let result = source;
|
||||
|
||||
@@ -131,13 +139,13 @@ export module ios {
|
||||
}
|
||||
|
||||
export function isLandscape(): boolean {
|
||||
var device = UIDevice.currentDevice();
|
||||
var statusBarOrientation = UIApplication.sharedApplication().statusBarOrientation;
|
||||
var device = getter(UIDevice, UIDevice.currentDevice);
|
||||
var statusBarOrientation = getter(UIApplication, UIApplication.sharedApplication).statusBarOrientation;
|
||||
var isStatusBarOrientationLandscape = isOrientationLandscape(statusBarOrientation);
|
||||
return isOrientationLandscape(device.orientation) || isStatusBarOrientationLandscape;
|
||||
}
|
||||
|
||||
export var MajorVersion = NSString.stringWithString(UIDevice.currentDevice().systemVersion).intValue;
|
||||
export var MajorVersion = NSString.stringWithString(getter(UIDevice, UIDevice.currentDevice).systemVersion).intValue;
|
||||
|
||||
export function openFile(filePath: string): boolean {
|
||||
try {
|
||||
@@ -163,8 +171,8 @@ export function GC() {
|
||||
export function openUrl(location: string): boolean {
|
||||
try {
|
||||
var url = NSURL.URLWithString(location.trim());
|
||||
if (UIApplication.sharedApplication().canOpenURL(url)) {
|
||||
return UIApplication.sharedApplication().openURL(url);
|
||||
if (ios.getter(UIApplication, UIApplication.sharedApplication).canOpenURL(url)) {
|
||||
return ios.getter(UIApplication, UIApplication.sharedApplication).openURL(url);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user