@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,335 @@
1
+ import {
2
+ defineComponent,
3
+ getCurrentInstance,
4
+ h,
5
+ inject,
6
+ onBeforeUnmount,
7
+ onMounted,
8
+ provide,
9
+ ref,
10
+ registerElement,
11
+ shallowRef,
12
+ watch,
13
+ type ExtractPropTypes,
14
+ type PropType,
15
+ type Ref,
16
+ type VNodeChild,
17
+ } from 'nativescript-vue'
18
+ import { bottomSheet, GestureSurface, type BottomSheet } from '@rafaelaugusto/jolt/bottom-sheet'
19
+ import { sheetProps, sheetEmits, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
20
+ import { checkSheetName, type SheetCloseReason } from '@getcortexlabs/mavis-core'
21
+ import { isAndroid, type EventData, type ScrollView, type View } from '@nativescript/core'
22
+ import { MRow, MColumn, MBox } from './layout.js'
23
+ import { MText } from './MText.js'
24
+ import { MButton } from './MButton.js'
25
+ import { useLayerHost } from '../layers.js'
26
+ import { nativeViewOf } from '../native-view.js'
27
+ import { systemBackKey } from '../system-back.js'
28
+ import { watchBack, setModal, safeAreaOf, bottomInset } from '../../native/sheet'
29
+ import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
30
+
31
+ registerElement('MavisSheetPanel', () => GestureSurface, { viewFlags: 4 })
32
+
33
+ type SheetState = ExtractPropTypes<typeof sheetProps>
34
+ type Element<T extends View = View> = { nativeView: T }
35
+
36
+ interface Bridge {
37
+ state: SheetState
38
+ content: () => VNodeChild
39
+ provides: Record<PropertyKey, unknown>
40
+ presented: Ref<boolean>
41
+ requestClose(reason: SheetCloseReason): void
42
+ dismissed(reason: SheetCloseReason): void
43
+ reopened(): void
44
+ settled(): void
45
+ }
46
+
47
+ /** Content rendered by the Screen still resolves injections from the sheet's own position. */
48
+ function bridgeProvides(source: Record<PropertyKey, unknown>) {
49
+ const seen = new Set<PropertyKey>()
50
+ for (
51
+ let chain: object | null = source;
52
+ chain && chain !== Object.prototype;
53
+ chain = Object.getPrototypeOf(chain)
54
+ ) {
55
+ for (const key of [
56
+ ...Object.getOwnPropertyNames(chain),
57
+ ...Object.getOwnPropertySymbols(chain),
58
+ ]) {
59
+ if (seen.has(key)) continue
60
+ seen.add(key)
61
+ provide(key as string | symbol, (chain as Record<PropertyKey, unknown>)[key])
62
+ }
63
+ }
64
+ }
65
+
66
+ function focusAccessibility(view: View | undefined) {
67
+ if (!view?.isLoaded) return
68
+ if (isAndroid) view.android.performAccessibilityAction(64, null)
69
+ else notifyAccessibilityLayout(view)
70
+ }
71
+
72
+ const SheetLayer = defineComponent({
73
+ name: 'MSheetLayer',
74
+ props: { bridge: { type: Object as PropType<Bridge>, required: true } },
75
+ setup(props) {
76
+ const bridge = props.bridge
77
+ bridgeProvides(bridge.provides)
78
+ const { theme } = useMavisTheme()
79
+ const claimSystemBack = inject(systemBackKey, undefined)
80
+ const panel = shallowRef<Element<GestureSurface>>()
81
+ const handle = shallowRef<Element>()
82
+ const scroll = shallowRef<Element<ScrollView>>()
83
+ const backdrop = shallowRef<Element>()
84
+ // The panel reaches the bottom of the window; its content stays above the home indicator.
85
+ const inset = ref(0)
86
+ let title: View | undefined
87
+ let sheet: BottomSheet | undefined
88
+ let pending: SheetCloseReason | undefined
89
+ let requested = false
90
+ let releaseBack = () => {}
91
+ let releaseClaim = () => {}
92
+
93
+ function dispose() {
94
+ releaseBack()
95
+ releaseClaim()
96
+ releaseBack = releaseClaim = () => {}
97
+ const current = sheet
98
+ sheet = undefined
99
+ current?.dispose()
100
+ }
101
+ function present() {
102
+ const views = {
103
+ panel: nativeViewOf(panel.value),
104
+ handle: nativeViewOf(handle.value),
105
+ scroll: nativeViewOf(scroll.value),
106
+ backdrop: nativeViewOf(backdrop.value),
107
+ }
108
+ if (sheet || !views.panel || !views.handle || !views.scroll || !views.backdrop) return
109
+ const state = bridge.state
110
+ const host = views.panel.parent as View
111
+ inset.value = bottomInset(host)
112
+ pending = undefined
113
+ requested = false
114
+ const back = () => {
115
+ if (!sheet?.isOpen) return
116
+ if (!state.dismissible) return
117
+ pending = 'back'
118
+ sheet.dismiss()
119
+ }
120
+ // Core's own navigation honors the cancelled event; a router that owns back asks the claimant first.
121
+ releaseBack = watchBack((event) => {
122
+ if (sheet?.isOpen) event.cancel = true
123
+ back()
124
+ })
125
+ releaseClaim = claimSystemBack?.({ owns: () => Boolean(sheet?.isOpen), back }) ?? (() => {})
126
+ setModal(views.panel, true)
127
+ let opened = false
128
+ sheet = bottomSheet(views.panel, {
129
+ handle: views.handle,
130
+ scrollView: views.scroll,
131
+ backdrop: views.backdrop,
132
+ safeArea: safeAreaOf(host),
133
+ snap: [state.fullscreen ? '100%' : 'content'],
134
+ dismissible: state.dismissible,
135
+ accessibility: {
136
+ label: state.title ?? state.accessibilityLabel,
137
+ dismiss: state.closeLabel,
138
+ },
139
+ onChange(point) {
140
+ if (point === null) {
141
+ if (!requested) bridge.dismissed(pending ?? 'swipe')
142
+ pending = undefined
143
+ opened = false
144
+ return
145
+ }
146
+ requested = false
147
+ bridge.reopened()
148
+ if (!opened) focusAccessibility(title)
149
+ opened = true
150
+ },
151
+ onDismiss: () => bridge.settled(),
152
+ })
153
+ sheet.open()
154
+ }
155
+
156
+ onMounted(() => {
157
+ if (bridge.presented.value) present()
158
+ })
159
+ watch(
160
+ () => bridge.presented.value,
161
+ (presented) => {
162
+ if (presented) present()
163
+ },
164
+ { flush: 'post' },
165
+ )
166
+ watch(
167
+ () => bridge.presented.value,
168
+ (presented) => {
169
+ if (!presented) dispose()
170
+ },
171
+ )
172
+ watch(
173
+ () => bridge.state.open,
174
+ (open) => {
175
+ if (!open && sheet) {
176
+ requested = true
177
+ sheet.dismiss()
178
+ }
179
+ },
180
+ )
181
+ onBeforeUnmount(dispose)
182
+
183
+ return () => {
184
+ if (!bridge.presented.value) return null
185
+ const state = bridge.state
186
+ const { colors, radius } = theme.value
187
+ const header =
188
+ state.title || state.dismissible
189
+ ? h(
190
+ MRow,
191
+ { paddingX: 'lg', paddingY: 'sm', gap: 'sm', justify: 'between' },
192
+ {
193
+ default: () => [
194
+ state.title
195
+ ? h(MText, {
196
+ as: 'h2',
197
+ variant: 'heading',
198
+ grow: 1,
199
+ text: state.title,
200
+ onLoaded: (event: EventData) => {
201
+ title = event.object as View
202
+ },
203
+ })
204
+ : h(MBox, { grow: 1 }),
205
+ state.dismissible
206
+ ? h(MButton, {
207
+ variant: 'ghost',
208
+ size: 'sm',
209
+ icon: 'x',
210
+ shrink: 0,
211
+ accessibilityLabel: state.closeLabel,
212
+ onClick: () => bridge.requestClose('button'),
213
+ })
214
+ : null,
215
+ ],
216
+ },
217
+ )
218
+ : null
219
+ return [
220
+ h('MavisBox', {
221
+ ref: backdrop,
222
+ backgroundColor: '#000000',
223
+ accessible: false,
224
+ accessibilityHidden: true,
225
+ onTap: () => {
226
+ if (state.dismissible) pending = 'backdrop'
227
+ },
228
+ }),
229
+ h(
230
+ 'MavisSheetPanel',
231
+ {
232
+ ref: panel,
233
+ id: state.id,
234
+ style: {
235
+ backgroundColor: colors.surface,
236
+ borderTopLeftRadius: radius.lg,
237
+ borderTopRightRadius: radius.lg,
238
+ paddingBottom: inset.value,
239
+ },
240
+ },
241
+ [
242
+ h(
243
+ MColumn,
244
+ {},
245
+ {
246
+ default: () => [
247
+ h('GridLayout', { ref: handle, height: 24 }, [
248
+ h('MavisBox', {
249
+ width: 36,
250
+ height: 5,
251
+ borderRadius: 3,
252
+ backgroundColor: colors.border,
253
+ horizontalAlignment: 'center',
254
+ verticalAlignment: 'middle',
255
+ }),
256
+ ]),
257
+ header,
258
+ // Jolt measures the content snap as the content plus the panel area outside the
259
+ // scroll view, so the scroll view fills whatever height the panel receives.
260
+ h('ScrollView', { ref: scroll, style: { flexGrow: 1, flexShrink: 1 } }, [
261
+ h(
262
+ MColumn,
263
+ { padding: state.padding, gap: state.gap, align: state.align },
264
+ { default: () => bridge.content() },
265
+ ),
266
+ ]),
267
+ ],
268
+ },
269
+ ),
270
+ ],
271
+ ),
272
+ ]
273
+ }
274
+ },
275
+ })
276
+
277
+ export const MSheet = defineComponent({
278
+ name: 'MSheet',
279
+ inheritAttrs: false,
280
+ props: sheetProps,
281
+ emits: sheetEmits,
282
+ setup(props, { slots, emit }) {
283
+ const host = useLayerHost('MSheet')
284
+ checkSheetName(props.title, props.accessibilityLabel)
285
+ // Vue keeps the injection chain on the instance without declaring it in its public types.
286
+ const provides =
287
+ (getCurrentInstance() as { provides?: Record<PropertyKey, unknown> } | null)?.provides ?? {}
288
+ const presented = ref(false)
289
+ let closing: SheetCloseReason | undefined
290
+ const announce = (reason: SheetCloseReason) => {
291
+ closing = reason
292
+ emit('update:open', false)
293
+ emit('close', reason)
294
+ }
295
+ const bridge: Bridge = {
296
+ state: props,
297
+ content: () => slots.default?.(),
298
+ provides,
299
+ presented,
300
+ requestClose(reason) {
301
+ if (props.open && !closing) announce(reason)
302
+ },
303
+ dismissed(reason) {
304
+ if (!closing) announce(reason)
305
+ },
306
+ reopened() {
307
+ closing = undefined
308
+ if (!props.open) emit('update:open', true)
309
+ },
310
+ settled() {
311
+ presented.value = false
312
+ closing = undefined
313
+ },
314
+ }
315
+ watch(
316
+ () => props.open,
317
+ (open) => {
318
+ if (open) {
319
+ closing = undefined
320
+ presented.value = true
321
+ } else if (presented.value && !closing) {
322
+ closing = 'program'
323
+ emit('close', 'program')
324
+ }
325
+ },
326
+ { immediate: true },
327
+ )
328
+ onBeforeUnmount(host.add({ component: SheetLayer, props: { bridge }, presented }))
329
+ return () => {
330
+ // An unnamed sheet fails where it is declared, not in the Screen's render.
331
+ checkSheetName(props.title, props.accessibilityLabel)
332
+ return null
333
+ }
334
+ },
335
+ })
package/src/vue/index.ts CHANGED
@@ -14,8 +14,23 @@ import { MSlider } from './components/MSlider.js'
14
14
  import { MInput } from './components/MInput.js'
15
15
  import { MIcon } from './components/MIcon.js'
16
16
  import { MReveal } from './components/MReveal.js'
17
+ import { MSheet } from './components/MSheet.js'
18
+ import { systemBackKey, type ClaimSystemBack, type SystemBackClaimant } from './system-back.js'
17
19
 
18
- export { MScreen, MBox, MRow, MColumn, MCard, MText, MButton, MSlider, MInput, MIcon, MReveal }
20
+ export {
21
+ MScreen,
22
+ MBox,
23
+ MRow,
24
+ MColumn,
25
+ MCard,
26
+ MText,
27
+ MButton,
28
+ MSlider,
29
+ MInput,
30
+ MIcon,
31
+ MReveal,
32
+ MSheet,
33
+ }
19
34
  export { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
20
35
  export type {
21
36
  MavisThemeContext,
@@ -26,14 +41,21 @@ export type {
26
41
  export type { Align, Justify } from './components/layout.js'
27
42
  export type {} from '@getcortexlabs/mavis-core/vue'
28
43
 
29
- export type MavisOptions = Omit<ThemeContextOptions, 'source'>
44
+ export type { SystemBackClaimant, ClaimSystemBack }
45
+
46
+ export type MavisOptions = Omit<ThemeContextOptions, 'source'> & {
47
+ /** Lets a router hand the Android back press to an open sheet first, e.g. vue-router-ns `claimSystemBack`. */
48
+ claimSystemBack?: ClaimSystemBack
49
+ }
30
50
 
31
51
  /** Create one plugin per application; `system` appearance follows the device. Vue also resolves MButton as <m-button>. */
32
52
  export function createMavis(options: MavisOptions = {}) {
33
53
  return {
34
54
  install(app: App) {
35
- const context = createThemeContext({ ...options, source: systemAppearance() })
55
+ const { claimSystemBack, ...theme } = options
56
+ const context = createThemeContext({ ...theme, source: systemAppearance() })
36
57
  app.provide(themeKey, context)
58
+ app.provide(systemBackKey, claimSystemBack)
37
59
  app.onUnmount(() => context.dispose())
38
60
  for (const [name, component] of Object.entries({
39
61
  MScreen,
@@ -47,6 +69,7 @@ export function createMavis(options: MavisOptions = {}) {
47
69
  MInput,
48
70
  MIcon,
49
71
  MReveal,
72
+ MSheet,
50
73
  })) {
51
74
  app.component(name, component)
52
75
  }
@@ -0,0 +1,46 @@
1
+ import {
2
+ inject,
3
+ provide,
4
+ shallowReactive,
5
+ type Component,
6
+ type InjectionKey,
7
+ type Ref,
8
+ } from 'nativescript-vue'
9
+
10
+ export interface Layer {
11
+ component: Component
12
+ props: Record<string, unknown>
13
+ /** True while the layer covers the screen content. */
14
+ presented: Ref<boolean>
15
+ }
16
+ export interface LayerEntry extends Layer {
17
+ key: number
18
+ }
19
+ export interface LayerHost {
20
+ add(layer: Layer): () => void
21
+ }
22
+
23
+ const layerHost: InjectionKey<LayerHost> = Symbol('mavis.layers')
24
+
25
+ /** A Screen renders registered layers above its content, inside one native cell. */
26
+ export function provideLayerHost(): LayerEntry[] {
27
+ const layers = shallowReactive<LayerEntry[]>([])
28
+ let next = 0
29
+ provide(layerHost, {
30
+ add(layer) {
31
+ const entry = { ...layer, key: next++ }
32
+ layers.push(entry)
33
+ return () => {
34
+ const index = layers.indexOf(entry)
35
+ if (index >= 0) layers.splice(index, 1)
36
+ }
37
+ },
38
+ })
39
+ return layers
40
+ }
41
+
42
+ export function useLayerHost(name: string): LayerHost {
43
+ const host = inject(layerHost, undefined)
44
+ if (!host) throw new Error(`${name} needs an MScreen ancestor on NativeScript`)
45
+ return host
46
+ }
@@ -0,0 +1,6 @@
1
+ import type { View } from '@nativescript/core'
2
+
3
+ /** Template refs on native elements wrap the NativeScript view. */
4
+ export function nativeViewOf<T extends View>(element: { nativeView: T } | undefined) {
5
+ return element?.nativeView
6
+ }
package/src/vue/props.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MavisTheme } from '@getcortexlabs/mavis-core'
1
+ import type { Dimension, MavisTheme } from '@getcortexlabs/mavis-core'
2
2
  import {
3
3
  resolveSpace,
4
4
  resolveRadius,
@@ -8,19 +8,44 @@ import {
8
8
  import type { BoxProps } from '@getcortexlabs/mavis-core/vue'
9
9
  export { boxProps, spacingProp } from '@getcortexlabs/mavis-core/vue'
10
10
 
11
- export function boxStyle(theme: MavisTheme, props: BoxProps, defaultShrink = 0) {
12
- const padding = resolveSpace(theme, props.padding ?? 'none')
13
- return {
14
- paddingLeft: props.paddingX === undefined ? padding : resolveSpace(theme, props.paddingX),
15
- paddingRight: props.paddingX === undefined ? padding : resolveSpace(theme, props.paddingX),
16
- paddingTop: props.paddingY === undefined ? padding : resolveSpace(theme, props.paddingY),
17
- paddingBottom: props.paddingY === undefined ? padding : resolveSpace(theme, props.paddingY),
18
- borderRadius: resolveRadius(theme, props.radius),
11
+ export interface BoxStyle {
12
+ paddingLeft?: number
13
+ paddingRight?: number
14
+ paddingTop?: number
15
+ paddingBottom?: number
16
+ borderRadius?: number
17
+ flexGrow: number
18
+ flexShrink: number
19
+ minWidth: number
20
+ width?: Dimension
21
+ height?: Dimension
22
+ backgroundColor?: string
23
+ }
24
+
25
+ // A prop that was not given leaves its style untouched, so a plain attribute such as
26
+ // `paddingTop` or `borderRadius` on the element survives every render.
27
+ export function boxStyle(theme: MavisTheme, props: BoxProps, defaultShrink = 0): BoxStyle {
28
+ const style: BoxStyle = {
19
29
  flexGrow: nonNegative(props.grow, 'grow'),
20
30
  flexShrink: nonNegative(props.shrink ?? defaultShrink, 'shrink'),
21
31
  minWidth: 0,
22
- width: resolveDimension(props.width),
23
- height: resolveDimension(props.height),
24
- backgroundColor: props.backgroundColor,
25
32
  }
33
+ const padding = props.padding === undefined ? undefined : resolveSpace(theme, props.padding)
34
+ const x = props.paddingX === undefined ? padding : resolveSpace(theme, props.paddingX)
35
+ const y = props.paddingY === undefined ? padding : resolveSpace(theme, props.paddingY)
36
+ if (x !== undefined) {
37
+ style.paddingLeft = x
38
+ style.paddingRight = x
39
+ }
40
+ if (y !== undefined) {
41
+ style.paddingTop = y
42
+ style.paddingBottom = y
43
+ }
44
+ if (props.radius !== undefined) style.borderRadius = resolveRadius(theme, props.radius)
45
+ const width = resolveDimension(props.width)
46
+ if (width !== undefined) style.width = width
47
+ const height = resolveDimension(props.height)
48
+ if (height !== undefined) style.height = height
49
+ if (props.backgroundColor !== undefined) style.backgroundColor = props.backgroundColor
50
+ return style
26
51
  }
@@ -0,0 +1,12 @@
1
+ import type { InjectionKey } from 'nativescript-vue'
2
+
3
+ /** Something other than a page that the Android system back should reach first. */
4
+ export interface SystemBackClaimant {
5
+ /** Whether it wants the next back press or gesture. */
6
+ owns(): boolean
7
+ /** Takes the press. */
8
+ back(): void
9
+ }
10
+ export type ClaimSystemBack = (claimant: SystemBackClaimant) => () => void
11
+
12
+ export const systemBackKey: InjectionKey<ClaimSystemBack | undefined> = Symbol('mavis.systemBack')