mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
only flex-box left
This commit is contained in:
@@ -3,56 +3,6 @@
|
||||
|
||||
export * from "./utils-common";
|
||||
|
||||
export module layout {
|
||||
var density = -1;
|
||||
var metrics: android.util.DisplayMetrics;
|
||||
|
||||
// cache the MeasureSpec constants here, to prevent extensive marshaling calls to and from Java
|
||||
// TODO: While this boosts the performance it is error-prone in case Google changes these constants
|
||||
var MODE_SHIFT = 30;
|
||||
var MODE_MASK = 0x3 << MODE_SHIFT;
|
||||
var sdkVersion = -1;
|
||||
var useOldMeasureSpec = false;
|
||||
|
||||
export function makeMeasureSpec(size: number, mode: number): number {
|
||||
if (sdkVersion === -1) {
|
||||
// check whether the old layout is needed
|
||||
sdkVersion = ad.getApplicationContext().getApplicationInfo().targetSdkVersion;
|
||||
useOldMeasureSpec = sdkVersion <= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||
}
|
||||
|
||||
if (useOldMeasureSpec) {
|
||||
return size + mode;
|
||||
}
|
||||
|
||||
return (size & ~MODE_MASK) | (mode & MODE_MASK);
|
||||
}
|
||||
|
||||
export function getDisplayMetrics(): android.util.DisplayMetrics {
|
||||
if (!metrics) {
|
||||
metrics = ad.getApplicationContext().getResources().getDisplayMetrics();
|
||||
}
|
||||
|
||||
return metrics;
|
||||
}
|
||||
|
||||
export function getDisplayDensity(): number {
|
||||
if (density === -1) {
|
||||
density = getDisplayMetrics().density;
|
||||
}
|
||||
|
||||
return density;
|
||||
}
|
||||
|
||||
export function toDevicePixels(value: number): number {
|
||||
return value * getDisplayDensity();
|
||||
}
|
||||
|
||||
export function toDeviceIndependentPixels(value: number): number {
|
||||
return value / getDisplayDensity();
|
||||
}
|
||||
}
|
||||
|
||||
// We are using "ad" here to avoid namespace collision with the global android object
|
||||
export module ad {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user