This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
forked from alexziskind1/nativescript-oauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tns-oauth-webview.ts
49 lines (40 loc) · 1.46 KB
/
tns-oauth-webview.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
/// <reference path="references.d.ts" />
import { WebView } from 'ui/web-view';
import { android } from 'tns-core-modules/application';
import { isAndroid } from 'tns-core-modules/platform';
import { isAppSuspending } from './tns-oauth-utils';
// https://developer.android.com/reference/android/view/WindowManager.LayoutParams#soft_input_adjust_resize
const SOFT_INPUT_ADJUST_RESIZE = 16;
export class TnsOauthWebView extends WebView {
private originalSoftInputMode: number;
constructor(
private _cancelEventHandler: (error?) => void
) {
super();
}
public onLoaded() {
super.onLoaded();
if (isAndroid) {
this.android.getSettings().setBuiltInZoomControls(false);
this.setAndroidSoftInputModeToResize();
}
}
public onUnloaded() {
super.onUnloaded();
if (!isAppSuspending()) {
this._cancelEventHandler("User cancelled.");
if (isAndroid) {
this.restoreAndroidSoftInputMode();
}
}
}
private setAndroidSoftInputModeToResize(): void {
const window = android.foregroundActivity.getWindow();
this.originalSoftInputMode = window.getAttributes().softInputMode;
window.setSoftInputMode(SOFT_INPUT_ADJUST_RESIZE);
}
private restoreAndroidSoftInputMode(): void {
const window = android.foregroundActivity.getWindow();
window.setSoftInputMode(this.originalSoftInputMode);
}
}