TextWatchListener is removed at onDetach so that no exception is thrown if android raise textChanged but we destroyed our android object in onDestroy of edit-text (#2392)

This commit is contained in:
Hristo Hristov
2016-07-01 13:20:09 +03:00
committed by GitHub
parent 369a0ac274
commit 7db517858b
2 changed files with 17 additions and 1 deletions

View File

@ -481,3 +481,16 @@ export var testMemoryLeak = function (done) {
textViewTestsNative.typeTextNatively(textView, "Hello, world!");
}, done);
}
export function test_watch_listerer_is_removed_at_onDetach() {
if (platform.isAndroid) {
helper.buildUIAndRunTest(_createTextViewFunc(), (views: Array<viewModule.View>) => {
let tv = <textViewModule.TextView>views[0];
let page = <pagesModule.Page>tv.page;
let editText = tv.android;
editText.setText("String");
page.content = null;
editText.setText("FAIL");
});
}
}

View File

@ -107,8 +107,11 @@ export class EditableTextBase extends common.EditableTextBase {
}
public _onDetached(force?: boolean) {
this._android = undefined;
if (this._android && this._textWatcher) {
this._android.removeTextChangedListener(this._textWatcher);
}
this._android = undefined;
super._onDetached(force);
}