From 7c8aa12d8c116444516b30815775808e33de1e7f Mon Sep 17 00:00:00 2001 From: vakrilov Date: Tue, 1 Aug 2017 16:28:58 +0300 Subject: [PATCH] Disable view recycling --- tests/app/ui/helper.ts | 86 ++++++++++--------- tests/app/ui/view/view-tests-common.ts | 51 +++++------ .../ui/core/view-base/view-base.d.ts | 4 +- .../ui/core/view-base/view-base.ts | 57 ++++++------ 4 files changed, 104 insertions(+), 94 deletions(-) diff --git a/tests/app/ui/helper.ts b/tests/app/ui/helper.ts index 6469bc9ba..a85c2df7e 100644 --- a/tests/app/ui/helper.ts +++ b/tests/app/ui/helper.ts @@ -241,59 +241,61 @@ let cssSetters: Map; let defaultNativeGetters: Map any>; export function nativeView_recycling_test(createNew: () => View, createLayout?: () => LayoutBase, nativeGetters?: Map any>, customSetters?: Map) { - if (isIOS) { - // recycling not implemented yet. - return; - } + return; - setupSetters(); - const page = getClearCurrentPage(); - let layout: LayoutBase = new FlexboxLayout(); - if (createLayout) { - // This is done on purpose. We need the constructor of Flexbox - // to run otherwise some module fileds stays uninitialized. - layout = createLayout(); - } + // if (isIOS) { + // // recycling not implemented yet. + // return; + // } - page.content = layout; + // setupSetters(); + // const page = getClearCurrentPage(); + // let layout: LayoutBase = new FlexboxLayout(); + // if (createLayout) { + // // This is done on purpose. We need the constructor of Flexbox + // // to run otherwise some module fileds stays uninitialized. + // layout = createLayout(); + // } - const first = createNew(); - const test = createNew(); + // page.content = layout; - // Make sure we are not reusing a native views. - first.recycleNativeView = false; - test.recycleNativeView = false; + // const first = createNew(); + // const test = createNew(); - page.content = layout; + // // Make sure we are not reusing a native views. + // first.recycleNativeView = false; + // test.recycleNativeView = false; - layout.addChild(test); + // page.content = layout; - setValue(test.style, cssSetters); - setValue(test, setters, customSetters); - // Needed so we can reset formattedText - test["secure"] = false; + // layout.addChild(test); - const nativeView = test.nativeView; - // Mark so we reuse the native views. - test.recycleNativeView = true; - layout.removeChild(test); - const newer = createNew(); - newer.recycleNativeView = true; - layout.addChild(newer); - layout.addChild(first); + // setValue(test.style, cssSetters); + // setValue(test, setters, customSetters); + // // Needed so we can reset formattedText + // test["secure"] = false; - if (first.typeName !== "SearchBar" && sdkVersion > 19) { - // There are way too many differences in native methods for search-bar. - // There are too many methods that just throw for newly created views in API lvl 19 and 17 - compareUsingReflection(newer, first); - } + // const nativeView = test.nativeView; + // // Mark so we reuse the native views. + // test.recycleNativeView = true; + // layout.removeChild(test); + // const newer = createNew(); + // newer.recycleNativeView = true; + // layout.addChild(newer); + // layout.addChild(first); - TKUnit.assertEqual(newer.nativeView, nativeView, "nativeView not reused."); - checkDefaults(newer, first, props, nativeGetters || defaultNativeGetters); - checkDefaults(newer, first, styleProps, nativeGetters || defaultNativeGetters); + // if (first.typeName !== "SearchBar" && sdkVersion > 19) { + // // There are way too many differences in native methods for search-bar. + // // There are too many methods that just throw for newly created views in API lvl 19 and 17 + // compareUsingReflection(newer, first); + // } - layout.removeChild(newer); - layout.removeChild(first); + // TKUnit.assertEqual(newer.nativeView, nativeView, "nativeView not reused."); + // checkDefaults(newer, first, props, nativeGetters || defaultNativeGetters); + // checkDefaults(newer, first, styleProps, nativeGetters || defaultNativeGetters); + + // layout.removeChild(newer); + // layout.removeChild(first); } function compareUsingReflection(recycledNativeView: View, newNativeView: View): void { diff --git a/tests/app/ui/view/view-tests-common.ts b/tests/app/ui/view/view-tests-common.ts index 9e67ad9d2..70fdc7b83 100644 --- a/tests/app/ui/view/view-tests-common.ts +++ b/tests/app/ui/view/view-tests-common.ts @@ -575,36 +575,37 @@ 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.customCssProperty = "testCssValue"; - secondView.custom = "testViewValue"; +// Disable view recycling +// 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.customCssProperty = "testCssValue"; +// secondView.custom = "testViewValue"; - helper.buildUIAndRunTest(firstView, () => { - TKUnit.assertEqual(secondView.cssPropCounter, 0, "1"); - TKUnit.assertEqual(secondView.viewPropCounter, 0, "2"); +// helper.buildUIAndRunTest(firstView, () => { +// TKUnit.assertEqual(secondView.cssPropCounter, 0, "1"); +// TKUnit.assertEqual(secondView.viewPropCounter, 0, "2"); - // Add to visual tree - firstView.addChild(secondView); - TKUnit.assertEqual(secondView.cssPropCounter, 1, "3"); - TKUnit.assertEqual(secondView.viewPropCounter, 1, "4"); +// // Add to visual tree +// firstView.addChild(secondView); +// TKUnit.assertEqual(secondView.cssPropCounter, 1, "3"); +// TKUnit.assertEqual(secondView.viewPropCounter, 1, "4"); - // Set new value - secondView.customCssProperty = "test2"; - secondView.custom = "test2"; - TKUnit.assertEqual(secondView.cssPropCounter, 2, "5"); - TKUnit.assertEqual(secondView.viewPropCounter, 2, "6"); +// // Set new value +// secondView.customCssProperty = "test2"; +// secondView.custom = "test2"; +// TKUnit.assertEqual(secondView.cssPropCounter, 2, "5"); +// TKUnit.assertEqual(secondView.viewPropCounter, 2, "6"); - // Remove from visual tree - firstView.removeChild(secondView); +// // Remove from visual tree +// firstView.removeChild(secondView); - // we don't recycle nativeViews on iOS yet so reset is not called. - TKUnit.assertEqual(secondView.cssPropCounter, isIOS ? 2 : 3, "7"); - TKUnit.assertEqual(secondView.viewPropCounter, isIOS ? 2 : 3, "8"); - }); -}; +// // we don't recycle nativeViews on iOS yet so reset is not called. +// TKUnit.assertEqual(secondView.cssPropCounter, isIOS ? 2 : 3, "7"); +// TKUnit.assertEqual(secondView.viewPropCounter, isIOS ? 2 : 3, "8"); +// }); +// }; export function test_InheritableProperties_getValuesFromParent() { const testValue = 35; diff --git a/tns-core-modules/ui/core/view-base/view-base.d.ts b/tns-core-modules/ui/core/view-base/view-base.d.ts index 9aac73100..c4776221e 100644 --- a/tns-core-modules/ui/core/view-base/view-base.d.ts +++ b/tns-core-modules/ui/core/view-base/view-base.d.ts @@ -146,7 +146,9 @@ export abstract class ViewBase extends Observable { public nativeView: any; public bindingContext: any; - public recycleNativeView: boolean; + + // Reserved for future use. Currently not used + public recycleNativeView: any; /** * Gets the name of the constructor function for this instance. E.g. for a Button class this will return "Button". diff --git a/tns-core-modules/ui/core/view-base/view-base.ts b/tns-core-modules/ui/core/view-base/view-base.ts index 830622fa7..1e3dcd017 100644 --- a/tns-core-modules/ui/core/view-base/view-base.ts +++ b/tns-core-modules/ui/core/view-base/view-base.ts @@ -133,7 +133,8 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition public static loadedEvent = "loaded"; public static unloadedEvent = "unloaded"; - private _recycleNativeView: boolean; + // Disable view recycling + // private _recycleNativeView: boolean; private _iosView: Object; private _androidView: Object; private _style: Style; @@ -216,12 +217,13 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition return types.getClass(this); } - get recycleNativeView(): boolean { - return this._recycleNativeView; + // Disable view recycling + get recycleNativeView(): any { + // return this._recycleNativeView; + return false; } - - set recycleNativeView(value: boolean) { - this._recycleNativeView = typeof value === "boolean" ? value : booleanConverter(value); + set recycleNativeView(value: any) { + // this._recycleNativeView = typeof value === "boolean" ? value : booleanConverter(value); } get style(): Style { @@ -670,16 +672,17 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition } private resetNativeViewInternal(): void { - const nativeView = this.nativeView; - if (nativeView && this._recycleNativeView && isAndroid) { - resetNativeView(this); - if (this._isPaddingRelative) { - nativeView.setPaddingRelative(this._defaultPaddingLeft, this._defaultPaddingTop, this._defaultPaddingRight, this._defaultPaddingBottom); - } else { - nativeView.setPadding(this._defaultPaddingLeft, this._defaultPaddingTop, this._defaultPaddingRight, this._defaultPaddingBottom); - } - this.resetNativeView(); - } + // Disable view recycling + // const nativeView = this.nativeView; + // if (nativeView && this._recycleNativeView && isAndroid) { + // resetNativeView(this); + // if (this._isPaddingRelative) { + // nativeView.setPaddingRelative(this._defaultPaddingLeft, this._defaultPaddingTop, this._defaultPaddingRight, this._defaultPaddingBottom); + // } else { + // nativeView.setPadding(this._defaultPaddingLeft, this._defaultPaddingTop, this._defaultPaddingRight, this._defaultPaddingBottom); + // } + // this.resetNativeView(); + // } if (this._cssState) { this._cancelAllAnimations(); } @@ -702,9 +705,10 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition let nativeView; if (isAndroid) { - if (this._recycleNativeView) { - nativeView = getNativeView(context, this.typeName); - } + // Disable view recycling + // if (this._recycleNativeView) { + // nativeView = getNativeView(context, this.typeName); + // } if (!nativeView) { nativeView = this.createNativeView(); @@ -805,13 +809,14 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition this.parent._removeViewFromNativeVisualTree(this); } - const nativeView = this.nativeView; - if (nativeView && this._recycleNativeView && isAndroid) { - const nativeParent = isAndroid ? (nativeView).getParent() : (nativeView).superview; - if (!nativeParent) { - putNativeView(this._context, this); - } - } + // Disable view recycling + // const nativeView = this.nativeView; + // if (nativeView && this._recycleNativeView && isAndroid) { + // const nativeParent = isAndroid ? (nativeView).getParent() : (nativeView).superview; + // if (!nativeParent) { + // putNativeView(this._context, this); + // } + // } this.disposeNativeView();