Skip to content

Commit 0f14101

Browse files
author
Hristo Hristov
authored
recycling now happens only if nativeView and android properties are not accessed. (NativeScript#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.
1 parent 8535e54 commit 0f14101

File tree

110 files changed

+844
-834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+844
-834
lines changed

tests/app/testRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ function showReportPage(finalMessage: string) {
359359
if (page.android) {
360360
setTimeout(() => {
361361
messageContainer.dismissSoftInput();
362-
(<android.view.View>messageContainer.nativeView).scrollTo(0, 0);
362+
(<android.view.View>messageContainer.nativeViewProtected).scrollTo(0, 0);
363363
});
364364
}
365365
}

tests/app/ui/action-bar/action-bar-tests.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function test_actionItem_visibility() {
1111
actionItem.text = "Test";
1212
const page = actionTestsCommon.createPageAndNavigate();
1313
page.actionBar.actionItems.addItem(actionItem);
14-
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeView;
14+
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeViewProtected;
1515
const menu = toolbar.getMenu();
1616

1717
TKUnit.assertTrue(menu.hasVisibleItems(), "Visibility does not work");
@@ -25,7 +25,7 @@ export function test_navigationButton_visibility() {
2525
const page = actionTestsCommon.createPageAndNavigate();
2626
page.actionBar.navigationButton = actionItem;
2727

28-
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeView;
28+
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeViewProtected;
2929

3030
TKUnit.assertNotNull(toolbar.getNavigationIcon(), "Visibility does not work");
3131
actionItem.visibility = Visibility.collapse;

tests/app/ui/activity-indicator/activity-indicator-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ if (platform.device.os === platform.platformNames.ios) {
5555
ai.color = new color.Color("red");
5656

5757
function testAction(views: Array<viewModule.View>) {
58-
TKUnit.assertEqual(ai.color.ios.CGColor, ai.nativeView.color.CGColor, "ai.color");
58+
TKUnit.assertEqual(ai.color.ios.CGColor, ai.nativeViewProtected.color.CGColor, "ai.color");
5959
};
6060

6161
helper.buildUIAndRunTest(ai, testAction);

tests/app/ui/helper.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ export function nativeView_recycling_test(createNew: () => View, createLayout?:
261261
const test = createNew();
262262

263263
// Make sure we are not reusing a native views.
264-
first.recycleNativeView = false;
265-
test.recycleNativeView = false;
264+
first.recycleNativeView = "never";
265+
test.recycleNativeView = "never";
266266

267267
page.content = layout;
268268

@@ -273,12 +273,12 @@ export function nativeView_recycling_test(createNew: () => View, createLayout?:
273273
// Needed so we can reset formattedText
274274
test["secure"] = false;
275275

276-
const nativeView = test.nativeView;
276+
const nativeView = test.nativeViewProtected;
277277
// Mark so we reuse the native views.
278-
test.recycleNativeView = true;
278+
test.recycleNativeView = "always";
279279
layout.removeChild(test);
280280
const newer = createNew();
281-
newer.recycleNativeView = true;
281+
newer.recycleNativeView = "always";
282282
layout.addChild(newer);
283283
layout.addChild(first);
284284

@@ -292,7 +292,7 @@ export function nativeView_recycling_test(createNew: () => View, createLayout?:
292292
compareUsingReflection(newer, first);
293293
}
294294

295-
TKUnit.assertEqual(newer.nativeView, nativeView, "nativeView not reused.");
295+
TKUnit.assertEqual(newer.nativeViewProtected, nativeView, "nativeView not reused.");
296296
checkDefaults(newer, first, props, nativeGetters || defaultNativeGetters);
297297
checkDefaults(newer, first, styleProps, nativeGetters || defaultNativeGetters);
298298

@@ -301,8 +301,8 @@ export function nativeView_recycling_test(createNew: () => View, createLayout?:
301301
}
302302

303303
function compareUsingReflection(recycledNativeView: View, newNativeView: View): void {
304-
const recycled: android.view.View = recycledNativeView.nativeView;
305-
const newer: android.view.View = newNativeView.nativeView;
304+
const recycled: android.view.View = recycledNativeView.nativeViewProtected;
305+
const newer: android.view.View = newNativeView.nativeViewProtected;
306306
TKUnit.assertNotEqual(recycled, newer);
307307
const methods = newer.getClass().getMethods();
308308
for (let i = 0, length = methods.length; i < length; i++) {

tests/app/ui/layouts/common-layout-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function percent_support_nativeLayoutParams_are_correct(test: testModule.
3030

3131
test.waitUntilTestElementLayoutIsValid();
3232

33-
let lp = getNativeLayoutParams(btn.nativeView);
33+
let lp = getNativeLayoutParams(btn.nativeViewProtected);
3434
TKUnit.assertEqual(lp.width, 100, "width");
3535
TKUnit.assertEqual(lp.widthPercent, -1, "widthPercent");
3636
TKUnit.assertEqual(lp.height, 100, "height");

tests/app/ui/layouts/layout-helper.android.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ class NativeGridLayout extends org.nativescript.widgets.GridLayout {
6666
}
6767

6868
export class MyButton extends Button implements def.MyButton {
69-
nativeView: NativeButton;
69+
nativeViewProtected: NativeButton;
7070

7171
public createNativeView() {
7272
return new NativeButton(this._context, this);
7373
}
7474

7575
public initNativeView(): void {
76-
this.nativeView.owner = this;
76+
this.nativeViewProtected.owner = this;
7777
}
7878

7979
public disposeNativeView() {
80-
this.nativeView.owner = undefined;
80+
this.nativeViewProtected.owner = undefined;
8181
}
8282

8383
public measureCount: number = 0;
@@ -102,35 +102,35 @@ export class MyButton extends Button implements def.MyButton {
102102
}
103103

104104
get layoutWidth(): number {
105-
return this.nativeView.getWidth();
105+
return this.nativeViewProtected.getWidth();
106106
}
107107

108108
get layoutHeight(): number {
109-
return this.nativeView.getHeight();
109+
return this.nativeViewProtected.getHeight();
110110
}
111111

112112
get layoutLeft(): number {
113-
return this.nativeView.getLeft();
113+
return this.nativeViewProtected.getLeft();
114114
}
115115

116116
get layoutTop(): number {
117-
return this.nativeView.getTop();
117+
return this.nativeViewProtected.getTop();
118118
}
119119
}
120120

121121
export class MyStackLayout extends StackLayout implements def.MyStackLayout {
122-
nativeView: NativeStackLayout;
122+
nativeViewProtected: NativeStackLayout;
123123

124124
public createNativeView() {
125125
return new NativeStackLayout(this._context, this);
126126
}
127127

128128
public initNativeView(): void {
129-
this.nativeView.owner = this;
129+
this.nativeViewProtected.owner = this;
130130
}
131131

132132
public disposeNativeView() {
133-
this.nativeView.owner = undefined;
133+
this.nativeViewProtected.owner = undefined;
134134
}
135135

136136
public measureCount: number = 0;
@@ -155,35 +155,35 @@ export class MyStackLayout extends StackLayout implements def.MyStackLayout {
155155
}
156156

157157
get layoutWidth(): number {
158-
return this.nativeView.getWidth();
158+
return this.nativeViewProtected.getWidth();
159159
}
160160

161161
get layoutHeight(): number {
162-
return this.nativeView.getHeight();
162+
return this.nativeViewProtected.getHeight();
163163
}
164164

165165
get layoutLeft(): number {
166-
return this.nativeView.getLeft();
166+
return this.nativeViewProtected.getLeft();
167167
}
168168

169169
get layoutTop(): number {
170-
return this.nativeView.getTop();
170+
return this.nativeViewProtected.getTop();
171171
}
172172
}
173173

174174
export class MyGridLayout extends GridLayout implements def.MyGridLayout {
175-
nativeView: NativeGridLayout;
175+
nativeViewProtected: NativeGridLayout;
176176

177177
public createNativeView() {
178178
return new NativeGridLayout(this._context, this);
179179
}
180180

181181
public initNativeView(): void {
182-
this.nativeView.owner = this;
182+
this.nativeViewProtected.owner = this;
183183
}
184184

185185
public disposeNativeView() {
186-
this.nativeView.owner = undefined;
186+
this.nativeViewProtected.owner = undefined;
187187
}
188188

189189
public measureCount: number = 0;
@@ -208,19 +208,19 @@ export class MyGridLayout extends GridLayout implements def.MyGridLayout {
208208
}
209209

210210
get layoutWidth(): number {
211-
return this.nativeView.getWidth();
211+
return this.nativeViewProtected.getWidth();
212212
}
213213

214214
get layoutHeight(): number {
215-
return this.nativeView.getHeight();
215+
return this.nativeViewProtected.getHeight();
216216
}
217217

218218
get layoutLeft(): number {
219-
return this.nativeView.getLeft();
219+
return this.nativeViewProtected.getLeft();
220220
}
221221

222222
get layoutTop(): number {
223-
return this.nativeView.getTop();
223+
return this.nativeViewProtected.getTop();
224224
}
225225
}
226226

tests/app/ui/lifecycle/pages/button-counter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ export class Button extends button.Button {
1919
super._redrawNativeBackground(value);
2020
}
2121
}
22-
Button.prototype.recycleNativeView = false;
22+
Button.prototype.recycleNativeView = "never";
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as listPickerModule from "tns-core-modules/ui/list-picker";
22

33
export function getNativeItemsCount(listPicker: listPickerModule.ListPicker): number {
4-
var maxValue = listPicker.nativeView.getMaxValue();
4+
var maxValue = listPicker.nativeViewProtected.getMaxValue();
55

66
if (listPicker.items.length === 0 && maxValue === 0) {
77
return 0;
@@ -12,6 +12,6 @@ export function getNativeItemsCount(listPicker: listPickerModule.ListPicker): nu
1212

1313
export function selectNativeItem(listPicker: listPickerModule.ListPicker, index: number): void {
1414
var oldIndex = listPicker.selectedIndex;
15-
listPicker.nativeView.setValue(index);
16-
listPicker.nativeView.valueChangedListener.onValueChange(listPicker.android, oldIndex, index);
15+
listPicker.nativeViewProtected.setValue(index);
16+
listPicker.nativeViewProtected.valueChangedListener.onValueChange(listPicker.android, oldIndex, index);
1717
}

tests/app/ui/list-picker/list-picker-tests.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export var test_Android_MaxValueIsOneLessThanItemsCount = function () {
186186
var listPicker = <listPickerModule.ListPicker>views[0];
187187
listPicker.items = ["One", "Two", "Three"];
188188
var expectedValue = listPicker.items.length - 1;
189-
var actualValue = listPicker.nativeView.getMaxValue();
189+
var actualValue = listPicker.nativeViewProtected.getMaxValue();
190190
TKUnit.assertEqual(actualValue, expectedValue);
191191
});
192192
}
@@ -199,7 +199,7 @@ export var test_Android_WhenItemsAreEmptyNativeControlDoesNotShowZero = function
199199
helper.buildUIAndRunTest(_createListPicker(), function (views: Array<viewModule.View>) {
200200
var listPicker = <listPickerModule.ListPicker>views[0];
201201
var expectedValue = " ";
202-
var actualValue = listPicker.nativeView.editText.getText().toString();
202+
var actualValue = listPicker.nativeViewProtected.editText.getText().toString();
203203
TKUnit.assertEqual(actualValue, expectedValue);
204204
});
205205
}
@@ -213,7 +213,7 @@ export var test_Android_WhenBoundToSingleElementArrayEditTextIsUpdatedProperly =
213213
var listPicker = <listPickerModule.ListPicker>views[0];
214214
listPicker.items = ["One"];
215215
var expectedValue = "One";
216-
var actualValue = listPicker.nativeView.editText.getText().toString();
216+
var actualValue = listPicker.nativeViewProtected.editText.getText().toString();
217217
TKUnit.assertEqual(actualValue, expectedValue);
218218
});
219219
}
@@ -228,7 +228,7 @@ export var test_Android_WhenSelectedIndexChangesEditTextIsUpdatedProperly = func
228228
listPicker.items = ["One", "Two"];
229229
listPicker.selectedIndex = 1;
230230
var expectedValue = "Two";
231-
var actualValue = listPicker.nativeView.editText.getText().toString();
231+
var actualValue = listPicker.nativeViewProtected.editText.getText().toString();
232232
TKUnit.assertEqual(actualValue, expectedValue);
233233
});
234234
}

tests/app/ui/page/page-tests-common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ export function test_page_backgroundColor_is_white() {
385385
helper.navigate(factory);
386386
let whiteColor = new Color("white");
387387
if (platform.isIOS) {
388-
TKUnit.assertTrue(whiteColor.ios.CGColor.isEqual(page.nativeView.backgroundColor.CGColor), "page default backgroundColor should be white");
388+
TKUnit.assertTrue(whiteColor.ios.CGColor.isEqual(page.nativeViewProtected.backgroundColor.CGColor), "page default backgroundColor should be white");
389389
} else {
390-
TKUnit.assertEqual(page.nativeView.getBackground().getColor(), whiteColor.android, "page default backgroundColor should be white");
390+
TKUnit.assertEqual(page.nativeViewProtected.getBackground().getColor(), whiteColor.android, "page default backgroundColor should be white");
391391
}
392392
}
393393

0 commit comments

Comments
 (0)