UNPKG

3.09 kBJavaScriptView Raw
1import * as layoutCommon from './layout-helper-common';
2import { android as AndroidUtils } from '../native-helper';
3// export * from './layout-helper-common';
4let density;
5let sdkVersion;
6let useOldMeasureSpec = false;
7export var layout;
8(function (layout) {
9 // cache the MeasureSpec constants here, to prevent extensive marshaling calls to and from Java
10 // TODO: While this boosts the performance it is error-prone in case Google changes these constants
11 layout.MODE_SHIFT = 30;
12 layout.MODE_MASK = 0x3 << layout.MODE_SHIFT;
13 layout.UNSPECIFIED = 0 << layout.MODE_SHIFT;
14 layout.EXACTLY = 1 << layout.MODE_SHIFT;
15 layout.AT_MOST = 2 << layout.MODE_SHIFT;
16 layout.MEASURED_HEIGHT_STATE_SHIFT = 0x00000010; /* 16 */
17 layout.MEASURED_STATE_TOO_SMALL = 0x01000000;
18 layout.MEASURED_STATE_MASK = 0xff000000;
19 layout.MEASURED_SIZE_MASK = 0x00ffffff;
20 function getMode(mode) {
21 return layoutCommon.getMode(mode);
22 }
23 layout.getMode = getMode;
24 function getMeasureSpecMode(spec) {
25 return layoutCommon.getMeasureSpecMode(spec);
26 }
27 layout.getMeasureSpecMode = getMeasureSpecMode;
28 function getMeasureSpecSize(spec) {
29 return layoutCommon.getMeasureSpecSize(spec);
30 }
31 layout.getMeasureSpecSize = getMeasureSpecSize;
32 function makeMeasureSpec(size, mode) {
33 if (sdkVersion === undefined) {
34 // check whether the old layout is needed
35 sdkVersion = AndroidUtils.getApplicationContext().getApplicationInfo().targetSdkVersion;
36 useOldMeasureSpec = sdkVersion <= 17;
37 }
38 if (useOldMeasureSpec) {
39 return size + mode;
40 }
41 return (size & ~layoutCommon.MODE_MASK) | (mode & layoutCommon.MODE_MASK);
42 }
43 layout.makeMeasureSpec = makeMeasureSpec;
44 function getDisplayDensity() {
45 if (density === undefined) {
46 density = AndroidUtils.getResources().getDisplayMetrics().density;
47 }
48 return density;
49 }
50 layout.getDisplayDensity = getDisplayDensity;
51 function toDevicePixels(value) {
52 return value * getDisplayDensity();
53 }
54 layout.toDevicePixels = toDevicePixels;
55 function toDeviceIndependentPixels(value) {
56 return value / getDisplayDensity();
57 }
58 layout.toDeviceIndependentPixels = toDeviceIndependentPixels;
59 function round(value) {
60 return layoutCommon.round(value);
61 }
62 layout.round = round;
63 function measureNativeView(nativeView /* android.view.View */, width, widthMode, height, heightMode) {
64 const view = nativeView;
65 view.measure(makeMeasureSpec(width, widthMode), makeMeasureSpec(height, heightMode));
66 return {
67 width: view.getMeasuredWidth(),
68 height: view.getMeasuredHeight(),
69 };
70 }
71 layout.measureNativeView = measureNativeView;
72 function measureSpecToString(measureSpec) {
73 return layoutCommon.measureSpecToString(measureSpec);
74 }
75 layout.measureSpecToString = measureSpecToString;
76})(layout || (layout = {}));
77//# sourceMappingURL=index.android.js.map
\No newline at end of file