Я использую Webview в NativeScript / Angular с событиями loadStarted и loadFinished. На моем iPhone (tns run ios) оба события запускаются. На моем телефоне Android (tns run android) событие loadStarted не вызывается, вызывая сбой счетчика. Похоже, только ссылки с tel :, mailto: и lo c: вызывают событие loadStarted. Надеюсь, что кто-то может помочь.
XML:
<ActionBar #webviewActionbar title="Facilitor" flat="true">
<ActionItem (tap)="onQrScanTap()" ios.position="right" ios.systemIcon="15" android.systemIcon="ic_menu_camera">
</ActionItem>
</ActionBar>
<GridLayout rows="*">
<WebView row="0" #loginView (loaded)="webviewLoaded($event);" (loadStarted)="webviewTrigger($event)" (loadFinished)="onLoadFinished($event)" (doubleTap)="onDoubleTap($event)" (swipe)="onSwipe($event)" [src]="webViewSrc" ></WebView>
<TextField row="0" [(ngModel)]="registerModel.push_action" #pushActionModel="ngModel" autocorrect="false"
autocapitalizationType="none" [visibility]="'collapse'" (textChange)="navigateToAction()"></TextField>
<ActivityIndicator (loaded)="onSpinnerLoaded($event)" rowSpan="2" [busy]="isBusy" (busyChange)="onBusyChanged($event)" width="100" height="100"></ActivityIndicator>
</GridLayout>
TypeScript:
private onLoadFinished(args: any) {
console.log("== onLoadFinished ==");
this.isBusy = false;
}
private webviewTrigger(args: any) {
console.log("== webviewTrigger ==");
var webView: WebView = <WebView>args.object;
console.log(webView);
// get location
if (args.url.startsWith('loc:')) {
let arr = args.url.split(":");
this.registerModel.push_action = this.registrationService.composeUrl() + arr[1] + "?longitude=" + this.lastLocation.longitude + "&latitude=" + this.lastLocation.latitude;
this.navigateToAction();
webView.reload();
return;
// handle mailto: and tel:
} else if (args.url.startsWith('mailto:') || args.url.startsWith('tel:')) {
utils.openUrl(args.url);
webView.reload();
return;
}
// start spinner
this.isBusy = true;
}
Журнал терминала после нажатия некоторых ссылок:
JS: == onNavigatingTo ==
chromium: [INFO:library_loader_hooks.cc(51)] Chromium logging enabled: level = 0, default verbosity = 0
JS: == webviewLoaded ==
JS: WebView(44)
JS: == setHTTPHeader ==
JS: == onSpinnerLoaded ==
JS: == onNavigatedTo ==
JS: == webviewTrigger ==
JS: WebView(44)
JS: indicator.busy changed to: true
JS: ===Location===
JS: == onLoadFinished ==
JS: indicator.busy changed to: false
JS: == onLoadFinished ==
JS: == onLoadFinished ==
JS: == onLoadFinished ==