forked from tjvantoll/nativescript-IQKeyboardManager
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main-view-model.ts
53 lines (42 loc) · 1.76 KB
/
main-view-model.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
import { Observable } from "tns-core-modules/data/observable";
import { isIOS } from "tns-core-modules/platform";
declare const IQKeyboardManager: any;
export class HelloWorldModel extends Observable {
private iqKeyboard: IQKeyboardManager;
public iqKeyboardEnabled: boolean = true;
public iqKeyboardToolbarEnabled: boolean = true;
public keepKeyboardOpenOnTouchOutside: boolean = true;
public showHintInToolbar: boolean = true;
public keyboardAppearanceDark: boolean = false;
public toggleDoneButtonTextChanged: boolean = false;
public increaseKeyboardDistanceFromTextField: boolean = false;
constructor() {
super();
if (isIOS) {
this.iqKeyboard = IQKeyboardManager.sharedManager();
}
}
toggleIQKeyboard(): void {
this.iqKeyboard.enable = !this.iqKeyboard.enable;
}
toggleIQKeyboardToolbar(): void {
this.iqKeyboard.enableAutoToolbar = !this.iqKeyboard.enableAutoToolbar;
}
toggleKeepKeyboardOpen(): void {
this.iqKeyboard.shouldResignOnTouchOutside = !this.iqKeyboard.shouldResignOnTouchOutside;
}
toggleShowHintInToolbar(): void {
this.iqKeyboard.shouldShowTextFieldPlaceholder = !this.iqKeyboard.shouldShowTextFieldPlaceholder;
}
toggleKeyboardAppearance(): void {
this.iqKeyboard.overrideKeyboardAppearance = true;
this.iqKeyboard.keyboardAppearance =
this.iqKeyboard.keyboardAppearance === UIKeyboardAppearance.Default ? UIKeyboardAppearance.Dark : UIKeyboardAppearance.Default;
}
toggleDoneButtonText(): void {
this.iqKeyboard.toolbarDoneBarButtonItemText = this.toggleDoneButtonTextChanged ? "Ready" : "Done";
}
toggleIncreaseKeyboardDistanceFromTextField(): void {
this.iqKeyboard.keyboardDistanceFromTextField = this.iqKeyboard.keyboardDistanceFromTextField === 10 ? 30 : 10;
}
}