Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions apps/automated/src/ui/list-picker/list-picker-tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as TKUnit from '../../tk-unit';
import * as helper from '../../ui-helper';
import { View, Application } from '@nativescript/core';
import { View, Application, Utils } from '@nativescript/core';
import * as listPickerTestsNative from './list-picker-tests-native';

// >> article-require-listpicker-module
Expand Down Expand Up @@ -200,7 +200,7 @@ export var test_Android_WhenItemsAreEmptyNativeControlDoesNotShowZero = function
helper.buildUIAndRunTest(_createListPicker(), function (views: Array<View>) {
var listPicker = <listPickerModule.ListPicker>views[0];
var expectedValue = ' ';
var actualValue = (listPicker.nativeViewProtected as any).editText.getText().toString();
var actualValue = (listPicker as any)._editText.getText().toString();
TKUnit.assertEqual(actualValue, expectedValue);
});
};
Expand All @@ -214,11 +214,30 @@ export var test_Android_WhenBoundToSingleElementArrayEditTextIsUpdatedProperly =
var listPicker = <listPickerModule.ListPicker>views[0];
listPicker.items = ['One'];
var expectedValue = 'One';
var actualValue = (listPicker.nativeViewProtected as any).editText.getText().toString();
var actualValue = (listPicker as any)._editText.getText().toString();
TKUnit.assertEqual(actualValue, expectedValue);
});
};

export function test_Android_EditTextIsUpdatedAfterGarbageCollection() {
if (!Application.android) {
return;
}

helper.buildUIAndRunTest(_createListPicker(), function (views: Array<View>) {
const listPicker = <listPickerModule.ListPicker>views[0];
listPicker.items = ['One', 'Two'];
for (let i = 0; i < 3; i++) {
Utils.GC();
java.lang.System.gc();
java.lang.System.runFinalization();
TKUnit.wait(0.05);
}
listPicker.selectedIndex = 1;
TKUnit.assertEqual((listPicker as any)._editText.getText().toString(), 'Two');
});
}

export var test_Android_WhenSelectedIndexChangesEditTextIsUpdatedProperly = function () {
if (!Application.android) {
return;
Expand All @@ -229,7 +248,7 @@ export var test_Android_WhenSelectedIndexChangesEditTextIsUpdatedProperly = func
listPicker.items = ['One', 'Two'];
listPicker.selectedIndex = 1;
var expectedValue = 'Two';
var actualValue = (listPicker.nativeViewProtected as any).editText.getText().toString();
var actualValue = (listPicker as any)._editText.getText().toString();
TKUnit.assertEqual(actualValue, expectedValue);
});
};
9 changes: 6 additions & 3 deletions packages/core/ui/list-picker/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ function getSelectorWheelPaint(picker: android.widget.NumberPicker): android.gra
export class ListPicker extends ListPickerBase {
nativeViewProtected: android.widget.NumberPicker;
private _selectorWheelPaint: android.graphics.Paint;
// Not a JS property of the picker: the edit text is its child, so that would be a cycle.
private _editText: android.widget.EditText;

public createNativeView() {
const picker = new android.widget.NumberPicker(this._context);
Expand Down Expand Up @@ -117,8 +119,8 @@ export class ListPicker extends ListPickerBase {
(<any>nativeView).valueChangedListener = valueChangedListener;

const editText = getEditText(nativeView);
this._editText = editText;
if (editText) {
(<any>nativeView).editText = editText;
//Fix the disappearing selected item.
//HACK: http://stackoverflow.com/questions/17708325/android-numberpicker-with-formatter-does-not-format-on-first-rendering/26797732
editText.setFilters([]);
Expand All @@ -136,6 +138,7 @@ export class ListPicker extends ListPickerBase {
if ((<any>nativeView)?.valueChangedListener) {
(<any>nativeView).valueChangedListener.owner = null;
}
this._editText = null;
super.disposeNativeView();
}

Expand All @@ -145,7 +148,7 @@ export class ListPicker extends ListPickerBase {
nativeView.setFormatter(null);
nativeView.setFormatter((<any>nativeView).formatter); //Force the NumberPicker to call our Formatter

const editText = (<any>nativeView).editText;
const editText = this._editText;
if (editText) {
editText.setFilters([]);
editText.invalidate(); //Force the EditText to redraw
Expand Down Expand Up @@ -197,7 +200,7 @@ export class ListPicker extends ListPickerBase {
if (this._selectorWheelPaint) {
this._selectorWheelPaint.setColor(color);

const editText = (<any>this.nativeViewProtected).editText;
const editText = this._editText;
if (editText) {
editText.setTextColor(color);
}
Expand Down
18 changes: 7 additions & 11 deletions packages/core/ui/tab-view/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const PRIMARY_COLOR = 'colorPrimary';
const DEFAULT_ELEVATION = 4;

interface PagerAdapter {
new (owner: WeakRef<TabView>): androidx.viewpager.widget.PagerAdapter;
new (owner: WeakRef<TabView>): androidx.viewpager.widget.PagerAdapter & { items: Array<TabViewItemDefinition> };
}

const TABID = '_tabId';
Expand Down Expand Up @@ -540,15 +540,17 @@ export class TabView extends TabViewBase {
accentColor = 0x00ffffff;
}

// Kept on this view rather than as JS properties of the native views: a native
// view referencing its own child (whose parent is that native view) is a cycle.
nativeView.addView(viewPager);
(<any>nativeView).viewPager = viewPager;
this._viewPager = viewPager;

const adapter = new PagerAdapter(new WeakRef(this));
viewPager.setAdapter(adapter);
(<any>viewPager).adapter = adapter;
this._pagerAdapter = adapter;

nativeView.addView(tabLayout);
(<any>nativeView).tabLayout = tabLayout;
this._tabLayout = tabLayout;

setElevation(nativeView, tabLayout);

Expand All @@ -569,13 +571,7 @@ export class TabView extends TabViewBase {
this._androidViewId = android.view.View.generateViewId();
}

const nativeView: any = this.nativeViewProtected;
this._tabLayout = (<any>nativeView).tabLayout;

const viewPager: androidx.viewpager.widget.ViewPager = (<any>nativeView).viewPager;
viewPager.setId(this._androidViewId);
this._viewPager = viewPager;
this._pagerAdapter = (<any>viewPager).adapter;
this._viewPager.setId(this._androidViewId);
}

public _loadUnloadTabItems(newIndex: number) {
Expand Down
Loading