Skip to content

Commit 7c8aa12

Browse files
author
vakrilov
committed
Disable view recycling
1 parent 7983895 commit 7c8aa12

File tree

4 files changed

+120
-110
lines changed

4 files changed

+120
-110
lines changed

tests/app/ui/helper.ts

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -241,59 +241,61 @@ let cssSetters: Map<string, any>;
241241
let defaultNativeGetters: Map<string, (view) => any>;
242242

243243
export function nativeView_recycling_test(createNew: () => View, createLayout?: () => LayoutBase, nativeGetters?: Map<string, (view) => any>, customSetters?: Map<string, any>) {
244-
if (isIOS) {
245-
// recycling not implemented yet.
246-
return;
247-
}
248-
249-
setupSetters();
250-
const page = getClearCurrentPage();
251-
let layout: LayoutBase = new FlexboxLayout();
252-
if (createLayout) {
253-
// This is done on purpose. We need the constructor of Flexbox
254-
// to run otherwise some module fileds stays uninitialized.
255-
layout = createLayout();
256-
}
257-
258-
page.content = layout;
259-
260-
const first = createNew();
261-
const test = createNew();
262-
263-
// Make sure we are not reusing a native views.
264-
first.recycleNativeView = false;
265-
test.recycleNativeView = false;
266-
267-
page.content = layout;
268-
269-
layout.addChild(test);
270-
271-
setValue(test.style, cssSetters);
272-
setValue(test, setters, customSetters);
273-
// Needed so we can reset formattedText
274-
test["secure"] = false;
275-
276-
const nativeView = test.nativeView;
277-
// Mark so we reuse the native views.
278-
test.recycleNativeView = true;
279-
layout.removeChild(test);
280-
const newer = createNew();
281-
newer.recycleNativeView = true;
282-
layout.addChild(newer);
283-
layout.addChild(first);
284-
285-
if (first.typeName !== "SearchBar" && sdkVersion > 19) {
286-
// There are way too many differences in native methods for search-bar.
287-
// There are too many methods that just throw for newly created views in API lvl 19 and 17
288-
compareUsingReflection(newer, first);
289-
}
290-
291-
TKUnit.assertEqual(newer.nativeView, nativeView, "nativeView not reused.");
292-
checkDefaults(newer, first, props, nativeGetters || defaultNativeGetters);
293-
checkDefaults(newer, first, styleProps, nativeGetters || defaultNativeGetters);
294-
295-
layout.removeChild(newer);
296-
layout.removeChild(first);
244+
return;
245+
246+
// if (isIOS) {
247+
// // recycling not implemented yet.
248+
// return;
249+
// }
250+
251+
// setupSetters();
252+
// const page = getClearCurrentPage();
253+
// let layout: LayoutBase = new FlexboxLayout();
254+
// if (createLayout) {
255+
// // This is done on purpose. We need the constructor of Flexbox
256+
// // to run otherwise some module fileds stays uninitialized.
257+
// layout = createLayout();
258+
// }
259+
260+
// page.content = layout;
261+
262+
// const first = createNew();
263+
// const test = createNew();
264+
265+
// // Make sure we are not reusing a native views.
266+
// first.recycleNativeView = false;
267+
// test.recycleNativeView = false;
268+
269+
// page.content = layout;
270+
271+
// layout.addChild(test);
272+
273+
// setValue(test.style, cssSetters);
274+
// setValue(test, setters, customSetters);
275+
// // Needed so we can reset formattedText
276+
// test["secure"] = false;
277+
278+
// const nativeView = test.nativeView;
279+
// // Mark so we reuse the native views.
280+
// test.recycleNativeView = true;
281+
// layout.removeChild(test);
282+
// const newer = createNew();
283+
// newer.recycleNativeView = true;
284+
// layout.addChild(newer);
285+
// layout.addChild(first);
286+
287+
// if (first.typeName !== "SearchBar" && sdkVersion > 19) {
288+
// // There are way too many differences in native methods for search-bar.
289+
// // There are too many methods that just throw for newly created views in API lvl 19 and 17
290+
// compareUsingReflection(newer, first);
291+
// }
292+
293+
// TKUnit.assertEqual(newer.nativeView, nativeView, "nativeView not reused.");
294+
// checkDefaults(newer, first, props, nativeGetters || defaultNativeGetters);
295+
// checkDefaults(newer, first, styleProps, nativeGetters || defaultNativeGetters);
296+
297+
// layout.removeChild(newer);
298+
// layout.removeChild(first);
297299
}
298300

299301
function compareUsingReflection(recycledNativeView: View, newNativeView: View): void {

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

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -575,36 +575,37 @@ export function test_NativeSetter_called_when_add_and_remove() {
575575
});
576576
};
577577

578-
export function test_NativeSetter_called_when_add_and_remove_and_recycled() {
579-
const firstView = new TestView("firstView");
580-
const secondView = new TestView("secondView");
581-
secondView.recycleNativeView = !isIOS;
582-
secondView.customCssProperty = "testCssValue";
583-
secondView.custom = "testViewValue";
584-
585-
helper.buildUIAndRunTest(firstView, () => {
586-
TKUnit.assertEqual(secondView.cssPropCounter, 0, "1");
587-
TKUnit.assertEqual(secondView.viewPropCounter, 0, "2");
588-
589-
// Add to visual tree
590-
firstView.addChild(secondView);
591-
TKUnit.assertEqual(secondView.cssPropCounter, 1, "3");
592-
TKUnit.assertEqual(secondView.viewPropCounter, 1, "4");
593-
594-
// Set new value
595-
secondView.customCssProperty = "test2";
596-
secondView.custom = "test2";
597-
TKUnit.assertEqual(secondView.cssPropCounter, 2, "5");
598-
TKUnit.assertEqual(secondView.viewPropCounter, 2, "6");
599-
600-
// Remove from visual tree
601-
firstView.removeChild(secondView);
602-
603-
// we don't recycle nativeViews on iOS yet so reset is not called.
604-
TKUnit.assertEqual(secondView.cssPropCounter, isIOS ? 2 : 3, "7");
605-
TKUnit.assertEqual(secondView.viewPropCounter, isIOS ? 2 : 3, "8");
606-
});
607-
};
578+
// Disable view recycling
579+
// export function test_NativeSetter_called_when_add_and_remove_and_recycled() {
580+
// const firstView = new TestView("firstView");
581+
// const secondView = new TestView("secondView");
582+
// secondView.recycleNativeView = !isIOS;
583+
// secondView.customCssProperty = "testCssValue";
584+
// secondView.custom = "testViewValue";
585+
586+
// helper.buildUIAndRunTest(firstView, () => {
587+
// TKUnit.assertEqual(secondView.cssPropCounter, 0, "1");
588+
// TKUnit.assertEqual(secondView.viewPropCounter, 0, "2");
589+
590+
// // Add to visual tree
591+
// firstView.addChild(secondView);
592+
// TKUnit.assertEqual(secondView.cssPropCounter, 1, "3");
593+
// TKUnit.assertEqual(secondView.viewPropCounter, 1, "4");
594+
595+
// // Set new value
596+
// secondView.customCssProperty = "test2";
597+
// secondView.custom = "test2";
598+
// TKUnit.assertEqual(secondView.cssPropCounter, 2, "5");
599+
// TKUnit.assertEqual(secondView.viewPropCounter, 2, "6");
600+
601+
// // Remove from visual tree
602+
// firstView.removeChild(secondView);
603+
604+
// // we don't recycle nativeViews on iOS yet so reset is not called.
605+
// TKUnit.assertEqual(secondView.cssPropCounter, isIOS ? 2 : 3, "7");
606+
// TKUnit.assertEqual(secondView.viewPropCounter, isIOS ? 2 : 3, "8");
607+
// });
608+
// };
608609

609610
export function test_InheritableProperties_getValuesFromParent() {
610611
const testValue = 35;

tns-core-modules/ui/core/view-base/view-base.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ export abstract class ViewBase extends Observable {
146146
public nativeView: any;
147147

148148
public bindingContext: any;
149-
public recycleNativeView: boolean;
149+
150+
// Reserved for future use. Currently not used
151+
public recycleNativeView: any;
150152

151153
/**
152154
* Gets the name of the constructor function for this instance. E.g. for a Button class this will return "Button".

tns-core-modules/ui/core/view-base/view-base.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
133133
public static loadedEvent = "loaded";
134134
public static unloadedEvent = "unloaded";
135135

136-
private _recycleNativeView: boolean;
136+
// Disable view recycling
137+
// private _recycleNativeView: boolean;
137138
private _iosView: Object;
138139
private _androidView: Object;
139140
private _style: Style;
@@ -216,12 +217,13 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
216217
return types.getClass(this);
217218
}
218219

219-
get recycleNativeView(): boolean {
220-
return this._recycleNativeView;
220+
// Disable view recycling
221+
get recycleNativeView(): any {
222+
// return this._recycleNativeView;
223+
return false;
221224
}
222-
223-
set recycleNativeView(value: boolean) {
224-
this._recycleNativeView = typeof value === "boolean" ? value : booleanConverter(value);
225+
set recycleNativeView(value: any) {
226+
// this._recycleNativeView = typeof value === "boolean" ? value : booleanConverter(value);
225227
}
226228

227229
get style(): Style {
@@ -670,16 +672,17 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
670672
}
671673

672674
private resetNativeViewInternal(): void {
673-
const nativeView = this.nativeView;
674-
if (nativeView && this._recycleNativeView && isAndroid) {
675-
resetNativeView(this);
676-
if (this._isPaddingRelative) {
677-
nativeView.setPaddingRelative(this._defaultPaddingLeft, this._defaultPaddingTop, this._defaultPaddingRight, this._defaultPaddingBottom);
678-
} else {
679-
nativeView.setPadding(this._defaultPaddingLeft, this._defaultPaddingTop, this._defaultPaddingRight, this._defaultPaddingBottom);
680-
}
681-
this.resetNativeView();
682-
}
675+
// Disable view recycling
676+
// const nativeView = this.nativeView;
677+
// if (nativeView && this._recycleNativeView && isAndroid) {
678+
// resetNativeView(this);
679+
// if (this._isPaddingRelative) {
680+
// nativeView.setPaddingRelative(this._defaultPaddingLeft, this._defaultPaddingTop, this._defaultPaddingRight, this._defaultPaddingBottom);
681+
// } else {
682+
// nativeView.setPadding(this._defaultPaddingLeft, this._defaultPaddingTop, this._defaultPaddingRight, this._defaultPaddingBottom);
683+
// }
684+
// this.resetNativeView();
685+
// }
683686
if (this._cssState) {
684687
this._cancelAllAnimations();
685688
}
@@ -702,9 +705,10 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
702705

703706
let nativeView;
704707
if (isAndroid) {
705-
if (this._recycleNativeView) {
706-
nativeView = <android.view.View>getNativeView(context, this.typeName);
707-
}
708+
// Disable view recycling
709+
// if (this._recycleNativeView) {
710+
// nativeView = <android.view.View>getNativeView(context, this.typeName);
711+
// }
708712

709713
if (!nativeView) {
710714
nativeView = <android.view.View>this.createNativeView();
@@ -805,13 +809,14 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
805809
this.parent._removeViewFromNativeVisualTree(this);
806810
}
807811

808-
const nativeView = this.nativeView;
809-
if (nativeView && this._recycleNativeView && isAndroid) {
810-
const nativeParent = isAndroid ? (<android.view.View>nativeView).getParent() : (<UIView>nativeView).superview;
811-
if (!nativeParent) {
812-
putNativeView(this._context, this);
813-
}
814-
}
812+
// Disable view recycling
813+
// const nativeView = this.nativeView;
814+
// if (nativeView && this._recycleNativeView && isAndroid) {
815+
// const nativeParent = isAndroid ? (<android.view.View>nativeView).getParent() : (<UIView>nativeView).superview;
816+
// if (!nativeParent) {
817+
// putNativeView(this._context, this);
818+
// }
819+
// }
815820

816821
this.disposeNativeView();
817822

0 commit comments

Comments
 (0)