mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Disable view recycling
This commit is contained in:
@@ -241,59 +241,61 @@ let cssSetters: Map<string, any>;
|
||||
let defaultNativeGetters: Map<string, (view) => any>;
|
||||
|
||||
export function nativeView_recycling_test(createNew: () => View, createLayout?: () => LayoutBase, nativeGetters?: Map<string, (view) => any>, customSetters?: Map<string, any>) {
|
||||
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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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".
|
||||
|
||||
@@ -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 = <android.view.View>getNativeView(context, this.typeName);
|
||||
}
|
||||
// Disable view recycling
|
||||
// if (this._recycleNativeView) {
|
||||
// nativeView = <android.view.View>getNativeView(context, this.typeName);
|
||||
// }
|
||||
|
||||
if (!nativeView) {
|
||||
nativeView = <android.view.View>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 ? (<android.view.View>nativeView).getParent() : (<UIView>nativeView).superview;
|
||||
if (!nativeParent) {
|
||||
putNativeView(this._context, this);
|
||||
}
|
||||
}
|
||||
// Disable view recycling
|
||||
// const nativeView = this.nativeView;
|
||||
// if (nativeView && this._recycleNativeView && isAndroid) {
|
||||
// const nativeParent = isAndroid ? (<android.view.View>nativeView).getParent() : (<UIView>nativeView).superview;
|
||||
// if (!nativeParent) {
|
||||
// putNativeView(this._context, this);
|
||||
// }
|
||||
// }
|
||||
|
||||
this.disposeNativeView();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user