@getcortexlabs/mavis 0.1.0-alpha.1 → 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.
- package/README.md +4 -4
- package/dist/native/appearance.android.d.ts +4 -0
- package/dist/native/appearance.android.d.ts.map +1 -0
- package/dist/native/appearance.android.js +55 -0
- package/dist/native/appearance.android.js.map +1 -0
- package/dist/native/appearance.d.ts +4 -0
- package/dist/native/appearance.d.ts.map +1 -0
- package/dist/native/appearance.js +31 -0
- package/dist/native/appearance.js.map +1 -0
- package/dist/native/box.android.d.ts +5 -0
- package/dist/native/box.android.d.ts.map +1 -0
- package/dist/native/box.android.js +7 -0
- package/dist/native/box.android.js.map +1 -0
- package/dist/native/box.d.ts +2 -0
- package/dist/native/box.d.ts.map +1 -0
- package/dist/native/box.ios.d.ts +10 -0
- package/dist/native/box.ios.d.ts.map +1 -0
- package/dist/native/box.ios.js +25 -0
- package/dist/native/box.ios.js.map +1 -0
- package/dist/native/box.js +3 -0
- package/dist/native/box.js.map +1 -0
- package/dist/native/button.android.d.ts +11 -0
- package/dist/native/button.android.d.ts.map +1 -0
- package/dist/native/button.android.js +31 -0
- package/dist/native/button.android.js.map +1 -0
- package/dist/native/button.ios.d.ts +4 -0
- package/dist/native/button.ios.d.ts.map +1 -1
- package/dist/native/button.ios.js +12 -0
- package/dist/native/button.ios.js.map +1 -1
- package/dist/native/flex-children.d.ts +4 -0
- package/dist/native/flex-children.d.ts.map +1 -0
- package/dist/native/flex-children.js +12 -0
- package/dist/native/flex-children.js.map +1 -0
- package/dist/native/flex-layout.android.d.ts +3 -1
- package/dist/native/flex-layout.android.d.ts.map +1 -1
- package/dist/native/flex-layout.android.js +9 -0
- package/dist/native/flex-layout.android.js.map +1 -1
- package/dist/native/flex-layout.ios.d.ts +9 -1
- package/dist/native/flex-layout.ios.d.ts.map +1 -1
- package/dist/native/flex-layout.ios.js +52 -0
- package/dist/native/flex-layout.ios.js.map +1 -1
- package/dist/native/keyboard-dismiss.android.d.ts +8 -0
- package/dist/native/keyboard-dismiss.android.d.ts.map +1 -0
- package/dist/native/keyboard-dismiss.android.js +9 -0
- package/dist/native/keyboard-dismiss.android.js.map +1 -0
- package/dist/native/keyboard-dismiss.d.ts +10 -0
- package/dist/native/keyboard-dismiss.d.ts.map +1 -0
- package/dist/native/keyboard-dismiss.ios.d.ts +8 -0
- package/dist/native/keyboard-dismiss.ios.d.ts.map +1 -0
- package/dist/native/keyboard-dismiss.ios.js +88 -0
- package/dist/native/keyboard-dismiss.ios.js.map +1 -0
- package/dist/native/keyboard-dismiss.js +6 -0
- package/dist/native/keyboard-dismiss.js.map +1 -0
- package/dist/native/label.ios.d.ts +4 -0
- package/dist/native/label.ios.d.ts.map +1 -1
- package/dist/native/label.ios.js +12 -0
- package/dist/native/label.ios.js.map +1 -1
- package/dist/native/measure-memo.d.ts +37 -0
- package/dist/native/measure-memo.d.ts.map +1 -0
- package/dist/native/measure-memo.js +82 -0
- package/dist/native/measure-memo.js.map +1 -0
- package/dist/native/screen.android.d.ts +6 -0
- package/dist/native/screen.android.d.ts.map +1 -0
- package/dist/native/screen.android.js +8 -0
- package/dist/native/screen.android.js.map +1 -0
- package/dist/native/screen.d.ts +2 -0
- package/dist/native/screen.d.ts.map +1 -0
- package/dist/native/screen.js +3 -0
- package/dist/native/screen.js.map +1 -0
- package/dist/native/sheet.android.d.ts +14 -0
- package/dist/native/sheet.android.d.ts.map +1 -0
- package/dist/native/sheet.android.js +16 -0
- package/dist/native/sheet.android.js.map +1 -0
- package/dist/native/sheet.d.ts +17 -0
- package/dist/native/sheet.d.ts.map +1 -0
- package/dist/native/sheet.ios.d.ts +15 -0
- package/dist/native/sheet.ios.d.ts.map +1 -0
- package/dist/native/sheet.ios.js +32 -0
- package/dist/native/sheet.ios.js.map +1 -0
- package/dist/native/sheet.js +17 -0
- package/dist/native/sheet.js.map +1 -0
- package/dist/vue/components/MButton.d.ts +26 -8
- package/dist/vue/components/MButton.d.ts.map +1 -1
- package/dist/vue/components/MButton.js +25 -6
- package/dist/vue/components/MButton.js.map +1 -1
- package/dist/vue/components/MCard.d.ts +3 -3
- package/dist/vue/components/MIcon.d.ts +55 -0
- package/dist/vue/components/MIcon.d.ts.map +1 -0
- package/dist/vue/components/MIcon.js +34 -0
- package/dist/vue/components/MIcon.js.map +1 -0
- package/dist/vue/components/MInput.d.ts +32 -14
- package/dist/vue/components/MInput.d.ts.map +1 -1
- package/dist/vue/components/MInput.js +26 -5
- package/dist/vue/components/MInput.js.map +1 -1
- package/dist/vue/components/MReveal.d.ts +4 -4
- package/dist/vue/components/MReveal.js +1 -1
- package/dist/vue/components/MReveal.js.map +1 -1
- package/dist/vue/components/MScreen.d.ts +10 -1
- package/dist/vue/components/MScreen.d.ts.map +1 -1
- package/dist/vue/components/MScreen.js +54 -6
- package/dist/vue/components/MScreen.js.map +1 -1
- package/dist/vue/components/MSheet.d.ts +95 -0
- package/dist/vue/components/MSheet.d.ts.map +1 -0
- package/dist/vue/components/MSheet.js +281 -0
- package/dist/vue/components/MSheet.js.map +1 -0
- package/dist/vue/components/MSlider.js +1 -1
- package/dist/vue/components/MSlider.js.map +1 -1
- package/dist/vue/components/MText.d.ts +2 -2
- package/dist/vue/components/MText.js +1 -1
- package/dist/vue/components/MText.js.map +1 -1
- package/dist/vue/components/layout.d.ts +11 -11
- package/dist/vue/components/layout.d.ts.map +1 -1
- package/dist/vue/components/layout.js +4 -2
- package/dist/vue/components/layout.js.map +1 -1
- package/dist/vue/index.d.ts +13 -7
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +14 -5
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/layers.d.ts +17 -0
- package/dist/vue/layers.d.ts.map +1 -0
- package/dist/vue/layers.js +26 -0
- package/dist/vue/layers.js.map +1 -0
- package/dist/vue/native-view.d.ts +6 -0
- package/dist/vue/native-view.d.ts.map +1 -0
- package/dist/vue/native-view.js +5 -0
- package/dist/vue/native-view.js.map +1 -0
- package/dist/vue/props.d.ts +12 -11
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +25 -10
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/system-back.d.ts +11 -0
- package/dist/vue/system-back.d.ts.map +1 -0
- package/dist/vue/system-back.js +2 -0
- package/dist/vue/system-back.js.map +1 -0
- package/fonts/LICENSE +45 -0
- package/fonts/lucide.ttf +0 -0
- package/package.json +3 -2
- package/platforms/android/java/com/mavis/ui/Box.java +63 -0
- package/platforms/android/java/com/mavis/ui/FlexLayout.java +97 -4
- package/platforms/android/java/com/mavis/ui/MeasureMemo.java +145 -0
- package/platforms/android/java/com/mavis/ui/Screen.java +108 -0
- package/src/native/appearance.android.ts +75 -0
- package/src/native/appearance.ts +33 -0
- package/src/native/box.android.ts +11 -0
- package/src/native/box.ios.ts +41 -0
- package/src/native/box.ts +2 -0
- package/src/native/button.android.ts +38 -0
- package/src/native/button.ios.ts +14 -0
- package/src/native/flex-children.ts +12 -0
- package/src/native/flex-layout.android.ts +12 -1
- package/src/native/flex-layout.ios.ts +76 -1
- package/src/native/keyboard-dismiss.android.ts +17 -0
- package/src/native/keyboard-dismiss.ios.ts +122 -0
- package/src/native/keyboard-dismiss.ts +14 -0
- package/src/native/label.ios.ts +14 -0
- package/src/native/measure-memo.ts +116 -0
- package/src/native/screen.android.ts +12 -0
- package/src/native/screen.ts +2 -0
- package/src/native/sheet.android.ts +24 -0
- package/src/native/sheet.ios.ts +43 -0
- package/src/native/sheet.ts +26 -0
- package/src/vue/components/MButton.ts +32 -5
- package/src/vue/components/MIcon.ts +41 -0
- package/src/vue/components/MInput.ts +27 -4
- package/src/vue/components/MReveal.ts +1 -1
- package/src/vue/components/MScreen.ts +79 -6
- package/src/vue/components/MSheet.ts +335 -0
- package/src/vue/components/MSlider.ts +1 -1
- package/src/vue/components/MText.ts +1 -1
- package/src/vue/components/layout.ts +4 -2
- package/src/vue/index.ts +45 -8
- package/src/vue/layers.ts +46 -0
- package/src/vue/native-view.ts +6 -0
- package/src/vue/props.ts +37 -12
- package/src/vue/system-back.ts +12 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Application, Utils } from '@nativescript/core'
|
|
2
|
+
import type { Appearance, AppearanceSource } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
|
|
4
|
+
interface Configuration {
|
|
5
|
+
uiMode: number
|
|
6
|
+
}
|
|
7
|
+
interface Context {
|
|
8
|
+
getResources(): { getConfiguration(): Configuration }
|
|
9
|
+
registerComponentCallbacks(callbacks: object): void
|
|
10
|
+
unregisterComponentCallbacks(callbacks: object): void
|
|
11
|
+
}
|
|
12
|
+
declare const android: {
|
|
13
|
+
content: {
|
|
14
|
+
ComponentCallbacks2: new (implementation: {
|
|
15
|
+
onConfigurationChanged(configuration: Configuration): void
|
|
16
|
+
onLowMemory(): void
|
|
17
|
+
onTrimMemory(level: number): void
|
|
18
|
+
}) => object
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// android.content.res.Configuration.UI_MODE_NIGHT_MASK and UI_MODE_NIGHT_YES.
|
|
23
|
+
const NIGHT_MASK = 0x30
|
|
24
|
+
const NIGHT_YES = 0x20
|
|
25
|
+
|
|
26
|
+
function context(): Context | undefined {
|
|
27
|
+
try {
|
|
28
|
+
return Utils.android.getApplicationContext() as Context
|
|
29
|
+
} catch {
|
|
30
|
+
// The application context does not exist before launch.
|
|
31
|
+
return undefined
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const appearanceOf = (configuration: Configuration): Appearance =>
|
|
36
|
+
(configuration.uiMode & NIGHT_MASK) === NIGHT_YES ? 'dark' : 'light'
|
|
37
|
+
|
|
38
|
+
/** Reads `uiMode` from the application configuration directly; Core's window cache can lag on older devices. */
|
|
39
|
+
export function systemAppearance(): AppearanceSource {
|
|
40
|
+
return {
|
|
41
|
+
current() {
|
|
42
|
+
const app = context()
|
|
43
|
+
return app ? appearanceOf(app.getResources().getConfiguration()) : undefined
|
|
44
|
+
},
|
|
45
|
+
observe(listener) {
|
|
46
|
+
let registered: { app: Context; callbacks: object } | undefined
|
|
47
|
+
const register = () => {
|
|
48
|
+
const app = context()
|
|
49
|
+
if (!app || registered) return
|
|
50
|
+
const callbacks = new android.content.ComponentCallbacks2({
|
|
51
|
+
onConfigurationChanged: (configuration) => listener(appearanceOf(configuration)),
|
|
52
|
+
onLowMemory() {},
|
|
53
|
+
onTrimMemory() {},
|
|
54
|
+
})
|
|
55
|
+
app.registerComponentCallbacks(callbacks)
|
|
56
|
+
registered = { app, callbacks }
|
|
57
|
+
listener(appearanceOf(app.getResources().getConfiguration()))
|
|
58
|
+
}
|
|
59
|
+
// An Android 8 phone skipped one of four configuration deliveries; resuming re-reads it.
|
|
60
|
+
const resumed = () => {
|
|
61
|
+
const app = context()
|
|
62
|
+
if (app) listener(appearanceOf(app.getResources().getConfiguration()))
|
|
63
|
+
}
|
|
64
|
+
register()
|
|
65
|
+
Application.on(Application.launchEvent, register)
|
|
66
|
+
Application.on(Application.resumeEvent, resumed)
|
|
67
|
+
return () => {
|
|
68
|
+
Application.off(Application.launchEvent, register)
|
|
69
|
+
Application.off(Application.resumeEvent, resumed)
|
|
70
|
+
registered?.app.unregisterComponentCallbacks(registered.callbacks)
|
|
71
|
+
registered = undefined
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Application } from '@nativescript/core'
|
|
2
|
+
import type { Appearance, AppearanceSource } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
|
|
4
|
+
function read(): Appearance | undefined {
|
|
5
|
+
try {
|
|
6
|
+
return (
|
|
7
|
+
Application.primaryWindow?.systemAppearance() ?? Application.systemAppearance() ?? undefined
|
|
8
|
+
)
|
|
9
|
+
} catch {
|
|
10
|
+
// Android has no application context before launch; the launch event resolves it below.
|
|
11
|
+
return undefined
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Core reports the primary window's appearance and raises `systemAppearanceChanged` on changes. */
|
|
16
|
+
export function systemAppearance(): AppearanceSource {
|
|
17
|
+
return {
|
|
18
|
+
current: read,
|
|
19
|
+
observe(listener) {
|
|
20
|
+
const changed = (args: { newValue: Appearance }) => listener(args.newValue)
|
|
21
|
+
const launched = () => {
|
|
22
|
+
const value = read()
|
|
23
|
+
if (value) listener(value)
|
|
24
|
+
}
|
|
25
|
+
Application.on(Application.systemAppearanceChangedEvent, changed)
|
|
26
|
+
Application.on(Application.launchEvent, launched)
|
|
27
|
+
return () => {
|
|
28
|
+
Application.off(Application.systemAppearanceChangedEvent, changed)
|
|
29
|
+
Application.off(Application.launchEvent, launched)
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GridLayout } from '@nativescript/core'
|
|
2
|
+
|
|
3
|
+
declare const com: {
|
|
4
|
+
mavis: { ui: { Box: new (context: unknown) => object } }
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class MavisBox extends GridLayout {
|
|
8
|
+
createNativeView() {
|
|
9
|
+
return new com.mavis.ui.Box(this._context)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GridLayout, Utils } from '@nativescript/core'
|
|
2
|
+
import {
|
|
3
|
+
filledLimit,
|
|
4
|
+
layoutChildren,
|
|
5
|
+
recordMeasurement,
|
|
6
|
+
reuseMeasurement,
|
|
7
|
+
type MeasureRecord,
|
|
8
|
+
} from './measure-memo'
|
|
9
|
+
|
|
10
|
+
const { layout } = Utils
|
|
11
|
+
|
|
12
|
+
/** An auto-height Box takes its content height when the parent only limits the available space. */
|
|
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
|
+
|
|
34
|
+
onMeasure(widthSpec: number, heightSpec: number) {
|
|
35
|
+
const relaxed =
|
|
36
|
+
this.effectiveHeight < 0 && layout.getMeasureSpecMode(heightSpec) === layout.AT_MOST
|
|
37
|
+
? layout.makeMeasureSpec(0, layout.UNSPECIFIED)
|
|
38
|
+
: heightSpec
|
|
39
|
+
super.onMeasure(widthSpec, relaxed)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Button, type FormattedString } from '@nativescript/core'
|
|
2
|
+
import { formattedTextProperty } from '@nativescript/core/ui/text-base'
|
|
3
|
+
import {
|
|
4
|
+
accessibilityLabelProperty,
|
|
5
|
+
accessibilityValueProperty,
|
|
6
|
+
} from '@nativescript/core/accessibility/accessibility-properties'
|
|
7
|
+
|
|
8
|
+
type Setter = (this: Button, value: unknown) => void
|
|
9
|
+
const base = Button.prototype as unknown as Record<symbol, Setter>
|
|
10
|
+
const setLabel = base[accessibilityLabelProperty.setNative]!
|
|
11
|
+
const setValue = base[accessibilityValueProperty.setNative]!
|
|
12
|
+
const setFormatted = base[formattedTextProperty.setNative]!
|
|
13
|
+
|
|
14
|
+
/** Core copies formatted text into `text`, so its description would repeat the label after icon glyphs. */
|
|
15
|
+
export class MavisButton extends Button {
|
|
16
|
+
[accessibilityLabelProperty.setNative](value: string) {
|
|
17
|
+
setLabel.call(this, value)
|
|
18
|
+
this.describe()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
[accessibilityValueProperty.setNative](value: string) {
|
|
22
|
+
setValue.call(this, value)
|
|
23
|
+
this.describe()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
[formattedTextProperty.setNative](value: FormattedString) {
|
|
27
|
+
setFormatted.call(this, value)
|
|
28
|
+
this.describe()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private describe() {
|
|
32
|
+
if (!this.formattedText) return
|
|
33
|
+
const description = [this.accessibilityLabel, this.accessibilityValue]
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.join('. ')
|
|
36
|
+
this.nativeViewProtected?.setContentDescription(description)
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/native/button.ios.ts
CHANGED
|
@@ -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
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FlexboxLayout, View } from '@nativescript/core'
|
|
2
|
+
import { flexShrinkProperty } from '@nativescript/core/ui/layouts/flexbox-layout'
|
|
3
|
+
|
|
4
|
+
const source = flexShrinkProperty.sourceKey
|
|
5
|
+
|
|
6
|
+
/** Children without their own shrink keep their natural height in a column, like Mavis children. */
|
|
7
|
+
export function applyColumnShrink(layout: FlexboxLayout, child: View) {
|
|
8
|
+
if (!layout.flexDirection.startsWith('column')) return
|
|
9
|
+
// Core records the value source even when a local value equals the default, unlike isSet.
|
|
10
|
+
const declared = (child.style as unknown as Record<symbol, number | undefined>)[source]
|
|
11
|
+
if (!declared) child.style.flexShrink = 0
|
|
12
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FlexboxLayout } from '@nativescript/core'
|
|
1
|
+
import { FlexboxLayout, type View } from '@nativescript/core'
|
|
2
|
+
import { applyColumnShrink } from './flex-children'
|
|
2
3
|
|
|
3
4
|
declare const com: {
|
|
4
5
|
mavis: { ui: { FlexLayout: new (context: unknown) => object } }
|
|
@@ -8,4 +9,14 @@ export class MavisFlexLayout extends FlexboxLayout {
|
|
|
8
9
|
createNativeView() {
|
|
9
10
|
return new com.mavis.ui.FlexLayout(this._context)
|
|
10
11
|
}
|
|
12
|
+
|
|
13
|
+
_registerLayoutChild(child: View) {
|
|
14
|
+
super._registerLayoutChild(child)
|
|
15
|
+
applyColumnShrink(this, child)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
onLoaded() {
|
|
19
|
+
super.onLoaded()
|
|
20
|
+
this.eachLayoutChild((child) => applyColumnShrink(this, child))
|
|
21
|
+
}
|
|
11
22
|
}
|
|
@@ -1,18 +1,77 @@
|
|
|
1
1
|
import { FlexboxLayout, Utils, type View } from '@nativescript/core'
|
|
2
|
+
import { applyColumnShrink } from './flex-children'
|
|
3
|
+
import {
|
|
4
|
+
layoutChildren,
|
|
5
|
+
recordMeasurement,
|
|
6
|
+
reuseMeasurement,
|
|
7
|
+
type MeasureRecord,
|
|
8
|
+
} from './measure-memo'
|
|
2
9
|
|
|
3
10
|
// Core 9.1.3 computes row heights before growing children. This adapter runs after width
|
|
4
11
|
// allocation and before cross-axis alignment; no global prototype or consumer styles change.
|
|
5
12
|
interface FlexMeasurement {
|
|
6
13
|
_determineMainSize(direction: string, widthSpec: number, heightSpec: number): void
|
|
7
|
-
_flexLines: {
|
|
14
|
+
_flexLines: {
|
|
15
|
+
_itemCount: number
|
|
16
|
+
_crossSize: number
|
|
17
|
+
_mainSize: number
|
|
18
|
+
_gapLengthInMainSize: number
|
|
19
|
+
}[]
|
|
8
20
|
_getReorderedChildAt(index: number): View
|
|
21
|
+
_getLargestMainSize(): number
|
|
22
|
+
_getSumOfCrossSize(): number
|
|
23
|
+
effectiveRowGap: number
|
|
9
24
|
}
|
|
10
25
|
|
|
11
26
|
const { layout } = Utils
|
|
12
27
|
const base = FlexboxLayout.prototype as unknown as FlexMeasurement
|
|
13
28
|
|
|
14
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
|
+
|
|
63
|
+
_registerLayoutChild(child: View) {
|
|
64
|
+
super._registerLayoutChild(child)
|
|
65
|
+
applyColumnShrink(this, child)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
onLoaded() {
|
|
69
|
+
super.onLoaded()
|
|
70
|
+
this.eachLayoutChild((child) => applyColumnShrink(this, child))
|
|
71
|
+
}
|
|
72
|
+
|
|
15
73
|
_determineMainSize(direction: string, widthSpec: number, heightSpec: number) {
|
|
74
|
+
if (direction === 'column' || direction === 'column-reverse') this.keepRowGaps()
|
|
16
75
|
if (direction === 'column' && this.alignItems === 'stretch' && this.flexWrap === 'nowrap') {
|
|
17
76
|
const measurement = this as unknown as FlexMeasurement
|
|
18
77
|
const width =
|
|
@@ -56,6 +115,22 @@ export class MavisFlexLayout extends FlexboxLayout {
|
|
|
56
115
|
}
|
|
57
116
|
}
|
|
58
117
|
|
|
118
|
+
// Core 9.1.3 adds row gaps to a column's main size but not to its gap total, so the growth and
|
|
119
|
+
// shrink passes measured the column shorter by every gap and squeezed shrinking children.
|
|
120
|
+
private keepRowGaps() {
|
|
121
|
+
const measurement = this as unknown as FlexMeasurement
|
|
122
|
+
if (!(measurement.effectiveRowGap > 0)) return
|
|
123
|
+
let index = 0
|
|
124
|
+
for (const line of measurement._flexLines) {
|
|
125
|
+
let visible = 0
|
|
126
|
+
for (let i = 0; i < line._itemCount; i++, index++) {
|
|
127
|
+
const child = measurement._getReorderedChildAt(index)
|
|
128
|
+
if (child && !child.isCollapsed) visible++
|
|
129
|
+
}
|
|
130
|
+
line._gapLengthInMainSize = measurement.effectiveRowGap * Math.max(0, visible - 1)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
59
134
|
private measureAtWidth(child: View, width: number, heightSpec: number) {
|
|
60
135
|
const available = Math.max(
|
|
61
136
|
0,
|
|
@@ -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
|
+
}
|