mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
recycling now happens only if nativeView and android properties are not accessed. (#4627)
recycleNativeView filed now accepts: "always" | "never" | "auto". Always will recycle the nativeView no matter if its nativeView or android proprties are accessed. Never will disable recycling. Auto will recycle it only if nativeView and android properties are not accessed.
This commit is contained in:
@@ -359,7 +359,7 @@ function showReportPage(finalMessage: string) {
|
||||
if (page.android) {
|
||||
setTimeout(() => {
|
||||
messageContainer.dismissSoftInput();
|
||||
(<android.view.View>messageContainer.nativeView).scrollTo(0, 0);
|
||||
(<android.view.View>messageContainer.nativeViewProtected).scrollTo(0, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export function test_actionItem_visibility() {
|
||||
actionItem.text = "Test";
|
||||
const page = actionTestsCommon.createPageAndNavigate();
|
||||
page.actionBar.actionItems.addItem(actionItem);
|
||||
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeView;
|
||||
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeViewProtected;
|
||||
const menu = toolbar.getMenu();
|
||||
|
||||
TKUnit.assertTrue(menu.hasVisibleItems(), "Visibility does not work");
|
||||
@@ -25,7 +25,7 @@ export function test_navigationButton_visibility() {
|
||||
const page = actionTestsCommon.createPageAndNavigate();
|
||||
page.actionBar.navigationButton = actionItem;
|
||||
|
||||
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeView;
|
||||
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeViewProtected;
|
||||
|
||||
TKUnit.assertNotNull(toolbar.getNavigationIcon(), "Visibility does not work");
|
||||
actionItem.visibility = Visibility.collapse;
|
||||
|
||||
@@ -55,7 +55,7 @@ if (platform.device.os === platform.platformNames.ios) {
|
||||
ai.color = new color.Color("red");
|
||||
|
||||
function testAction(views: Array<viewModule.View>) {
|
||||
TKUnit.assertEqual(ai.color.ios.CGColor, ai.nativeView.color.CGColor, "ai.color");
|
||||
TKUnit.assertEqual(ai.color.ios.CGColor, ai.nativeViewProtected.color.CGColor, "ai.color");
|
||||
};
|
||||
|
||||
helper.buildUIAndRunTest(ai, testAction);
|
||||
|
||||
@@ -261,8 +261,8 @@ export function nativeView_recycling_test(createNew: () => View, createLayout?:
|
||||
const test = createNew();
|
||||
|
||||
// Make sure we are not reusing a native views.
|
||||
first.recycleNativeView = false;
|
||||
test.recycleNativeView = false;
|
||||
first.recycleNativeView = "never";
|
||||
test.recycleNativeView = "never";
|
||||
|
||||
page.content = layout;
|
||||
|
||||
@@ -273,12 +273,12 @@ export function nativeView_recycling_test(createNew: () => View, createLayout?:
|
||||
// Needed so we can reset formattedText
|
||||
test["secure"] = false;
|
||||
|
||||
const nativeView = test.nativeView;
|
||||
const nativeView = test.nativeViewProtected;
|
||||
// Mark so we reuse the native views.
|
||||
test.recycleNativeView = true;
|
||||
test.recycleNativeView = "always";
|
||||
layout.removeChild(test);
|
||||
const newer = createNew();
|
||||
newer.recycleNativeView = true;
|
||||
newer.recycleNativeView = "always";
|
||||
layout.addChild(newer);
|
||||
layout.addChild(first);
|
||||
|
||||
@@ -292,7 +292,7 @@ export function nativeView_recycling_test(createNew: () => View, createLayout?:
|
||||
compareUsingReflection(newer, first);
|
||||
}
|
||||
|
||||
TKUnit.assertEqual(newer.nativeView, nativeView, "nativeView not reused.");
|
||||
TKUnit.assertEqual(newer.nativeViewProtected, nativeView, "nativeView not reused.");
|
||||
checkDefaults(newer, first, props, nativeGetters || defaultNativeGetters);
|
||||
checkDefaults(newer, first, styleProps, nativeGetters || defaultNativeGetters);
|
||||
|
||||
@@ -301,8 +301,8 @@ export function nativeView_recycling_test(createNew: () => View, createLayout?:
|
||||
}
|
||||
|
||||
function compareUsingReflection(recycledNativeView: View, newNativeView: View): void {
|
||||
const recycled: android.view.View = recycledNativeView.nativeView;
|
||||
const newer: android.view.View = newNativeView.nativeView;
|
||||
const recycled: android.view.View = recycledNativeView.nativeViewProtected;
|
||||
const newer: android.view.View = newNativeView.nativeViewProtected;
|
||||
TKUnit.assertNotEqual(recycled, newer);
|
||||
const methods = newer.getClass().getMethods();
|
||||
for (let i = 0, length = methods.length; i < length; i++) {
|
||||
|
||||
@@ -30,7 +30,7 @@ export function percent_support_nativeLayoutParams_are_correct(test: testModule.
|
||||
|
||||
test.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
let lp = getNativeLayoutParams(btn.nativeView);
|
||||
let lp = getNativeLayoutParams(btn.nativeViewProtected);
|
||||
TKUnit.assertEqual(lp.width, 100, "width");
|
||||
TKUnit.assertEqual(lp.widthPercent, -1, "widthPercent");
|
||||
TKUnit.assertEqual(lp.height, 100, "height");
|
||||
|
||||
@@ -66,18 +66,18 @@ class NativeGridLayout extends org.nativescript.widgets.GridLayout {
|
||||
}
|
||||
|
||||
export class MyButton extends Button implements def.MyButton {
|
||||
nativeView: NativeButton;
|
||||
nativeViewProtected: NativeButton;
|
||||
|
||||
public createNativeView() {
|
||||
return new NativeButton(this._context, this);
|
||||
}
|
||||
|
||||
public initNativeView(): void {
|
||||
this.nativeView.owner = this;
|
||||
this.nativeViewProtected.owner = this;
|
||||
}
|
||||
|
||||
public disposeNativeView() {
|
||||
this.nativeView.owner = undefined;
|
||||
this.nativeViewProtected.owner = undefined;
|
||||
}
|
||||
|
||||
public measureCount: number = 0;
|
||||
@@ -102,35 +102,35 @@ export class MyButton extends Button implements def.MyButton {
|
||||
}
|
||||
|
||||
get layoutWidth(): number {
|
||||
return this.nativeView.getWidth();
|
||||
return this.nativeViewProtected.getWidth();
|
||||
}
|
||||
|
||||
get layoutHeight(): number {
|
||||
return this.nativeView.getHeight();
|
||||
return this.nativeViewProtected.getHeight();
|
||||
}
|
||||
|
||||
get layoutLeft(): number {
|
||||
return this.nativeView.getLeft();
|
||||
return this.nativeViewProtected.getLeft();
|
||||
}
|
||||
|
||||
get layoutTop(): number {
|
||||
return this.nativeView.getTop();
|
||||
return this.nativeViewProtected.getTop();
|
||||
}
|
||||
}
|
||||
|
||||
export class MyStackLayout extends StackLayout implements def.MyStackLayout {
|
||||
nativeView: NativeStackLayout;
|
||||
nativeViewProtected: NativeStackLayout;
|
||||
|
||||
public createNativeView() {
|
||||
return new NativeStackLayout(this._context, this);
|
||||
}
|
||||
|
||||
public initNativeView(): void {
|
||||
this.nativeView.owner = this;
|
||||
this.nativeViewProtected.owner = this;
|
||||
}
|
||||
|
||||
public disposeNativeView() {
|
||||
this.nativeView.owner = undefined;
|
||||
this.nativeViewProtected.owner = undefined;
|
||||
}
|
||||
|
||||
public measureCount: number = 0;
|
||||
@@ -155,35 +155,35 @@ export class MyStackLayout extends StackLayout implements def.MyStackLayout {
|
||||
}
|
||||
|
||||
get layoutWidth(): number {
|
||||
return this.nativeView.getWidth();
|
||||
return this.nativeViewProtected.getWidth();
|
||||
}
|
||||
|
||||
get layoutHeight(): number {
|
||||
return this.nativeView.getHeight();
|
||||
return this.nativeViewProtected.getHeight();
|
||||
}
|
||||
|
||||
get layoutLeft(): number {
|
||||
return this.nativeView.getLeft();
|
||||
return this.nativeViewProtected.getLeft();
|
||||
}
|
||||
|
||||
get layoutTop(): number {
|
||||
return this.nativeView.getTop();
|
||||
return this.nativeViewProtected.getTop();
|
||||
}
|
||||
}
|
||||
|
||||
export class MyGridLayout extends GridLayout implements def.MyGridLayout {
|
||||
nativeView: NativeGridLayout;
|
||||
nativeViewProtected: NativeGridLayout;
|
||||
|
||||
public createNativeView() {
|
||||
return new NativeGridLayout(this._context, this);
|
||||
}
|
||||
|
||||
public initNativeView(): void {
|
||||
this.nativeView.owner = this;
|
||||
this.nativeViewProtected.owner = this;
|
||||
}
|
||||
|
||||
public disposeNativeView() {
|
||||
this.nativeView.owner = undefined;
|
||||
this.nativeViewProtected.owner = undefined;
|
||||
}
|
||||
|
||||
public measureCount: number = 0;
|
||||
@@ -208,19 +208,19 @@ export class MyGridLayout extends GridLayout implements def.MyGridLayout {
|
||||
}
|
||||
|
||||
get layoutWidth(): number {
|
||||
return this.nativeView.getWidth();
|
||||
return this.nativeViewProtected.getWidth();
|
||||
}
|
||||
|
||||
get layoutHeight(): number {
|
||||
return this.nativeView.getHeight();
|
||||
return this.nativeViewProtected.getHeight();
|
||||
}
|
||||
|
||||
get layoutLeft(): number {
|
||||
return this.nativeView.getLeft();
|
||||
return this.nativeViewProtected.getLeft();
|
||||
}
|
||||
|
||||
get layoutTop(): number {
|
||||
return this.nativeView.getTop();
|
||||
return this.nativeViewProtected.getTop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,4 @@ export class Button extends button.Button {
|
||||
super._redrawNativeBackground(value);
|
||||
}
|
||||
}
|
||||
Button.prototype.recycleNativeView = false;
|
||||
Button.prototype.recycleNativeView = "never";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as listPickerModule from "tns-core-modules/ui/list-picker";
|
||||
|
||||
export function getNativeItemsCount(listPicker: listPickerModule.ListPicker): number {
|
||||
var maxValue = listPicker.nativeView.getMaxValue();
|
||||
var maxValue = listPicker.nativeViewProtected.getMaxValue();
|
||||
|
||||
if (listPicker.items.length === 0 && maxValue === 0) {
|
||||
return 0;
|
||||
@@ -12,6 +12,6 @@ export function getNativeItemsCount(listPicker: listPickerModule.ListPicker): nu
|
||||
|
||||
export function selectNativeItem(listPicker: listPickerModule.ListPicker, index: number): void {
|
||||
var oldIndex = listPicker.selectedIndex;
|
||||
listPicker.nativeView.setValue(index);
|
||||
listPicker.nativeView.valueChangedListener.onValueChange(listPicker.android, oldIndex, index);
|
||||
listPicker.nativeViewProtected.setValue(index);
|
||||
listPicker.nativeViewProtected.valueChangedListener.onValueChange(listPicker.android, oldIndex, index);
|
||||
}
|
||||
@@ -186,7 +186,7 @@ export var test_Android_MaxValueIsOneLessThanItemsCount = function () {
|
||||
var listPicker = <listPickerModule.ListPicker>views[0];
|
||||
listPicker.items = ["One", "Two", "Three"];
|
||||
var expectedValue = listPicker.items.length - 1;
|
||||
var actualValue = listPicker.nativeView.getMaxValue();
|
||||
var actualValue = listPicker.nativeViewProtected.getMaxValue();
|
||||
TKUnit.assertEqual(actualValue, expectedValue);
|
||||
});
|
||||
}
|
||||
@@ -199,7 +199,7 @@ export var test_Android_WhenItemsAreEmptyNativeControlDoesNotShowZero = function
|
||||
helper.buildUIAndRunTest(_createListPicker(), function (views: Array<viewModule.View>) {
|
||||
var listPicker = <listPickerModule.ListPicker>views[0];
|
||||
var expectedValue = " ";
|
||||
var actualValue = listPicker.nativeView.editText.getText().toString();
|
||||
var actualValue = listPicker.nativeViewProtected.editText.getText().toString();
|
||||
TKUnit.assertEqual(actualValue, expectedValue);
|
||||
});
|
||||
}
|
||||
@@ -213,7 +213,7 @@ export var test_Android_WhenBoundToSingleElementArrayEditTextIsUpdatedProperly =
|
||||
var listPicker = <listPickerModule.ListPicker>views[0];
|
||||
listPicker.items = ["One"];
|
||||
var expectedValue = "One";
|
||||
var actualValue = listPicker.nativeView.editText.getText().toString();
|
||||
var actualValue = listPicker.nativeViewProtected.editText.getText().toString();
|
||||
TKUnit.assertEqual(actualValue, expectedValue);
|
||||
});
|
||||
}
|
||||
@@ -228,7 +228,7 @@ export var test_Android_WhenSelectedIndexChangesEditTextIsUpdatedProperly = func
|
||||
listPicker.items = ["One", "Two"];
|
||||
listPicker.selectedIndex = 1;
|
||||
var expectedValue = "Two";
|
||||
var actualValue = listPicker.nativeView.editText.getText().toString();
|
||||
var actualValue = listPicker.nativeViewProtected.editText.getText().toString();
|
||||
TKUnit.assertEqual(actualValue, expectedValue);
|
||||
});
|
||||
}
|
||||
@@ -385,9 +385,9 @@ export function test_page_backgroundColor_is_white() {
|
||||
helper.navigate(factory);
|
||||
let whiteColor = new Color("white");
|
||||
if (platform.isIOS) {
|
||||
TKUnit.assertTrue(whiteColor.ios.CGColor.isEqual(page.nativeView.backgroundColor.CGColor), "page default backgroundColor should be white");
|
||||
TKUnit.assertTrue(whiteColor.ios.CGColor.isEqual(page.nativeViewProtected.backgroundColor.CGColor), "page default backgroundColor should be white");
|
||||
} else {
|
||||
TKUnit.assertEqual(page.nativeView.getBackground().getColor(), whiteColor.android, "page default backgroundColor should be white");
|
||||
TKUnit.assertEqual(page.nativeViewProtected.getBackground().getColor(), whiteColor.android, "page default backgroundColor should be white");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ export function test_NavigateToNewPage_WithAndroidCache() {
|
||||
|
||||
TKUnit.assertNull(label._context, "InnerControl._context should not be set after navigate back.");
|
||||
TKUnit.assertNull(label.android, "InnerControl.android should not be set after navigate back.");
|
||||
TKUnit.assertNull(label.nativeView, "InnerControl.nativeView hould not be set after navigate back.");
|
||||
TKUnit.assertNull(label.nativeViewProtected, "InnerControl.nativeView hould not be set after navigate back.");
|
||||
TKUnit.assertFalse(label.isLoaded, "InnerControl.isLoaded should become false after navigating back");
|
||||
TKUnit.assertFalse(label._isAddedToNativeVisualTree, "InnerControl._isAddedToNativeVisualTree should not be true after navigating back");
|
||||
}
|
||||
@@ -71,7 +71,7 @@ export function test_NavigateToNewPage_InnerControl() {
|
||||
|
||||
TKUnit.assertNull(label._context, "InnerControl._context should be undefined after navigate back.");
|
||||
TKUnit.assertNull(label.android, "InnerControl.android should be undefined after navigate back.");
|
||||
TKUnit.assertNull(label.nativeView, "InnerControl.nativeView should be undefined after navigate back.");
|
||||
TKUnit.assertNull(label.nativeViewProtected, "InnerControl.nativeView should be undefined after navigate back.");
|
||||
TKUnit.assertFalse(label.isLoaded, "InnerControl.isLoaded should become false after navigating back");
|
||||
TKUnit.assertFalse(label._isAddedToNativeVisualTree, "InnerControl._isAddedToNativeVisualTree should become false after navigating back");
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ export function test_placeholder_creatingView() {
|
||||
|
||||
function testAction(views: Array<viewModule.View>) {
|
||||
if (isIOS) {
|
||||
TKUnit.assert(p.nativeView instanceof UITextView, "nativeView property should be UITextView. Current value: " + p.nativeView);
|
||||
TKUnit.assert(p.nativeViewProtected instanceof UITextView, "nativeView property should be UITextView. Current value: " + p.nativeViewProtected);
|
||||
} else if (isAndroid) {
|
||||
TKUnit.assert(p.nativeView instanceof android.widget.TextView, "Native view should be android.widget.TextView. Current value: " + p.nativeView);
|
||||
TKUnit.assert(p.nativeViewProtected instanceof android.widget.TextView, "Native view should be android.widget.TextView. Current value: " + p.nativeViewProtected);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export function checkNativeItemsTextColor(bar: segmentedBarModule.SegmentedBar):
|
||||
// }
|
||||
|
||||
for (let i = 0, itemsLength = bar.items.length; i < itemsLength; i++) {
|
||||
let textView = <android.widget.TextView>bar.items[0].nativeView;
|
||||
let textView = <android.widget.TextView>bar.items[0].nativeViewProtected;
|
||||
isValid = bar.color && bar.color.android === textView.getCurrentTextColor();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import * as segmentedBarModule from "tns-core-modules/ui/segmented-bar";
|
||||
|
||||
export function getNativeItemsCount(bar: segmentedBarModule.SegmentedBar): number {
|
||||
return (<UISegmentedControl>bar.nativeView).numberOfSegments;
|
||||
return (<UISegmentedControl>bar.nativeViewProtected).numberOfSegments;
|
||||
}
|
||||
|
||||
export function checkNativeItemsTextColor(bar: segmentedBarModule.SegmentedBar): boolean {
|
||||
var isValid = true;
|
||||
|
||||
var attrs = (<UISegmentedControl>bar.nativeView).titleTextAttributesForState(UIControlState.Normal);
|
||||
var attrs = (<UISegmentedControl>bar.nativeViewProtected).titleTextAttributesForState(UIControlState.Normal);
|
||||
isValid = bar.color && attrs && attrs.valueForKey(NSForegroundColorAttributeName) === bar.color.ios;
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
export function setNativeSelectedIndex(bar: segmentedBarModule.SegmentedBar, index: number): void {
|
||||
(<UISegmentedControl>bar.nativeView).selectedSegmentIndex = index;
|
||||
(<UISegmentedControl>bar.nativeView).sendActionsForControlEvents(UIControlEvents.ValueChanged);
|
||||
(<UISegmentedControl>bar.nativeViewProtected).selectedSegmentIndex = index;
|
||||
(<UISegmentedControl>bar.nativeViewProtected).sendActionsForControlEvents(UIControlEvents.ValueChanged);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ export function test_binding_value_to_model() {
|
||||
|
||||
function getNativeValue(mySwitch: switchModule.Switch): boolean {
|
||||
if (platform.isAndroid) {
|
||||
const nativeView: android.widget.Switch = mySwitch.nativeView;
|
||||
const nativeView: android.widget.Switch = mySwitch.nativeViewProtected;
|
||||
return nativeView.isChecked();
|
||||
} else if (mySwitch.ios) {
|
||||
return mySwitch.ios.on;
|
||||
@@ -151,7 +151,7 @@ function getNativeValue(mySwitch: switchModule.Switch): boolean {
|
||||
|
||||
function setNativeValue(mySwitch: switchModule.Switch, value: boolean) {
|
||||
if (platform.isAndroid) {
|
||||
const nativeView: android.widget.Switch = mySwitch.nativeView;
|
||||
const nativeView: android.widget.Switch = mySwitch.nativeViewProtected;
|
||||
nativeView.setChecked(value);
|
||||
}
|
||||
else if (mySwitch.ios) {
|
||||
|
||||
@@ -14,7 +14,7 @@ import * as helper from "../../ui/helper";
|
||||
import * as observable from "tns-core-modules/data/observable";
|
||||
import * as bindable from "tns-core-modules/ui/core/bindable";
|
||||
import * as definition from "./view-tests";
|
||||
import { isIOS } from "tns-core-modules/platform";
|
||||
import { isIOS, isAndroid } from "tns-core-modules/platform";
|
||||
|
||||
export function test_eachDescendant() {
|
||||
const test = function (views: Array<View>) {
|
||||
@@ -350,8 +350,8 @@ class TestView extends Layout {
|
||||
private _nativeView;
|
||||
constructor(public name: string) {
|
||||
super();
|
||||
this._nativeView = this.nativeView;
|
||||
this.nativeView = undefined;
|
||||
this._nativeView = this.nativeViewProtected;
|
||||
this.nativeViewProtected = undefined;
|
||||
}
|
||||
|
||||
public createNativeView() {
|
||||
@@ -578,7 +578,7 @@ export function test_NativeSetter_called_when_add_and_remove() {
|
||||
export function test_NativeSetter_called_when_add_and_remove_and_recycled() {
|
||||
const firstView = new TestView("firstView");
|
||||
const secondView = new TestView("secondView");
|
||||
secondView.recycleNativeView = !isIOS;
|
||||
secondView.recycleNativeView = isAndroid ? "always" : "never";
|
||||
secondView.customCssProperty = "testCssValue";
|
||||
secondView.custom = "testViewValue";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user