mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
definitions fixed
This commit is contained in:
84
utils/utils.ios.ts
Normal file
84
utils/utils.ios.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import common = require("utils/utils-common");
|
||||
import colorModule = require("color");
|
||||
|
||||
// merge the exports of the common file with the exports of this file
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(common, exports);
|
||||
|
||||
function isOrientationLandscape(orientation: number) {
|
||||
return orientation === UIDeviceOrientation.UIDeviceOrientationLandscapeLeft || orientation === UIDeviceOrientation.UIDeviceOrientationLandscapeRight;
|
||||
}
|
||||
|
||||
export module layout {
|
||||
var MODE_SHIFT = 30;
|
||||
var MODE_MASK = 0x3 << MODE_SHIFT;
|
||||
|
||||
export function makeMeasureSpec(size: number, mode: number): number {
|
||||
return (Math.round(size) & ~MODE_MASK) | (mode & MODE_MASK);
|
||||
}
|
||||
|
||||
export function getDisplayDensity(): number {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
export module ios {
|
||||
export module collections {
|
||||
export function jsArrayToNSArray(str: string[]): any {
|
||||
var arr = new NSMutableArray();
|
||||
if ("undefined" !== typeof str) {
|
||||
for (var element in str) {
|
||||
arr.addObject(str[element]);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
export function nsArrayToJSArray(a: any): string[] {
|
||||
var arr = [];
|
||||
if ("undefined" !== typeof a) {
|
||||
for (var i = 0; i < a.count(); i++) {
|
||||
arr.push(a.objectAtIndex(i));
|
||||
}
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
|
||||
export function getColor(uiColor: UIColor): colorModule.Color {
|
||||
var redRef = new interop.Reference<number>();
|
||||
var greenRef = new interop.Reference<number>();
|
||||
var blueRef = new interop.Reference<number>();
|
||||
var alphaRef = new interop.Reference<number>();
|
||||
|
||||
uiColor.getRedGreenBlueAlpha(redRef, greenRef, blueRef, alphaRef);
|
||||
var red = redRef.value * 255;
|
||||
var green = greenRef.value * 255;
|
||||
var blue = blueRef.value * 255;
|
||||
var alpha = alphaRef.value * 255;
|
||||
|
||||
return new colorModule.Color(alpha, red, green, blue);
|
||||
}
|
||||
|
||||
export function getActualHeight(uiView: UIView): number {
|
||||
if (uiView.window && !uiView.hidden) {
|
||||
return uiView.frame.size.height;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function isLandscape(): boolean {
|
||||
var device = UIDevice.currentDevice();
|
||||
var statusBarOrientation = UIApplication.sharedApplication().statusBarOrientation;
|
||||
var isStatusBarOrientationLandscape = isOrientationLandscape(statusBarOrientation);
|
||||
return isOrientationLandscape(device.orientation) || isStatusBarOrientationLandscape;
|
||||
}
|
||||
|
||||
export var MajorVersion = NSString.stringWithString(UIDevice.currentDevice().systemVersion).intValue;
|
||||
}
|
||||
|
||||
export function GC() {
|
||||
__collect();
|
||||
}
|
||||
Reference in New Issue
Block a user