-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathcommon.ts
85 lines (64 loc) · 2.5 KB
/
common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { ContentView, View, Property, AddChildFromBuilder, booleanConverter, CoreTypes } from '@nativescript/core';
export const forIdProperty = new Property<ToolbarBase, string>({
name: 'forId',
});
export const showWhenKeyboardHiddenProperty = new Property<ToolbarBase, boolean>({
name: 'showWhenKeyboardHidden',
defaultValue: false,
valueConverter: booleanConverter,
});
export const showAtBottomWhenKeyboardHiddenProperty = new Property<ToolbarBase, boolean>({
name: 'showAtBottomWhenKeyboardHidden',
defaultValue: false,
valueConverter: booleanConverter,
});
export abstract class ToolbarBase extends ContentView implements AddChildFromBuilder {
content: View;
verticalAlignment: CoreTypes.VerticalAlignmentType;
private static DEBUG = false;
// if the keyboard is hidden without blurring the textfield (and vice versa) then the blur/focus events don't fire, so track focus manually
protected hasFocus = false;
protected forId: string;
protected showWhenKeyboardHidden: boolean;
// TODO rename showAtBottomWhenKeyboardHidden to moveToAtBottomWhenKeyboardHidden (?)
protected showAtBottomWhenKeyboardHidden: boolean;
protected abstract _loaded(): void;
protected abstract _unloaded(): void;
protected _layout(left: number, top: number, right: number, bottom: number): void {}
protected log(what: string): void {
if (ToolbarBase.DEBUG) {
console.log('⌨︎ ' + what);
}
}
onLoaded(): void {
super.onLoaded();
// TODO figure out how to determine and apply the parent's height automatically based on the child's height
if (isNaN(+this.height)) {
console.log(`\n⌨ ⌨ ⌨ Please specify height="<nr of px>" or the toolbar won't render correctly! Example: <Toolbar forId="${this.forId}" height="44">\n\n`);
}
this._loaded();
}
onUnloaded(): void {
super.onUnloaded();
this._unloaded();
}
public onLayout(left: number, top: number, right: number, bottom: number): void {
super.onLayout(left, top, right, bottom);
this._layout(left, top, right, bottom);
}
_addChildFromBuilder(name: string, value: View): void {
this.content = value;
}
[forIdProperty.setNative](value: string) {
this.forId = value;
}
[showWhenKeyboardHiddenProperty.setNative](value: boolean) {
this.showWhenKeyboardHidden = value;
}
[showAtBottomWhenKeyboardHiddenProperty.setNative](value: boolean) {
this.showAtBottomWhenKeyboardHidden = value;
}
}
forIdProperty.register(ToolbarBase);
showWhenKeyboardHiddenProperty.register(ToolbarBase);
showAtBottomWhenKeyboardHiddenProperty.register(ToolbarBase);