@getcortexlabs/mavis 0.1.0-alpha.2 → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +3 -3
  2. package/dist/native/box.ios.d.ts +4 -0
  3. package/dist/native/box.ios.d.ts.map +1 -1
  4. package/dist/native/box.ios.js +13 -0
  5. package/dist/native/box.ios.js.map +1 -1
  6. package/dist/native/button.ios.d.ts +4 -0
  7. package/dist/native/button.ios.d.ts.map +1 -1
  8. package/dist/native/button.ios.js +12 -0
  9. package/dist/native/button.ios.js.map +1 -1
  10. package/dist/native/flex-layout.ios.d.ts +5 -0
  11. package/dist/native/flex-layout.ios.d.ts.map +1 -1
  12. package/dist/native/flex-layout.ios.js +24 -0
  13. package/dist/native/flex-layout.ios.js.map +1 -1
  14. package/dist/native/keyboard-dismiss.android.d.ts +8 -0
  15. package/dist/native/keyboard-dismiss.android.d.ts.map +1 -0
  16. package/dist/native/keyboard-dismiss.android.js +9 -0
  17. package/dist/native/keyboard-dismiss.android.js.map +1 -0
  18. package/dist/native/keyboard-dismiss.d.ts +10 -0
  19. package/dist/native/keyboard-dismiss.d.ts.map +1 -0
  20. package/dist/native/keyboard-dismiss.ios.d.ts +8 -0
  21. package/dist/native/keyboard-dismiss.ios.d.ts.map +1 -0
  22. package/dist/native/keyboard-dismiss.ios.js +88 -0
  23. package/dist/native/keyboard-dismiss.ios.js.map +1 -0
  24. package/dist/native/keyboard-dismiss.js +6 -0
  25. package/dist/native/keyboard-dismiss.js.map +1 -0
  26. package/dist/native/label.ios.d.ts +4 -0
  27. package/dist/native/label.ios.d.ts.map +1 -1
  28. package/dist/native/label.ios.js +12 -0
  29. package/dist/native/label.ios.js.map +1 -1
  30. package/dist/native/measure-memo.d.ts +37 -0
  31. package/dist/native/measure-memo.d.ts.map +1 -0
  32. package/dist/native/measure-memo.js +82 -0
  33. package/dist/native/measure-memo.js.map +1 -0
  34. package/dist/native/screen.android.d.ts +6 -0
  35. package/dist/native/screen.android.d.ts.map +1 -0
  36. package/dist/native/screen.android.js +8 -0
  37. package/dist/native/screen.android.js.map +1 -0
  38. package/dist/native/screen.d.ts +2 -0
  39. package/dist/native/screen.d.ts.map +1 -0
  40. package/dist/native/screen.js +3 -0
  41. package/dist/native/screen.js.map +1 -0
  42. package/dist/native/sheet.android.d.ts +14 -0
  43. package/dist/native/sheet.android.d.ts.map +1 -0
  44. package/dist/native/sheet.android.js +16 -0
  45. package/dist/native/sheet.android.js.map +1 -0
  46. package/dist/native/sheet.d.ts +17 -0
  47. package/dist/native/sheet.d.ts.map +1 -0
  48. package/dist/native/sheet.ios.d.ts +15 -0
  49. package/dist/native/sheet.ios.d.ts.map +1 -0
  50. package/dist/native/sheet.ios.js +32 -0
  51. package/dist/native/sheet.ios.js.map +1 -0
  52. package/dist/native/sheet.js +17 -0
  53. package/dist/native/sheet.js.map +1 -0
  54. package/dist/vue/components/MButton.d.ts +2 -2
  55. package/dist/vue/components/MCard.d.ts +2 -2
  56. package/dist/vue/components/MInput.d.ts +3 -3
  57. package/dist/vue/components/MReveal.d.ts +2 -2
  58. package/dist/vue/components/MScreen.d.ts +9 -0
  59. package/dist/vue/components/MScreen.d.ts.map +1 -1
  60. package/dist/vue/components/MScreen.js +53 -5
  61. package/dist/vue/components/MScreen.js.map +1 -1
  62. package/dist/vue/components/MSheet.d.ts +95 -0
  63. package/dist/vue/components/MSheet.d.ts.map +1 -0
  64. package/dist/vue/components/MSheet.js +281 -0
  65. package/dist/vue/components/MSheet.js.map +1 -0
  66. package/dist/vue/components/MText.d.ts +1 -1
  67. package/dist/vue/components/layout.d.ts +6 -6
  68. package/dist/vue/index.d.ts +8 -2
  69. package/dist/vue/index.d.ts.map +1 -1
  70. package/dist/vue/index.js +7 -2
  71. package/dist/vue/index.js.map +1 -1
  72. package/dist/vue/layers.d.ts +17 -0
  73. package/dist/vue/layers.d.ts.map +1 -0
  74. package/dist/vue/layers.js +26 -0
  75. package/dist/vue/layers.js.map +1 -0
  76. package/dist/vue/native-view.d.ts +6 -0
  77. package/dist/vue/native-view.d.ts.map +1 -0
  78. package/dist/vue/native-view.js +5 -0
  79. package/dist/vue/native-view.js.map +1 -0
  80. package/dist/vue/props.d.ts +12 -11
  81. package/dist/vue/props.d.ts.map +1 -1
  82. package/dist/vue/props.js +25 -10
  83. package/dist/vue/props.js.map +1 -1
  84. package/dist/vue/system-back.d.ts +11 -0
  85. package/dist/vue/system-back.d.ts.map +1 -0
  86. package/dist/vue/system-back.js +2 -0
  87. package/dist/vue/system-back.js.map +1 -0
  88. package/package.json +2 -2
  89. package/platforms/android/java/com/mavis/ui/Box.java +36 -3
  90. package/platforms/android/java/com/mavis/ui/FlexLayout.java +76 -4
  91. package/platforms/android/java/com/mavis/ui/MeasureMemo.java +145 -0
  92. package/platforms/android/java/com/mavis/ui/Screen.java +108 -0
  93. package/src/native/box.ios.ts +27 -0
  94. package/src/native/button.ios.ts +14 -0
  95. package/src/native/flex-layout.ios.ts +41 -0
  96. package/src/native/keyboard-dismiss.android.ts +17 -0
  97. package/src/native/keyboard-dismiss.ios.ts +122 -0
  98. package/src/native/keyboard-dismiss.ts +14 -0
  99. package/src/native/label.ios.ts +14 -0
  100. package/src/native/measure-memo.ts +116 -0
  101. package/src/native/screen.android.ts +12 -0
  102. package/src/native/screen.ts +2 -0
  103. package/src/native/sheet.android.ts +24 -0
  104. package/src/native/sheet.ios.ts +43 -0
  105. package/src/native/sheet.ts +26 -0
  106. package/src/vue/components/MScreen.ts +78 -5
  107. package/src/vue/components/MSheet.ts +335 -0
  108. package/src/vue/index.ts +26 -3
  109. package/src/vue/layers.ts +46 -0
  110. package/src/vue/native-view.ts +6 -0
  111. package/src/vue/props.ts +37 -12
  112. package/src/vue/system-back.ts +12 -0
@@ -0,0 +1,26 @@
1
+ import { inject, provide, shallowReactive, } from 'nativescript-vue';
2
+ const layerHost = Symbol('mavis.layers');
3
+ /** A Screen renders registered layers above its content, inside one native cell. */
4
+ export function provideLayerHost() {
5
+ const layers = shallowReactive([]);
6
+ let next = 0;
7
+ provide(layerHost, {
8
+ add(layer) {
9
+ const entry = { ...layer, key: next++ };
10
+ layers.push(entry);
11
+ return () => {
12
+ const index = layers.indexOf(entry);
13
+ if (index >= 0)
14
+ layers.splice(index, 1);
15
+ };
16
+ },
17
+ });
18
+ return layers;
19
+ }
20
+ export function useLayerHost(name) {
21
+ const host = inject(layerHost, undefined);
22
+ if (!host)
23
+ throw new Error(`${name} needs an MScreen ancestor on NativeScript`);
24
+ return host;
25
+ }
26
+ //# sourceMappingURL=layers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layers.js","sourceRoot":"","sources":["../../src/vue/layers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,OAAO,EACP,eAAe,GAIhB,MAAM,kBAAkB,CAAA;AAezB,MAAM,SAAS,GAA4B,MAAM,CAAC,cAAc,CAAC,CAAA;AAEjE,oFAAoF;AACpF,MAAM,UAAU,gBAAgB;IAC9B,MAAM,MAAM,GAAG,eAAe,CAAe,EAAE,CAAC,CAAA;IAChD,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,OAAO,CAAC,SAAS,EAAE;QACjB,GAAG,CAAC,KAAK;YACP,MAAM,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAA;YACvC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAClB,OAAO,GAAG,EAAE;gBACV,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;gBACnC,IAAI,KAAK,IAAI,CAAC;oBAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;YACzC,CAAC,CAAA;QACH,CAAC;KACF,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IACzC,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,4CAA4C,CAAC,CAAA;IAC/E,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { View } from '@nativescript/core';
2
+ /** Template refs on native elements wrap the NativeScript view. */
3
+ export declare function nativeViewOf<T extends View>(element: {
4
+ nativeView: T;
5
+ } | undefined): T | undefined;
6
+ //# sourceMappingURL=native-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-view.d.ts","sourceRoot":"","sources":["../../src/vue/native-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AAE9C,mEAAmE;AACnE,wBAAgB,YAAY,CAAC,CAAC,SAAS,IAAI,EAAE,OAAO,EAAE;IAAE,UAAU,EAAE,CAAC,CAAA;CAAE,GAAG,SAAS,iBAElF"}
@@ -0,0 +1,5 @@
1
+ /** Template refs on native elements wrap the NativeScript view. */
2
+ export function nativeViewOf(element) {
3
+ return element?.nativeView;
4
+ }
5
+ //# sourceMappingURL=native-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-view.js","sourceRoot":"","sources":["../../src/vue/native-view.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,MAAM,UAAU,YAAY,CAAiB,OAAsC;IACjF,OAAO,OAAO,EAAE,UAAU,CAAA;AAC5B,CAAC"}
@@ -1,17 +1,18 @@
1
- import type { MavisTheme } from '@getcortexlabs/mavis-core';
1
+ import type { Dimension, MavisTheme } from '@getcortexlabs/mavis-core';
2
2
  import type { BoxProps } from '@getcortexlabs/mavis-core/vue';
3
3
  export { boxProps, spacingProp } from '@getcortexlabs/mavis-core/vue';
4
- export declare function boxStyle(theme: MavisTheme, props: BoxProps, defaultShrink?: number): {
5
- paddingLeft: number;
6
- paddingRight: number;
7
- paddingTop: number;
8
- paddingBottom: number;
9
- borderRadius: number;
4
+ export interface BoxStyle {
5
+ paddingLeft?: number;
6
+ paddingRight?: number;
7
+ paddingTop?: number;
8
+ paddingBottom?: number;
9
+ borderRadius?: number;
10
10
  flexGrow: number;
11
11
  flexShrink: number;
12
12
  minWidth: number;
13
- width: import("@getcortexlabs/mavis-core").Dimension | undefined;
14
- height: import("@getcortexlabs/mavis-core").Dimension | undefined;
15
- backgroundColor: string | undefined;
16
- };
13
+ width?: Dimension;
14
+ height?: Dimension;
15
+ backgroundColor?: string;
16
+ }
17
+ export declare function boxStyle(theme: MavisTheme, props: BoxProps, defaultShrink?: number): BoxStyle;
17
18
  //# sourceMappingURL=props.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/vue/props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAO3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAErE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,SAAI;;;;;;;;;;;;EAe7E"}
1
+ {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/vue/props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAOtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAErE,MAAM,WAAW,QAAQ;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAID,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,SAAI,GAAG,QAAQ,CAwBxF"}
package/dist/vue/props.js CHANGED
@@ -1,19 +1,34 @@
1
1
  import { resolveSpace, resolveRadius, resolveDimension, nonNegative, } from '@getcortexlabs/mavis-core';
2
2
  export { boxProps, spacingProp } from '@getcortexlabs/mavis-core/vue';
3
+ // A prop that was not given leaves its style untouched, so a plain attribute such as
4
+ // `paddingTop` or `borderRadius` on the element survives every render.
3
5
  export function boxStyle(theme, props, defaultShrink = 0) {
4
- const padding = resolveSpace(theme, props.padding ?? 'none');
5
- return {
6
- paddingLeft: props.paddingX === undefined ? padding : resolveSpace(theme, props.paddingX),
7
- paddingRight: props.paddingX === undefined ? padding : resolveSpace(theme, props.paddingX),
8
- paddingTop: props.paddingY === undefined ? padding : resolveSpace(theme, props.paddingY),
9
- paddingBottom: props.paddingY === undefined ? padding : resolveSpace(theme, props.paddingY),
10
- borderRadius: resolveRadius(theme, props.radius),
6
+ const style = {
11
7
  flexGrow: nonNegative(props.grow, 'grow'),
12
8
  flexShrink: nonNegative(props.shrink ?? defaultShrink, 'shrink'),
13
9
  minWidth: 0,
14
- width: resolveDimension(props.width),
15
- height: resolveDimension(props.height),
16
- backgroundColor: props.backgroundColor,
17
10
  };
11
+ const padding = props.padding === undefined ? undefined : resolveSpace(theme, props.padding);
12
+ const x = props.paddingX === undefined ? padding : resolveSpace(theme, props.paddingX);
13
+ const y = props.paddingY === undefined ? padding : resolveSpace(theme, props.paddingY);
14
+ if (x !== undefined) {
15
+ style.paddingLeft = x;
16
+ style.paddingRight = x;
17
+ }
18
+ if (y !== undefined) {
19
+ style.paddingTop = y;
20
+ style.paddingBottom = y;
21
+ }
22
+ if (props.radius !== undefined)
23
+ style.borderRadius = resolveRadius(theme, props.radius);
24
+ const width = resolveDimension(props.width);
25
+ if (width !== undefined)
26
+ style.width = width;
27
+ const height = resolveDimension(props.height);
28
+ if (height !== undefined)
29
+ style.height = height;
30
+ if (props.backgroundColor !== undefined)
31
+ style.backgroundColor = props.backgroundColor;
32
+ return style;
18
33
  }
19
34
  //# sourceMappingURL=props.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"props.js","sourceRoot":"","sources":["../../src/vue/props.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,WAAW,GACZ,MAAM,2BAA2B,CAAA;AAElC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAErE,MAAM,UAAU,QAAQ,CAAC,KAAiB,EAAE,KAAe,EAAE,aAAa,GAAG,CAAC;IAC5E,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,CAAA;IAC5D,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC;QACzF,YAAY,EAAE,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC;QAC1F,UAAU,EAAE,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC;QACxF,aAAa,EAAE,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC;QAC3F,YAAY,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC;QAChD,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;QACzC,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,MAAM,IAAI,aAAa,EAAE,QAAQ,CAAC;QAChE,QAAQ,EAAE,CAAC;QACX,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC;QACpC,MAAM,EAAE,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC;QACtC,eAAe,EAAE,KAAK,CAAC,eAAe;KACvC,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"props.js","sourceRoot":"","sources":["../../src/vue/props.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,WAAW,GACZ,MAAM,2BAA2B,CAAA;AAElC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAgBrE,qFAAqF;AACrF,uEAAuE;AACvE,MAAM,UAAU,QAAQ,CAAC,KAAiB,EAAE,KAAe,EAAE,aAAa,GAAG,CAAC;IAC5E,MAAM,KAAK,GAAa;QACtB,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;QACzC,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,MAAM,IAAI,aAAa,EAAE,QAAQ,CAAC;QAChE,QAAQ,EAAE,CAAC;KACZ,CAAA;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5F,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;IACtF,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;IACtF,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,KAAK,CAAC,WAAW,GAAG,CAAC,CAAA;QACrB,KAAK,CAAC,YAAY,GAAG,CAAC,CAAA;IACxB,CAAC;IACD,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,KAAK,CAAC,UAAU,GAAG,CAAC,CAAA;QACpB,KAAK,CAAC,aAAa,GAAG,CAAC,CAAA;IACzB,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;QAAE,KAAK,CAAC,YAAY,GAAG,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACvF,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC3C,IAAI,KAAK,KAAK,SAAS;QAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAAA;IAC5C,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC7C,IAAI,MAAM,KAAK,SAAS;QAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAA;IAC/C,IAAI,KAAK,CAAC,eAAe,KAAK,SAAS;QAAE,KAAK,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,CAAA;IACtF,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { InjectionKey } from 'nativescript-vue';
2
+ /** Something other than a page that the Android system back should reach first. */
3
+ export interface SystemBackClaimant {
4
+ /** Whether it wants the next back press or gesture. */
5
+ owns(): boolean;
6
+ /** Takes the press. */
7
+ back(): void;
8
+ }
9
+ export type ClaimSystemBack = (claimant: SystemBackClaimant) => () => void;
10
+ export declare const systemBackKey: InjectionKey<ClaimSystemBack | undefined>;
11
+ //# sourceMappingURL=system-back.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-back.d.ts","sourceRoot":"","sources":["../../src/vue/system-back.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,mFAAmF;AACnF,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,IAAI,IAAI,OAAO,CAAA;IACf,uBAAuB;IACvB,IAAI,IAAI,IAAI,CAAA;CACb;AACD,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,kBAAkB,KAAK,MAAM,IAAI,CAAA;AAE1E,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,eAAe,GAAG,SAAS,CAA8B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export const systemBackKey = Symbol('mavis.systemBack');
2
+ //# sourceMappingURL=system-back.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-back.js","sourceRoot":"","sources":["../../src/vue/system-back.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,aAAa,GAA8C,MAAM,CAAC,kBAAkB,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getcortexlabs/mavis",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "Mavis UI foundations for NativeScript, with a Vue integration.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -37,7 +37,7 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
- "@getcortexlabs/mavis-core": "0.1.0-alpha.2"
40
+ "@getcortexlabs/mavis-core": "0.1.0-alpha.3"
41
41
  },
42
42
  "nativescript": {
43
43
  "platforms": {
@@ -6,17 +6,50 @@ import org.nativescript.widgets.CommonLayoutParams;
6
6
  import org.nativescript.widgets.GridLayout;
7
7
 
8
8
  /** An auto-height Box takes its content height when the parent only limits the available space. */
9
- public class Box extends GridLayout {
9
+ public class Box extends GridLayout implements MeasureMemo.Owner {
10
+ private final MeasureMemo memo = new MeasureMemo();
11
+
10
12
  public Box(Context context) {
11
13
  super(context);
12
14
  }
13
15
 
16
+ @Override
17
+ public int memoWidthSpec() {
18
+ return memo.receivedWidthSpec();
19
+ }
20
+
21
+ @Override
22
+ public int memoHeightSpec() {
23
+ return memo.receivedHeightSpec();
24
+ }
25
+
26
+ // Android's view constructors already request layout, before this field exists.
27
+ @Override
28
+ public void requestLayout() {
29
+ if (memo != null) memo.invalidate();
30
+ super.requestLayout();
31
+ }
32
+
33
+ @Override
34
+ public void forceLayout() {
35
+ if (memo != null) memo.invalidate();
36
+ super.forceLayout();
37
+ }
38
+
14
39
  @Override
15
40
  protected void onMeasure(int widthSpec, int heightSpec) {
41
+ memo.receive(widthSpec, heightSpec);
42
+ if (memo.restore(this, widthSpec, heightSpec)) {
43
+ setMeasuredDimension(memo.widthAndState(), memo.heightAndState());
44
+ return;
45
+ }
46
+ int contentHeightSpec = heightSpec;
16
47
  if (MeasureSpec.getMode(heightSpec) == MeasureSpec.AT_MOST && isAutoHeight()) {
17
- heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
48
+ contentHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
18
49
  }
19
- super.onMeasure(widthSpec, heightSpec);
50
+ super.onMeasure(widthSpec, contentHeightSpec);
51
+ memo.record(this, widthSpec, heightSpec,
52
+ MeasureMemo.filledLimit(widthSpec, heightSpec, getMeasuredWidthAndState(), getMeasuredHeightAndState()));
20
53
  }
21
54
 
22
55
  private boolean isAutoHeight() {
@@ -2,23 +2,95 @@ package com.mavis.ui;
2
2
 
3
3
  import android.content.Context;
4
4
  import android.view.View;
5
+ import android.view.View.MeasureSpec;
5
6
  import org.nativescript.widgets.FlexboxLayout;
6
7
 
7
8
  /** Keeps the cross-axis measurement in sync with the final width of flexible children. */
8
- public class FlexLayout extends FlexboxLayout {
9
+ public class FlexLayout extends FlexboxLayout implements MeasureMemo.Owner {
10
+ private final MeasureMemo memo = new MeasureMemo();
11
+
9
12
  public FlexLayout(Context context) {
10
13
  super(context);
11
14
  }
12
15
 
16
+ @Override
17
+ public int memoWidthSpec() {
18
+ return memo.receivedWidthSpec();
19
+ }
20
+
21
+ @Override
22
+ public int memoHeightSpec() {
23
+ return memo.receivedHeightSpec();
24
+ }
25
+
26
+ // Android's view constructors already request layout, before this field exists.
27
+ @Override
28
+ public void requestLayout() {
29
+ if (memo != null) memo.invalidate();
30
+ super.requestLayout();
31
+ }
32
+
33
+ @Override
34
+ public void forceLayout() {
35
+ if (memo != null) memo.invalidate();
36
+ super.forceLayout();
37
+ }
38
+
13
39
  @Override
14
40
  protected void onMeasure(int widthSpec, int heightSpec) {
41
+ memo.receive(widthSpec, heightSpec);
42
+ if (memo.restore(this, widthSpec, heightSpec)) {
43
+ setMeasuredDimension(memo.widthAndState(), memo.heightAndState());
44
+ return;
45
+ }
46
+ measureContent(widthSpec, heightSpec);
47
+ memo.record(this, widthSpec, heightSpec, contentExceeds(widthSpec, heightSpec));
48
+ }
49
+
50
+ // Core measures a looser request without shrinking, so the children's sizes tell whether the
51
+ // content wanted more room than the request allowed. Wrapping lines are not summed here.
52
+ private boolean contentExceeds(int widthSpec, int heightSpec) {
53
+ if (getFlexWrap() != FLEX_WRAP_NOWRAP) {
54
+ return MeasureSpec.getMode(widthSpec) == MeasureSpec.AT_MOST
55
+ || MeasureSpec.getMode(heightSpec) == MeasureSpec.AT_MOST;
56
+ }
57
+ boolean horizontal = getFlexDirection() == FLEX_DIRECTION_ROW
58
+ || getFlexDirection() == FLEX_DIRECTION_ROW_REVERSE;
59
+ int main = 0;
60
+ int cross = 0;
61
+ int visible = 0;
62
+ for (int i = 0, count = getChildCount(); i < count; i++) {
63
+ View child = getChildAt(i);
64
+ if (child.getVisibility() == View.GONE) continue;
65
+ LayoutParams params = (LayoutParams) child.getLayoutParams();
66
+ int width = child.getMeasuredWidth() + params.leftMargin + params.rightMargin;
67
+ int height = child.getMeasuredHeight() + params.topMargin + params.bottomMargin;
68
+ main += horizontal ? width : height;
69
+ cross = Math.max(cross, horizontal ? height : width);
70
+ visible++;
71
+ }
72
+ main += (horizontal ? getColumnGap() : getRowGap()) * Math.max(0, visible - 1);
73
+ int contentWidth = (horizontal ? main : cross) + getPaddingLeft() + getPaddingRight();
74
+ int contentHeight = (horizontal ? cross : main) + getPaddingTop() + getPaddingBottom();
75
+ return exceeds(widthSpec, contentWidth) || exceeds(heightSpec, contentHeight);
76
+ }
77
+
78
+ private static boolean exceeds(int spec, int size) {
79
+ return MeasureSpec.getMode(spec) == MeasureSpec.AT_MOST && MeasureSpec.getSize(spec) < size;
80
+ }
81
+
82
+ private void measureContent(int widthSpec, int heightSpec) {
15
83
  boolean horizontal = getFlexDirection() == FLEX_DIRECTION_ROW
16
84
  || getFlexDirection() == FLEX_DIRECTION_ROW_REVERSE;
17
85
 
18
86
  int count = getChildCount();
19
87
  // Core restores percentage LayoutParams after layout. Android's measure cache can then
20
- // return a result from an earlier pass with different resolved LayoutParams.
21
- for (int i = 0; i < count; i++) getChildAt(i).forceLayout();
88
+ // return a result from an earlier pass with different resolved LayoutParams. Mavis
89
+ // layouts key their own memo on the specs, so only other views need the forced pass.
90
+ for (int i = 0; i < count; i++) {
91
+ View child = getChildAt(i);
92
+ if (!(child instanceof MeasureMemo.Owner)) child.forceLayout();
93
+ }
22
94
  super.onMeasure(widthSpec, heightSpec);
23
95
 
24
96
  int[] widths = new int[count];
@@ -40,7 +112,7 @@ public class FlexLayout extends FlexboxLayout {
40
112
  params.flexGrow = 0;
41
113
  params.flexShrink = 0;
42
114
  }
43
- child.forceLayout();
115
+ if (!(child instanceof MeasureMemo.Owner)) child.forceLayout();
44
116
  }
45
117
  try {
46
118
  // Core's growth pass fixes the old height even when the new width unwraps text.
@@ -0,0 +1,145 @@
1
+ package com.mavis.ui;
2
+
3
+ import android.view.View;
4
+ import android.view.View.MeasureSpec;
5
+ import android.view.ViewGroup;
6
+ import org.nativescript.widgets.CommonLayoutParams;
7
+
8
+ /**
9
+ * Remembers the last measurement of a layout while nothing in its subtree asked for layout.
10
+ *
11
+ * Android measures every view again whenever its parent asks while a layout request is pending,
12
+ * and flex containers ask several times per pass, so nested containers measure their leaves an
13
+ * exponential number of times. The memo answers a repeated request from the recorded result and
14
+ * measures again only the children that no longer hold that result.
15
+ */
16
+ final class MeasureMemo {
17
+ /** Layouts that own a memo report the specs their latest measurement received. */
18
+ interface Owner {
19
+ int memoWidthSpec();
20
+
21
+ int memoHeightSpec();
22
+ }
23
+
24
+ private boolean valid;
25
+ private boolean percentChildren;
26
+ private boolean clamped;
27
+ private int widthSpec;
28
+ private int heightSpec;
29
+ private int widthAndState;
30
+ private int heightAndState;
31
+ private int receivedWidthSpec;
32
+ private int receivedHeightSpec;
33
+ private int[] childWidthSpecs = new int[0];
34
+ private int[] childHeightSpecs = new int[0];
35
+ private int[] childWidths = new int[0];
36
+ private int[] childHeights = new int[0];
37
+
38
+ void invalidate() {
39
+ valid = false;
40
+ }
41
+
42
+ int receivedWidthSpec() {
43
+ return receivedWidthSpec;
44
+ }
45
+
46
+ int receivedHeightSpec() {
47
+ return receivedHeightSpec;
48
+ }
49
+
50
+ /** Records the specs of the measurement that is starting, memoized or not. */
51
+ void receive(int widthSpec, int heightSpec) {
52
+ receivedWidthSpec = widthSpec;
53
+ receivedHeightSpec = heightSpec;
54
+ }
55
+
56
+ /** True when the recorded measurement answers these specs; children that changed are measured again. */
57
+ boolean restore(ViewGroup owner, int widthSpec, int heightSpec) {
58
+ if (!valid) return false;
59
+ if (!matches(widthSpec, this.widthSpec, widthAndState)) return false;
60
+ if (!matches(heightSpec, this.heightSpec, heightAndState)) return false;
61
+ int count = owner.getChildCount();
62
+ if (count != childWidthSpecs.length) {
63
+ valid = false;
64
+ return false;
65
+ }
66
+ for (int i = 0; i < count; i++) {
67
+ View child = owner.getChildAt(i);
68
+ if (child.getVisibility() == View.GONE) continue;
69
+ // A child still holding the recorded result was measured by this record's pass.
70
+ if (child.getMeasuredWidthAndState() == childWidths[i]
71
+ && child.getMeasuredHeightAndState() == childHeights[i]) continue;
72
+ child.measure(childWidthSpecs[i], childHeightSpecs[i]);
73
+ }
74
+ return true;
75
+ }
76
+
77
+ int widthAndState() {
78
+ return widthAndState;
79
+ }
80
+
81
+ int heightAndState() {
82
+ return heightAndState;
83
+ }
84
+
85
+ /**
86
+ * Stores the measurement that just completed with the result and specs every child last
87
+ * received. A clamped looser request is never reused for an exact size, which would shrink
88
+ * the children; Android keeps the too-small state only for widths.
89
+ */
90
+ void record(ViewGroup owner, int widthSpec, int heightSpec, boolean clamped) {
91
+ this.widthSpec = widthSpec;
92
+ this.heightSpec = heightSpec;
93
+ this.clamped = clamped;
94
+ widthAndState = owner.getMeasuredWidthAndState();
95
+ heightAndState = owner.getMeasuredHeightAndState();
96
+ int count = owner.getChildCount();
97
+ if (childWidthSpecs.length != count) {
98
+ childWidthSpecs = new int[count];
99
+ childHeightSpecs = new int[count];
100
+ childWidths = new int[count];
101
+ childHeights = new int[count];
102
+ }
103
+ percentChildren = false;
104
+ for (int i = 0; i < count; i++) {
105
+ View child = owner.getChildAt(i);
106
+ ViewGroup.LayoutParams params = child.getLayoutParams();
107
+ if (params instanceof CommonLayoutParams) {
108
+ CommonLayoutParams common = (CommonLayoutParams) params;
109
+ if (common.widthPercent > 0 || common.heightPercent > 0) percentChildren = true;
110
+ }
111
+ childWidths[i] = child.getMeasuredWidthAndState();
112
+ childHeights[i] = child.getMeasuredHeightAndState();
113
+ if (child instanceof Owner) {
114
+ childWidthSpecs[i] = ((Owner) child).memoWidthSpec();
115
+ childHeightSpecs[i] = ((Owner) child).memoHeightSpec();
116
+ } else {
117
+ childWidthSpecs[i] = MeasureSpec.makeMeasureSpec(child.getMeasuredWidth(), MeasureSpec.EXACTLY);
118
+ childHeightSpecs[i] = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(), MeasureSpec.EXACTLY);
119
+ }
120
+ }
121
+ valid = true;
122
+ }
123
+
124
+ /** Whether a looser request on either axis returned its whole limit; for layouts that cannot tell. */
125
+ static boolean filledLimit(int widthSpec, int heightSpec, int widthAndState, int heightAndState) {
126
+ return filled(widthSpec, widthAndState) || filled(heightSpec, heightAndState);
127
+ }
128
+
129
+ private static boolean filled(int spec, int sizeAndState) {
130
+ return MeasureSpec.getMode(spec) == MeasureSpec.AT_MOST
131
+ && (sizeAndState & View.MEASURED_SIZE_MASK) >= MeasureSpec.getSize(spec);
132
+ }
133
+
134
+ // An exact request for the size a looser request produced is the same measurement, unless a
135
+ // child resolves a percentage against the request itself or the looser request clamped content
136
+ // that wanted more room: an exact size would then shrink the children instead.
137
+ private boolean matches(int spec, int recordedSpec, int recordedSizeAndState) {
138
+ if (spec == recordedSpec) return true;
139
+ if (percentChildren || clamped) return false;
140
+ if (MeasureSpec.getMode(spec) != MeasureSpec.EXACTLY) return false;
141
+ if (MeasureSpec.getMode(recordedSpec) == MeasureSpec.EXACTLY) return false;
142
+ if ((recordedSizeAndState & View.MEASURED_STATE_TOO_SMALL) != 0) return false;
143
+ return MeasureSpec.getSize(spec) == (recordedSizeAndState & View.MEASURED_SIZE_MASK);
144
+ }
145
+ }
@@ -0,0 +1,108 @@
1
+ package com.mavis.ui;
2
+
3
+ import android.content.Context;
4
+ import android.view.MotionEvent;
5
+ import android.view.View;
6
+ import android.view.ViewConfiguration;
7
+ import android.view.ViewGroup;
8
+ import android.view.inputmethod.InputMethodManager;
9
+ import android.widget.EditText;
10
+ import org.nativescript.widgets.GridLayout;
11
+
12
+ /** The page container: puts the soft keyboard away on a tap outside the editor or on a drag. */
13
+ public class Screen extends GridLayout {
14
+ private final int slop;
15
+ private boolean dismissOnTap;
16
+ private boolean dismissOnDrag;
17
+ private boolean tracking;
18
+ private View editing;
19
+ private float downX;
20
+ private float downY;
21
+
22
+ public Screen(Context context) {
23
+ super(context);
24
+ slop = ViewConfiguration.get(context).getScaledTouchSlop();
25
+ }
26
+
27
+ public void setKeyboardDismissal(boolean onTap, boolean onDrag) {
28
+ dismissOnTap = onTap;
29
+ dismissOnDrag = onDrag;
30
+ if (!onTap && !onDrag) tracking = false;
31
+ }
32
+
33
+ // Every touch of the page passes here, so a tap on a button or a drag that the scroll view
34
+ // takes over still counts. The event itself is never consumed. Clicks run from the queue
35
+ // after the up event, so the tap waits its turn: a control that focused another editor
36
+ // meanwhile keeps that focus.
37
+ @Override
38
+ public boolean dispatchTouchEvent(MotionEvent event) {
39
+ switch (event.getActionMasked()) {
40
+ case MotionEvent.ACTION_DOWN:
41
+ downX = event.getRawX();
42
+ downY = event.getRawY();
43
+ editing = findFocus();
44
+ tracking = (dismissOnTap || dismissOnDrag)
45
+ && editing instanceof EditText
46
+ && !touchesEditor(this, downX, downY);
47
+ break;
48
+ case MotionEvent.ACTION_MOVE:
49
+ // Like the interactive mode on iOS, only a drag towards the keyboard puts it
50
+ // away; dragging the other way still scrolls the form while typing.
51
+ if (tracking && dismissOnDrag && event.getRawY() - downY > slop) {
52
+ tracking = false;
53
+ dismiss();
54
+ } else if (tracking && moved(event)) {
55
+ tracking = false;
56
+ }
57
+ break;
58
+ case MotionEvent.ACTION_UP:
59
+ if (tracking && dismissOnTap && !moved(event)) {
60
+ final View before = editing;
61
+ post(() -> {
62
+ if (findFocus() == before) dismiss();
63
+ });
64
+ }
65
+ tracking = false;
66
+ break;
67
+ case MotionEvent.ACTION_CANCEL:
68
+ tracking = false;
69
+ break;
70
+ default:
71
+ break;
72
+ }
73
+ return super.dispatchTouchEvent(event);
74
+ }
75
+
76
+ private boolean moved(MotionEvent event) {
77
+ return Math.abs(event.getRawX() - downX) > slop || Math.abs(event.getRawY() - downY) > slop;
78
+ }
79
+
80
+ // A touch that starts on any editor keeps the keyboard: it focuses that editor or edits it.
81
+ private static boolean touchesEditor(View view, float x, float y) {
82
+ if (view.getVisibility() != View.VISIBLE) return false;
83
+ if (view instanceof EditText) {
84
+ int[] origin = new int[2];
85
+ view.getLocationOnScreen(origin);
86
+ return x >= origin[0] && x <= origin[0] + view.getWidth()
87
+ && y >= origin[1] && y <= origin[1] + view.getHeight();
88
+ }
89
+ if (view instanceof ViewGroup) {
90
+ ViewGroup group = (ViewGroup) view;
91
+ for (int i = 0, count = group.getChildCount(); i < count; i++) {
92
+ if (touchesEditor(group.getChildAt(i), x, y)) return true;
93
+ }
94
+ }
95
+ return false;
96
+ }
97
+
98
+ // Clearing the focus makes Core report blur and hide the keyboard; hiding it here as well
99
+ // covers editors that are not Core views.
100
+ private void dismiss() {
101
+ View focused = findFocus();
102
+ if (!(focused instanceof EditText)) return;
103
+ InputMethodManager manager =
104
+ (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
105
+ if (manager != null) manager.hideSoftInputFromWindow(focused.getWindowToken(), 0);
106
+ focused.clearFocus();
107
+ }
108
+ }
@@ -1,9 +1,36 @@
1
1
  import { GridLayout, Utils } from '@nativescript/core'
2
+ import {
3
+ filledLimit,
4
+ layoutChildren,
5
+ recordMeasurement,
6
+ reuseMeasurement,
7
+ type MeasureRecord,
8
+ } from './measure-memo'
2
9
 
3
10
  const { layout } = Utils
4
11
 
5
12
  /** An auto-height Box takes its content height when the parent only limits the available space. */
6
13
  export class MavisBox extends GridLayout {
14
+ measureRecord?: MeasureRecord
15
+
16
+ measure(widthSpec: number, heightSpec: number) {
17
+ if (reuseMeasurement(this, widthSpec, heightSpec)) return
18
+ super.measure(widthSpec, heightSpec)
19
+ const measured = this as unknown as { _measuredWidth: number; _measuredHeight: number }
20
+ recordMeasurement(
21
+ this,
22
+ widthSpec,
23
+ heightSpec,
24
+ layoutChildren(this),
25
+ filledLimit(widthSpec, heightSpec, measured._measuredWidth, measured._measuredHeight),
26
+ )
27
+ }
28
+
29
+ requestLayout() {
30
+ this.measureRecord = undefined
31
+ super.requestLayout()
32
+ }
33
+
7
34
  onMeasure(widthSpec: number, heightSpec: number) {
8
35
  const relaxed =
9
36
  this.effectiveHeight < 0 && layout.getMeasureSpecMode(heightSpec) === layout.AT_MOST
@@ -1,6 +1,20 @@
1
1
  import { Button } from '@nativescript/core'
2
+ import { recordMeasurement, reuseMeasurement, type MeasureRecord } from './measure-memo'
2
3
 
3
4
  export class MavisButton extends Button {
5
+ measureRecord?: MeasureRecord
6
+
7
+ measure(widthSpec: number, heightSpec: number) {
8
+ if (reuseMeasurement(this, widthSpec, heightSpec)) return
9
+ super.measure(widthSpec, heightSpec)
10
+ recordMeasurement(this, widthSpec, heightSpec)
11
+ }
12
+
13
+ requestLayout() {
14
+ this.measureRecord = undefined
15
+ super.requestLayout()
16
+ }
17
+
4
18
  onMeasure(widthSpec: number, heightSpec: number) {
5
19
  const button = this.ios
6
20
  // UIButton updates titleLabel during its layout pass. Wrapped measurement needs the