@nativescript/core
Version:
A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.
86 lines • 3.48 kB
JavaScript
import * as layoutCommon from './layout-helper-common';
import { android as androidUtils } from '../native-helper';
// export * from './layout-helper-common';
let density;
let sdkVersion;
let useOldMeasureSpec = false;
let supportsRtl;
export var layout;
(function (layout) {
// 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
layout.MODE_SHIFT = 30;
layout.MODE_MASK = 0x3 << layout.MODE_SHIFT;
layout.UNSPECIFIED = 0 << layout.MODE_SHIFT;
layout.EXACTLY = 1 << layout.MODE_SHIFT;
layout.AT_MOST = 2 << layout.MODE_SHIFT;
layout.MEASURED_HEIGHT_STATE_SHIFT = 0x00000010; /* 16 */
layout.MEASURED_STATE_TOO_SMALL = 0x01000000;
layout.MEASURED_STATE_MASK = 0xff000000;
layout.MEASURED_SIZE_MASK = 0x00ffffff;
function getMode(mode) {
return layoutCommon.getMode(mode);
}
layout.getMode = getMode;
function getMeasureSpecMode(spec) {
return layoutCommon.getMeasureSpecMode(spec);
}
layout.getMeasureSpecMode = getMeasureSpecMode;
function getMeasureSpecSize(spec) {
return layoutCommon.getMeasureSpecSize(spec);
}
layout.getMeasureSpecSize = getMeasureSpecSize;
function makeMeasureSpec(size, mode) {
if (sdkVersion === undefined) {
// check whether the old layout is needed
sdkVersion = androidUtils.getApplicationContext().getApplicationInfo().targetSdkVersion;
useOldMeasureSpec = sdkVersion <= 17;
}
if (useOldMeasureSpec) {
return size + mode;
}
return (size & ~layout.MODE_MASK) | (mode & layout.MODE_MASK);
}
layout.makeMeasureSpec = makeMeasureSpec;
function hasRtlSupport() {
if (supportsRtl === undefined) {
const FLAG_SUPPORTS_RTL = android.content.pm.ApplicationInfo.FLAG_SUPPORTS_RTL;
supportsRtl = (androidUtils.getApplicationContext().getApplicationInfo().flags & FLAG_SUPPORTS_RTL) == FLAG_SUPPORTS_RTL;
}
return supportsRtl;
}
layout.hasRtlSupport = hasRtlSupport;
function getDisplayDensity() {
if (density === undefined) {
density = androidUtils.getResources().getDisplayMetrics().density;
}
return density;
}
layout.getDisplayDensity = getDisplayDensity;
function toDevicePixels(value) {
return value * getDisplayDensity();
}
layout.toDevicePixels = toDevicePixels;
function toDeviceIndependentPixels(value) {
return value / getDisplayDensity();
}
layout.toDeviceIndependentPixels = toDeviceIndependentPixels;
function round(value) {
return layoutCommon.round(value);
}
layout.round = round;
function measureNativeView(nativeView /* android.view.View */, width, widthMode, height, heightMode) {
const view = nativeView;
view.measure(makeMeasureSpec(width, widthMode), makeMeasureSpec(height, heightMode));
return {
width: view.getMeasuredWidth(),
height: view.getMeasuredHeight(),
};
}
layout.measureNativeView = measureNativeView;
function measureSpecToString(measureSpec) {
return layoutCommon.measureSpecToString(measureSpec);
}
layout.measureSpecToString = measureSpecToString;
})(layout || (layout = {}));
//# sourceMappingURL=index.android.js.map