Skip to content

Commit 7db5178

Browse files
author
Hristo Hristov
authored
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 (NativeScript#2392)
1 parent 369a0ac commit 7db5178

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

tests/app/ui/text-view/text-view-tests.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,16 @@ export var testMemoryLeak = function (done) {
481481
textViewTestsNative.typeTextNatively(textView, "Hello, world!");
482482
}, done);
483483
}
484+
485+
export function test_watch_listerer_is_removed_at_onDetach() {
486+
if (platform.isAndroid) {
487+
helper.buildUIAndRunTest(_createTextViewFunc(), (views: Array<viewModule.View>) => {
488+
let tv = <textViewModule.TextView>views[0];
489+
let page = <pagesModule.Page>tv.page;
490+
let editText = tv.android;
491+
editText.setText("String");
492+
page.content = null;
493+
editText.setText("FAIL");
494+
});
495+
}
496+
}

tns-core-modules/ui/editable-text-base/editable-text-base.android.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ export class EditableTextBase extends common.EditableTextBase {
107107
}
108108

109109
public _onDetached(force?: boolean) {
110-
this._android = undefined;
110+
if (this._android && this._textWatcher) {
111+
this._android.removeTextChangedListener(this._textWatcher);
112+
}
111113

114+
this._android = undefined;
112115
super._onDetached(force);
113116
}
114117

0 commit comments

Comments
 (0)