Skip to content

Commit eac042b

Browse files
committed
Code review
1 parent d90c146 commit eac042b

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/ChromeTabsManagerActivity.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import Intent = android.content.Intent;
33
import Bundle = android.os.Bundle;
44

55
import { Observable } from '@nativescript/core';
6-
import { BROWSER_TYPES } from './InAppBrowser.common';
6+
import { BROWSER_TYPES } from './InAppBrowser.common';
7+
import { DISMISSED_EVENT } from './utils.android';
78

89

910
export class ChromeTabsEvent extends Observable {
@@ -15,7 +16,7 @@ export const BROWSER_ACTIVITY_EVENTS = new ChromeTabsEvent();
1516

1617
const KEY_BROWSER_INTENT = 'browserIntent';
1718
const BROWSER_RESULT_TYPE = 'browserResultType';
18-
const DEFAULT_RESULT_TYPE = 'dismiss';
19+
const DEFAULT_RESULT_TYPE = BROWSER_TYPES.DISMISS;
1920

2021
/**
2122
* Manages the custom chrome tabs intent by detecting when it is dismissed by the user and allowing
@@ -78,7 +79,7 @@ export class ChromeTabsManagerActivity extends android.app.Activity {
7879
break;
7980
}
8081
BROWSER_ACTIVITY_EVENTS.notify({
81-
eventName: 'DismissedEvent',
82+
eventName: DISMISSED_EVENT,
8283
object: BROWSER_ACTIVITY_EVENTS
8384
});
8485
this.resultType = null;

src/InAppBrowser.android.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ import {
2121
BrowserResult,
2222
getDefaultOptions,
2323
InAppBrowserOptions,
24-
InAppBrowserClassMethods
24+
InAppBrowserClassMethods,
25+
RedirectResolve,
26+
RedirectReject,
27+
BROWSER_TYPES,
2528
} from './InAppBrowser.common';
2629
import {
2730
Builder,
2831
getDrawableId,
2932
toolbarIsLight,
3033
CustomTabsIntent,
34+
DISMISSED_EVENT,
3135
ARROW_BACK_WHITE,
3236
ARROW_BACK_BLACK,
3337
getPreferredPackages,
@@ -59,9 +63,9 @@ function setup() {
5963
private static KEY_BROWSER_PACKAGE = "browserPackage";
6064
private static KEY_SHOW_IN_RECENTS = "showInRecents";
6165

62-
private static redirectResolve: any;
63-
private static redirectReject: any;
64-
private isLightTheme: Boolean;
66+
private static redirectResolve: RedirectResolve;
67+
private static redirectReject: RedirectReject;
68+
private isLightTheme: boolean;
6569
private currentActivity: any;
6670
private animationIdentifierPattern = Pattern.compile("^.+:.+/");
6771

@@ -84,7 +88,7 @@ function setup() {
8488
if (mOpenBrowserPromise) {
8589
this.flowDidFinish();
8690
const result: BrowserResult = {
87-
type: 'cancel'
91+
type: BROWSER_TYPES.CANCEL
8892
};
8993
return Promise.resolve(result);
9094
}
@@ -207,7 +211,7 @@ function setup() {
207211
return;
208212
}
209213

210-
BROWSER_ACTIVITY_EVENTS.off('DismissedEvent');
214+
BROWSER_ACTIVITY_EVENTS.off(DISMISSED_EVENT);
211215

212216
const result: BrowserResult = {
213217
type: 'dismiss'
@@ -243,7 +247,7 @@ function setup() {
243247
}
244248

245249
public onEvent(event: EventData): void {
246-
BROWSER_ACTIVITY_EVENTS.off('DismissedEvent');
250+
BROWSER_ACTIVITY_EVENTS.off(DISMISSED_EVENT);
247251

248252
if (!InAppBrowserModule.redirectResolve) {
249253
throw new AssertionError();
@@ -252,12 +256,12 @@ function setup() {
252256
InAppBrowserModule.redirectResolve({
253257
type: browserEvent.resultType,
254258
message: browserEvent.message
255-
});
259+
} as BrowserResult);
256260
this.flowDidFinish();
257261
}
258262

259263
private registerEvent(): void {
260-
BROWSER_ACTIVITY_EVENTS.once('DismissedEvent', (e) => this.onEvent(e));
264+
BROWSER_ACTIVITY_EVENTS.once(DISMISSED_EVENT, (e) => this.onEvent(e));
261265
}
262266

263267
private resolveAnimationIdentifierIfNeeded(context: Context, identifier: string): number {

src/utils.android.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const LOCAL_PACKAGE = "com.google.android.apps.chrome";
3737
export const ACTION_CUSTOM_TABS_CONNECTION = "android.support.customtabs.action.CustomTabsService";
3838
export const ARROW_BACK_BLACK = 'ic_arrow_back_black';
3939
export const ARROW_BACK_WHITE = 'ic_arrow_back_white';
40+
export const DISMISSED_EVENT = 'DismissedEvent';
4041

4142
/**
4243
* Save the handler of the redirection event in order to removes listener later.

0 commit comments

Comments
 (0)