Files
Alexander Vakrilov 23757e5dfc Enable recycling of nativeView 2 (#4467)
* enable recycling of nativeView

* backgroundInternal is reset if setting new value leads to background.isEmpty() == true.

* android background.getDefault always return copy of the background. Now all controls that mutate the background can be reset to initial state (e.g. Button & ActionBar)
passing resources to copied background so it respect density.
fix properties initNativeView

* reset padding when backgroundInternal is reset.

* Fix text reset
Fix padding reset

* fix tsc errors

* fix ugly text rendering.

* Add unit tests for recycling native views
Fix several issues that came from the above tests
Fix maxLength property missing a converter callback
Remove old files

* Remove old files

* Revert backgroundInternal setter

* change the order of tests so that appium can work again

* Remove suggestion on every TextView & TextField init (strangely it is enabled after view is recycled....)

* Fix function to get parent layout if specified

* Button stateListAnimator restored when button is recycled
zIndex defaultValue is now undefined instead of NaN

* revert zIndex.setNative to always clear stateListAnimator because it was breaking one UI test (setting value=0 was returning the previous stateListAnimator)

* fix search-bar backgound-color recycling

* Fix alignments setters

* Fix imageView recycling
Fix button recycling
Fix edit-text recycling
resetNativeView is called only if recycleNativeView flag is true

* Fix incorrect merge

* Fix text-view & text-field textTransform

* Fix EditText text reset

* Fix runtime crash on ARM emulator API 21

* Fix text-base minHeight. maxHeight reset
Fix reset of isUserInteractionEnabled
2017-06-29 18:01:22 +03:00

176 lines
5.4 KiB
TypeScript

import { WebViewBase, knownFolders, traceEnabled, traceWrite, traceCategories } from "./web-view-common";
export * from "./web-view-common";
interface WebViewClient {
new (owner: WebView): android.webkit.WebViewClient;
}
let WebViewClient: WebViewClient;
function initializeWebViewClient(): void {
if (WebViewClient) {
return;
}
class WebViewClientImpl extends android.webkit.WebViewClient {
constructor(public owner: WebViewBase) {
super();
return global.__native(this);
}
public shouldOverrideUrlLoading(view: android.webkit.WebView, url: string) {
if (traceEnabled()) {
traceWrite("WebViewClientClass.shouldOverrideUrlLoading(" + url + ")", traceCategories.Debug);
}
return false;
}
public onPageStarted(view: android.webkit.WebView, url: string, favicon: android.graphics.Bitmap) {
super.onPageStarted(view, url, favicon);
const owner = this.owner;
if (owner) {
if (traceEnabled()) {
traceWrite("WebViewClientClass.onPageStarted(" + url + ", " + favicon + ")", traceCategories.Debug);
}
owner._onLoadStarted(url, undefined);
}
}
public onPageFinished(view: android.webkit.WebView, url: string) {
super.onPageFinished(view, url);
const owner = this.owner;
if (owner) {
if (traceEnabled()) {
traceWrite("WebViewClientClass.onPageFinished(" + url + ")", traceCategories.Debug);
}
owner._onLoadFinished(url, undefined);
}
}
public onReceivedError() {
let view: android.webkit.WebView = arguments[0];
if (arguments.length === 4) {
let errorCode: number = arguments[1];
let description: string = arguments[2];
let failingUrl: string = arguments[3];
super.onReceivedError(view, errorCode, description, failingUrl);
const owner = this.owner;
if (owner) {
if (traceEnabled()) {
traceWrite("WebViewClientClass.onReceivedError(" + errorCode + ", " + description + ", " + failingUrl + ")", traceCategories.Debug);
}
owner._onLoadFinished(failingUrl, description + "(" + errorCode + ")");
}
} else {
let request: any = arguments[1];
let error: any = arguments[2];
super.onReceivedError(view, request, error);
const owner = this.owner;
if (owner) {
if (traceEnabled()) {
traceWrite("WebViewClientClass.onReceivedError(" + error.getErrorCode() + ", " + error.getDescription() + ", " + (error.getUrl && error.getUrl()) + ")", traceCategories.Debug);
}
owner._onLoadFinished(error.getUrl && error.getUrl(), error.getDescription() + "(" + error.getErrorCode() + ")");
}
}
}
};
WebViewClient = WebViewClientImpl;
}
export class WebView extends WebViewBase {
nativeView: android.webkit.WebView;
public createNativeView() {
initializeWebViewClient();
const nativeView = new android.webkit.WebView(this._context);
nativeView.getSettings().setJavaScriptEnabled(true);
nativeView.getSettings().setBuiltInZoomControls(true);
const client = new WebViewClient(this);
nativeView.setWebViewClient(client);
(<any>nativeView).client = client;
return nativeView;
}
public initNativeView(): void {
super.initNativeView();
(<any>this.nativeView).client.owner = this;
}
public disposeNativeView() {
const nativeView = this.nativeView;
if (nativeView) {
nativeView.destroy();
}
(<any>nativeView).client.owner = null;
super.disposeNativeView();
}
public _loadUrl(src: string) {
const nativeView = this.nativeView;
if (!nativeView) {
return;
}
nativeView.loadUrl(src);
}
public _loadData(src: string) {
const nativeView = this.nativeView;
if (!nativeView) {
return;
}
const baseUrl = `file:///${knownFolders.currentApp().path}/`;
nativeView.loadDataWithBaseURL(baseUrl, src, "text/html", "utf-8", null);
}
get canGoBack(): boolean {
return this.nativeView.canGoBack();
}
public stopLoading() {
const nativeView = this.nativeView;
if (nativeView) {
nativeView.stopLoading();
}
}
get canGoForward(): boolean {
const nativeView = this.nativeView;
if (nativeView) {
return nativeView.canGoForward();
}
return false;
}
public goBack() {
const nativeView = this.nativeView;
if (nativeView) {
return nativeView.goBack();
}
}
public goForward() {
const nativeView = this.nativeView;
if (nativeView) {
return nativeView.goForward();
}
}
public reload() {
const nativeView = this.nativeView;
if (nativeView) {
return nativeView.reload();
}
}
}