UNPKG

1.67 kBJavaScriptView Raw
1// cache the MeasureSpec constants here, to prevent extensive marshaling calls to and from Java
2// TODO: While this boosts the performance it is error-prone in case Google changes these constants
3export const MODE_SHIFT = 30;
4export const MODE_MASK = 0x3 << MODE_SHIFT;
5export const UNSPECIFIED = 0 << MODE_SHIFT;
6export const EXACTLY = 1 << MODE_SHIFT;
7export const AT_MOST = 2 << MODE_SHIFT;
8export const MEASURED_HEIGHT_STATE_SHIFT = 0x00000010; /* 16 */
9export const MEASURED_STATE_TOO_SMALL = 0x01000000;
10export const MEASURED_STATE_MASK = 0xff000000;
11export const MEASURED_SIZE_MASK = 0x00ffffff;
12export function getMode(mode) {
13 switch (mode) {
14 case EXACTLY:
15 return 'Exact';
16 case AT_MOST:
17 return 'AtMost';
18 default:
19 return 'Unspecified';
20 }
21}
22export function getMeasureSpecMode(spec) {
23 return spec & MODE_MASK;
24}
25export function getMeasureSpecSize(spec) {
26 return spec & ~MODE_MASK;
27}
28export function measureSpecToString(measureSpec) {
29 const mode = getMeasureSpecMode(measureSpec);
30 const size = getMeasureSpecSize(measureSpec);
31 let text = 'MeasureSpec: ';
32 if (mode === UNSPECIFIED) {
33 text += 'UNSPECIFIED ';
34 }
35 else if (mode === EXACTLY) {
36 text += 'EXACTLY ';
37 }
38 else if (mode === AT_MOST) {
39 text += 'AT_MOST ';
40 }
41 text += size;
42 return text;
43}
44export function round(value) {
45 const res = Math.floor(value + 0.5);
46 if (res !== 0) {
47 return res;
48 }
49 else if (value === 0) {
50 return 0;
51 }
52 else if (value > 0) {
53 return 1;
54 }
55 return -1;
56}
57//# sourceMappingURL=layout-helper-common.js.map
\No newline at end of file