@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
@@ -1,5 +1,11 @@
1
1
  import { FlexboxLayout, Utils, type View } from '@nativescript/core'
2
2
  import { applyColumnShrink } from './flex-children'
3
+ import {
4
+ layoutChildren,
5
+ recordMeasurement,
6
+ reuseMeasurement,
7
+ type MeasureRecord,
8
+ } from './measure-memo'
3
9
 
4
10
  // Core 9.1.3 computes row heights before growing children. This adapter runs after width
5
11
  // allocation and before cross-axis alignment; no global prototype or consumer styles change.
@@ -12,6 +18,8 @@ interface FlexMeasurement {
12
18
  _gapLengthInMainSize: number
13
19
  }[]
14
20
  _getReorderedChildAt(index: number): View
21
+ _getLargestMainSize(): number
22
+ _getSumOfCrossSize(): number
15
23
  effectiveRowGap: number
16
24
  }
17
25
 
@@ -19,6 +27,39 @@ const { layout } = Utils
19
27
  const base = FlexboxLayout.prototype as unknown as FlexMeasurement
20
28
 
21
29
  export class MavisFlexLayout extends FlexboxLayout {
30
+ measureRecord?: MeasureRecord
31
+
32
+ measure(widthSpec: number, heightSpec: number) {
33
+ if (reuseMeasurement(this, widthSpec, heightSpec)) return
34
+ super.measure(widthSpec, heightSpec)
35
+ recordMeasurement(
36
+ this,
37
+ widthSpec,
38
+ heightSpec,
39
+ layoutChildren(this),
40
+ this.contentExceeds(widthSpec, heightSpec),
41
+ )
42
+ }
43
+
44
+ // Core measures a looser request without shrinking, so its lines tell whether the content
45
+ // wanted more room than the request allowed.
46
+ private contentExceeds(widthSpec: number, heightSpec: number) {
47
+ const measurement = this as unknown as FlexMeasurement
48
+ const column = this.flexDirection.startsWith('column')
49
+ const main = measurement._getLargestMainSize()
50
+ const cross = measurement._getSumOfCrossSize()
51
+ const maxHeight = column ? main : cross + this.effectivePaddingTop + this.effectivePaddingBottom
52
+ const maxWidth = column ? cross + this.effectivePaddingLeft + this.effectivePaddingRight : main
53
+ const exceeds = (spec: number, size: number) =>
54
+ layout.getMeasureSpecMode(spec) === layout.AT_MOST && layout.getMeasureSpecSize(spec) < size
55
+ return exceeds(heightSpec, maxHeight) || exceeds(widthSpec, maxWidth)
56
+ }
57
+
58
+ requestLayout() {
59
+ this.measureRecord = undefined
60
+ super.requestLayout()
61
+ }
62
+
22
63
  _registerLayoutChild(child: View) {
23
64
  super._registerLayoutChild(child)
24
65
  applyColumnShrink(this, child)
@@ -0,0 +1,17 @@
1
+ import type { View } from '@nativescript/core'
2
+
3
+ export interface KeyboardDismissal {
4
+ tap: boolean
5
+ drag: boolean
6
+ }
7
+ interface ScreenView {
8
+ setKeyboardDismissal(onTap: boolean, onDrag: boolean): void
9
+ }
10
+
11
+ /** The container is a `com.mavis.ui.Screen`, which watches every touch of the page. */
12
+ export function dismissKeyboardOn(container: View, options: KeyboardDismissal): () => void {
13
+ const screen = container.android as Partial<ScreenView> | undefined
14
+ if (!screen?.setKeyboardDismissal) return () => {}
15
+ screen.setKeyboardDismissal(options.tap, options.drag)
16
+ return () => screen.setKeyboardDismissal?.(false, false)
17
+ }
@@ -0,0 +1,122 @@
1
+ import { ScrollView, type View } from '@nativescript/core'
2
+
3
+ export interface KeyboardDismissal {
4
+ tap: boolean
5
+ drag: boolean
6
+ }
7
+ interface NativeView {
8
+ superview: NativeView | null
9
+ subviews: { count: number; objectAtIndex(index: number): NativeView }
10
+ isFirstResponder: boolean
11
+ isEqual(other: NativeView): boolean
12
+ endEditing(force: boolean): boolean
13
+ addGestureRecognizer(recognizer: Recognizer): void
14
+ removeGestureRecognizer(recognizer: Recognizer): void
15
+ }
16
+ interface Recognizer {
17
+ view: NativeView
18
+ delegate: unknown
19
+ cancelsTouchesInView: boolean
20
+ delaysTouchesEnded: boolean
21
+ }
22
+ interface NativeClass {
23
+ extend(members: object, options: object): { new (): object }
24
+ }
25
+ declare const NSObject: NativeClass
26
+ declare const UITapGestureRecognizer: {
27
+ alloc(): { initWithTargetAction(target: object, action: string): Recognizer }
28
+ }
29
+ declare const UIGestureRecognizerDelegate: unknown
30
+ declare const UITextField: unknown
31
+ declare const UITextView: unknown
32
+ declare const UIGestureRecognizer: unknown
33
+ declare const interop: { types: { void: unknown } }
34
+
35
+ const editor = (view: NativeView | null) => {
36
+ for (let current = view; current; current = current.superview) {
37
+ if (current instanceof (UITextField as never) || current instanceof (UITextView as never))
38
+ return true
39
+ }
40
+ return false
41
+ }
42
+
43
+ const firstResponder = (view: NativeView): NativeView | null => {
44
+ if (view.isFirstResponder) return view
45
+ const subviews = view.subviews
46
+ for (let index = 0; index < subviews.count; index++) {
47
+ const found = firstResponder(subviews.objectAtIndex(index))
48
+ if (found) return found
49
+ }
50
+ return null
51
+ }
52
+
53
+ // The recognizer only observes: it never cancels or delays the touches of the controls below
54
+ // it, and it recognizes together with the gesture recognizers of Core and Jolt. It takes a
55
+ // touch only while an editor is active and the touch is not on an editor. UIKit runs the tap
56
+ // action after the control's own action, so a control that focused another editor meanwhile
57
+ // keeps that focus.
58
+ let editing: NativeView | null = null
59
+ let Delegate: { new (): object } | undefined
60
+ let Target: { new (): object } | undefined
61
+ function classes() {
62
+ Delegate ??= NSObject.extend(
63
+ {
64
+ gestureRecognizerShouldReceiveTouch(recognizer: Recognizer, touch: { view: NativeView }) {
65
+ editing = editor(touch.view) ? null : firstResponder(recognizer.view)
66
+ return editing !== null
67
+ },
68
+ gestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer() {
69
+ return true
70
+ },
71
+ },
72
+ { protocols: [UIGestureRecognizerDelegate] },
73
+ )
74
+ Target ??= NSObject.extend(
75
+ {
76
+ dismiss(recognizer: Recognizer) {
77
+ const current = firstResponder(recognizer.view)
78
+ if (editing && current?.isEqual(editing)) recognizer.view.endEditing(true)
79
+ editing = null
80
+ },
81
+ },
82
+ { exposedMethods: { dismiss: { returns: interop.types.void, params: [UIGestureRecognizer] } } },
83
+ )
84
+ return { Delegate, Target }
85
+ }
86
+
87
+ /** A tap recognizer on the page container; the scroll view follows the drag with the keyboard. */
88
+ export function dismissKeyboardOn(container: View, options: KeyboardDismissal): () => void {
89
+ const native = container.ios as NativeView | undefined
90
+ if (!native) return () => {}
91
+ let recognizer: Recognizer | undefined
92
+ // The recognizer keeps neither object alive for the runtime: hold both until release.
93
+ let delegate: object | undefined
94
+ let target: object | undefined
95
+ if (options.tap) {
96
+ const { Delegate, Target } = classes()
97
+ delegate = new Delegate()
98
+ target = new Target()
99
+ recognizer = UITapGestureRecognizer.alloc().initWithTargetAction(target, 'dismiss')
100
+ recognizer.cancelsTouchesInView = false
101
+ recognizer.delaysTouchesEnded = false
102
+ recognizer.delegate = delegate
103
+ native.addGestureRecognizer(recognizer)
104
+ }
105
+ let scroll: ScrollView | undefined
106
+ container.eachChildView((child) => {
107
+ if (child instanceof ScrollView) scroll = child
108
+ return !scroll
109
+ })
110
+ // UIScrollViewKeyboardDismissMode: none (0) or interactive (2).
111
+ if (scroll?.ios) scroll.ios.keyboardDismissMode = options.drag ? 2 : 0
112
+ return () => {
113
+ if (recognizer) {
114
+ native.removeGestureRecognizer(recognizer)
115
+ recognizer.delegate = null
116
+ }
117
+ recognizer = undefined
118
+ delegate = undefined
119
+ target = undefined
120
+ if (scroll?.ios) scroll.ios.keyboardDismissMode = 0
121
+ }
122
+ }
@@ -0,0 +1,14 @@
1
+ import type { View } from '@nativescript/core'
2
+
3
+ export interface KeyboardDismissal {
4
+ /** A tap anywhere on the page that is not an editor. */
5
+ tap: boolean
6
+ /** A drag of the scrolling content. */
7
+ drag: boolean
8
+ }
9
+
10
+ // NativeScript resolves the platform implementation before loading this module.
11
+ /** Puts the software keyboard away for the given gestures until the returned function runs. */
12
+ export function dismissKeyboardOn(_container: View, _options: KeyboardDismissal): () => void {
13
+ return () => {}
14
+ }
@@ -1,6 +1,20 @@
1
1
  import { Label, Utils } from '@nativescript/core'
2
+ import { recordMeasurement, reuseMeasurement, type MeasureRecord } from './measure-memo'
2
3
 
3
4
  export class MavisLabel extends Label {
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
  disposeNativeView() {
5
19
  const native = this.nativeViewProtected
6
20
  super.disposeNativeView()
@@ -0,0 +1,116 @@
1
+ import { Utils, type View } from '@nativescript/core'
2
+
3
+ const { layout } = Utils
4
+
5
+ interface ChildRecord {
6
+ view: View
7
+ widthSpec: number
8
+ heightSpec: number
9
+ width: number
10
+ height: number
11
+ }
12
+ export interface MeasureRecord {
13
+ widthSpec: number
14
+ heightSpec: number
15
+ width: number
16
+ height: number
17
+ percent: boolean
18
+ /** The looser request clamped content that wanted more room; an exact size would shrink it. */
19
+ clamped: boolean
20
+ children: ChildRecord[]
21
+ }
22
+ interface Internals {
23
+ _currentWidthMeasureSpec: number
24
+ _currentHeightMeasureSpec: number
25
+ _measuredWidth: number
26
+ _measuredHeight: number
27
+ _setCurrentMeasureSpecs(widthSpec: number, heightSpec: number): boolean
28
+ isLayoutRequested: boolean
29
+ }
30
+ export interface Memoized extends View {
31
+ measureRecord?: MeasureRecord
32
+ }
33
+
34
+ const isPercent = (value: unknown) =>
35
+ typeof value === 'object' && value !== null && (value as { unit?: string }).unit === '%'
36
+
37
+ // An exact request for the size a looser request produced is the same measurement, unless a
38
+ // child resolves a percentage against the request itself or the looser request clamped content
39
+ // that wanted more room: an exact size would then shrink the children instead. Core keeps the
40
+ // too-small state only for widths, so layouts report clamping themselves.
41
+ function matches(spec: number, record: MeasureRecord, recordedSpec: number, sizeAndState: number) {
42
+ if (spec === recordedSpec) return true
43
+ if (record.percent || record.clamped) return false
44
+ if (layout.getMeasureSpecMode(spec) !== layout.EXACTLY) return false
45
+ if (layout.getMeasureSpecMode(recordedSpec) === layout.EXACTLY) return false
46
+ if (sizeAndState & layout.MEASURED_STATE_TOO_SMALL) return false
47
+ return layout.getMeasureSpecSize(spec) === (sizeAndState & layout.MEASURED_SIZE_MASK)
48
+ }
49
+
50
+ /** Whether a looser request on either axis returned its whole limit; for layouts that cannot tell. */
51
+ export function filledLimit(widthSpec: number, heightSpec: number, width: number, height: number) {
52
+ const filled = (spec: number, size: number) =>
53
+ layout.getMeasureSpecMode(spec) === layout.AT_MOST &&
54
+ (size & layout.MEASURED_SIZE_MASK) >= layout.getMeasureSpecSize(spec)
55
+ return filled(widthSpec, width) || filled(heightSpec, height)
56
+ }
57
+
58
+ /**
59
+ * Core measures a view again whenever its parent asks while a layout request is pending, and
60
+ * flex containers ask several times per pass, so nested containers measure their leaves an
61
+ * exponential number of times. While nothing in the subtree asked for layout, the recorded
62
+ * measurement answers a repeated request and the children are measured again from their records.
63
+ */
64
+ export function reuseMeasurement(view: Memoized, widthSpec: number, heightSpec: number) {
65
+ const record = view.measureRecord
66
+ const internals = view as unknown as Internals
67
+ if (!record || !internals.isLayoutRequested) return false
68
+ if (!matches(widthSpec, record, record.widthSpec, record.width)) return false
69
+ if (!matches(heightSpec, record, record.heightSpec, record.height)) return false
70
+ internals._setCurrentMeasureSpecs(widthSpec, heightSpec)
71
+ for (const child of record.children) {
72
+ const current = child.view as unknown as Internals
73
+ // A child still holding the recorded result was measured by this record's pass.
74
+ if (current._measuredWidth === child.width && current._measuredHeight === child.height) continue
75
+ child.view.measure(child.widthSpec, child.heightSpec)
76
+ }
77
+ view.setMeasuredDimension(record.width, record.height)
78
+ return true
79
+ }
80
+
81
+ /** Stores the measurement that just completed with the specs every child last received. */
82
+ export function recordMeasurement(
83
+ view: Memoized,
84
+ widthSpec: number,
85
+ heightSpec: number,
86
+ children: readonly View[] = [],
87
+ clamped = false,
88
+ ) {
89
+ const internals = view as unknown as Internals
90
+ view.measureRecord = {
91
+ widthSpec,
92
+ heightSpec,
93
+ width: internals._measuredWidth,
94
+ height: internals._measuredHeight,
95
+ percent: children.some((child) => isPercent(child.width) || isPercent(child.height)),
96
+ clamped,
97
+ children: children.map((child) => {
98
+ const specs = child as unknown as Internals
99
+ return {
100
+ view: child,
101
+ widthSpec: specs._currentWidthMeasureSpec,
102
+ heightSpec: specs._currentHeightMeasureSpec,
103
+ width: specs._measuredWidth,
104
+ height: specs._measuredHeight,
105
+ }
106
+ }),
107
+ }
108
+ }
109
+
110
+ export function layoutChildren(view: { eachLayoutChild(callback: (child: View) => void): void }) {
111
+ const children: View[] = []
112
+ view.eachLayoutChild((child) => {
113
+ children.push(child)
114
+ })
115
+ return children
116
+ }
@@ -0,0 +1,12 @@
1
+ import { GridLayout } from '@nativescript/core'
2
+
3
+ declare const com: {
4
+ mavis: { ui: { Screen: new (context: unknown) => object } }
5
+ }
6
+
7
+ /** The page container sees every touch of the page and can put the keyboard away. */
8
+ export class MavisScreen extends GridLayout {
9
+ createNativeView() {
10
+ return new com.mavis.ui.Screen(this._context)
11
+ }
12
+ }
@@ -0,0 +1,2 @@
1
+ // NativeScript resolves the platform implementation before loading this module.
2
+ export { GridLayout as MavisScreen } from '@nativescript/core'
@@ -0,0 +1,24 @@
1
+ import { Application, type View } from '@nativescript/core'
2
+
3
+ export interface BackPress {
4
+ cancel: boolean
5
+ }
6
+
7
+ export function watchBack(handler: (event: BackPress) => void): () => void {
8
+ const event = Application.android.activityBackPressedEvent
9
+ Application.android.on(event, handler)
10
+ return () => Application.android.off(event, handler)
11
+ }
12
+
13
+ export function setModal(_panel: View, _modal: boolean) {}
14
+
15
+ /** The Android window keeps the page inside the system bars, so the host needs no insets. */
16
+ export function safeAreaOf(_host: View): { readonly top: number; readonly bottom: number } {
17
+ return { top: 0, bottom: 0 }
18
+ }
19
+
20
+ export function expandLayerHost(_host: View) {}
21
+
22
+ export function bottomInset(_host: View): number {
23
+ return 0
24
+ }
@@ -0,0 +1,43 @@
1
+ import type { View } from '@nativescript/core'
2
+
3
+ export interface BackPress {
4
+ cancel: boolean
5
+ }
6
+
7
+ export function watchBack(_handler: (event: BackPress) => void): () => void {
8
+ return () => {}
9
+ }
10
+
11
+ export function setModal(panel: View, modal: boolean) {
12
+ const native = panel.ios as { accessibilityViewIsModal: boolean } | undefined
13
+ if (native) native.accessibilityViewIsModal = modal
14
+ }
15
+
16
+ interface Insets {
17
+ top: number
18
+ bottom: number
19
+ }
20
+ const windowInsets = (view: View): Insets | undefined =>
21
+ (view.page?.ios as { safeAreaInsets?: Insets } | undefined)?.safeAreaInsets
22
+
23
+ /** The page lays its content inside the safe area; the host grows back over it with negative margins. */
24
+ export function expandLayerHost(host: View) {
25
+ const insets = windowInsets(host)
26
+ if (!insets) return
27
+ if (host.marginTop !== -insets.top) host.marginTop = -insets.top
28
+ if (host.marginBottom !== -insets.bottom) host.marginBottom = -insets.bottom
29
+ }
30
+
31
+ /** Keeps the panel below the status bar; the panel itself pads its content above the home indicator. */
32
+ export function safeAreaOf(host: View): { readonly top: number; readonly bottom: number } {
33
+ return {
34
+ get top() {
35
+ return windowInsets(host)?.top ?? 0
36
+ },
37
+ bottom: 0,
38
+ }
39
+ }
40
+
41
+ export function bottomInset(host: View): number {
42
+ return windowInsets(host)?.bottom ?? 0
43
+ }
@@ -0,0 +1,26 @@
1
+ import type { View } from '@nativescript/core'
2
+
3
+ export interface BackPress {
4
+ cancel: boolean
5
+ }
6
+
7
+ // NativeScript resolves the platform implementation before loading this module.
8
+ /** Android reports the back press before the sheet handles it; other platforms have none. */
9
+ export function watchBack(_handler: (event: BackPress) => void): () => void {
10
+ return () => {}
11
+ }
12
+
13
+ /** iOS keeps VoiceOver inside a modal view; Android hides the covered content instead. */
14
+ export function setModal(_panel: View, _modal: boolean) {}
15
+
16
+ /** Safe-area insets around the sheet host, in DIPs; only iOS reports them. */
17
+ export function safeAreaOf(_host: View): { readonly top: number; readonly bottom: number } {
18
+ return { top: 0, bottom: 0 }
19
+ }
20
+
21
+ /** Lets the layer host cover the whole window; only iOS insets it by default. */
22
+ export function expandLayerHost(_host: View) {}
23
+
24
+ export function bottomInset(_host: View): number {
25
+ return 0
26
+ }
@@ -1,13 +1,28 @@
1
- import { defineComponent, h, mergeProps, provide, registerElement } from 'nativescript-vue'
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ mergeProps,
5
+ onBeforeUnmount,
6
+ provide,
7
+ registerElement,
8
+ watch,
9
+ } from 'nativescript-vue'
10
+ import { isIOS, type EventData, type View } from '@nativescript/core'
2
11
  import { screenProps, useMavisTheme, layoutDirection } from '@getcortexlabs/mavis-core/vue'
3
12
  import { MColumn } from './layout.js'
4
13
  import { MavisScreenScroll } from '../../native/screen-scroll'
14
+ import { MavisScreen } from '../../native/screen'
15
+ import { dismissKeyboardOn } from '../../native/keyboard-dismiss'
5
16
  import { useNativeViewAttrs } from '../accessibility.js'
17
+ import { provideLayerHost } from '../layers.js'
18
+ import { expandLayerHost } from '../../native/sheet'
6
19
 
7
20
  registerElement('MavisScreenScroll', () => MavisScreenScroll, {
8
21
  // NSVViewFlags.CONTENT_VIEW; ScrollView owns one content view.
9
22
  viewFlags: 2,
10
23
  })
24
+ // NSVViewFlags.LAYOUT_VIEW; the page container also puts the keyboard away.
25
+ registerElement('MavisScreen', () => MavisScreen, { viewFlags: 4 })
11
26
 
12
27
  export const MScreen = defineComponent({
13
28
  name: 'MScreen',
@@ -16,10 +31,31 @@ export const MScreen = defineComponent({
16
31
  setup(props, { attrs, slots }) {
17
32
  const { theme } = useMavisTheme()
18
33
  const nativeAttrs = useNativeViewAttrs(props)
34
+ const layers = provideLayerHost()
19
35
  provide(layoutDirection, 'column')
36
+ let container: View | undefined
37
+ let release: (() => void) | undefined
38
+ const applyKeyboard = () => {
39
+ release?.()
40
+ release = undefined
41
+ if (!container || !props.dismissKeyboard) return
42
+ release = dismissKeyboardOn(container, { tap: true, drag: props.scroll })
43
+ }
44
+ watch(() => [props.dismissKeyboard, props.scroll], applyKeyboard)
45
+ onBeforeUnmount(() => {
46
+ release?.()
47
+ release = undefined
48
+ })
20
49
  return () => {
50
+ // A presented layer covers the content, which leaves the accessibility tree meanwhile.
51
+ const presented = layers.filter((layer) => layer.presented.value)
52
+ const covered = presented.length > 0
21
53
  // Page and ScrollView require one content view; the column also accepts multiple slot children.
22
- const content = h(MColumn, {}, { default: () => slots.default?.() })
54
+ const content = h(
55
+ MColumn,
56
+ { accessibilityHidden: props.scroll ? undefined : covered },
57
+ { default: () => slots.default?.() },
58
+ )
23
59
  return h(
24
60
  'Page',
25
61
  mergeProps(
@@ -33,9 +69,46 @@ export const MScreen = defineComponent({
33
69
  attrs,
34
70
  ),
35
71
  [
36
- props.scroll
37
- ? h('MavisScreenScroll', { iosOverflowSafeArea: false }, [content])
38
- : content,
72
+ h(
73
+ 'MavisScreen',
74
+ {
75
+ ...(isIOS ? { clipToBounds: false } : {}),
76
+ onLoaded: (event: EventData) => {
77
+ container = event.object as View
78
+ applyKeyboard()
79
+ },
80
+ onUnloaded: () => {
81
+ release?.()
82
+ release = undefined
83
+ container = undefined
84
+ },
85
+ },
86
+ [
87
+ props.scroll
88
+ ? h(
89
+ 'MavisScreenScroll',
90
+ { iosOverflowSafeArea: false, accessibilityHidden: covered },
91
+ [content],
92
+ )
93
+ : content,
94
+ // Layers such as sheets render above the content. Their host ignores Core's safe-area
95
+ // adjustment and grows over the whole window, so the sheet geometry can trust its frame
96
+ // and the scrim covers the status bar and home indicator areas too.
97
+ covered
98
+ ? h(
99
+ 'GridLayout',
100
+ {
101
+ iosIgnoreSafeArea: true,
102
+ onLoaded: (event: EventData) => expandLayerHost(event.object as View),
103
+ onLayoutChanged: (event: EventData) => expandLayerHost(event.object as View),
104
+ },
105
+ presented.map((layer) =>
106
+ h(layer.component, { ...layer.props, key: layer.key }),
107
+ ),
108
+ )
109
+ : null,
110
+ ],
111
+ ),
39
112
  ],
40
113
  )
41
114
  }