mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Enable recycling of nativeView 2 (#4467)
* enable recycling of nativeView * backgroundInternal is reset if setting new value leads to background.isEmpty() == true. * android background.getDefault always return copy of the background. Now all controls that mutate the background can be reset to initial state (e.g. Button & ActionBar) passing resources to copied background so it respect density. fix properties initNativeView * reset padding when backgroundInternal is reset. * Fix text reset Fix padding reset * fix tsc errors * fix ugly text rendering. * Add unit tests for recycling native views Fix several issues that came from the above tests Fix maxLength property missing a converter callback Remove old files * Remove old files * Revert backgroundInternal setter * change the order of tests so that appium can work again * Remove suggestion on every TextView & TextField init (strangely it is enabled after view is recycled....) * Fix function to get parent layout if specified * Button stateListAnimator restored when button is recycled zIndex defaultValue is now undefined instead of NaN * revert zIndex.setNative to always clear stateListAnimator because it was breaking one UI test (setting value=0 was returning the previous stateListAnimator) * fix search-bar backgound-color recycling * Fix alignments setters * Fix imageView recycling Fix button recycling Fix edit-text recycling resetNativeView is called only if recycleNativeView flag is true * Fix incorrect merge * Fix text-view & text-field textTransform * Fix EditText text reset * Fix runtime crash on ARM emulator API 21 * Fix text-base minHeight. maxHeight reset Fix reset of isUserInteractionEnabled
This commit is contained in:
committed by
GitHub
parent
b1432679e6
commit
23757e5dfc
@@ -269,9 +269,6 @@ export class View extends ViewCommon {
|
||||
return result | (childMeasuredState & layout.MEASURED_STATE_MASK);
|
||||
}
|
||||
|
||||
[isEnabledProperty.getDefault](): boolean {
|
||||
return this.nativeView.isEnabled();
|
||||
}
|
||||
[isEnabledProperty.setNative](value: boolean) {
|
||||
this.nativeView.setEnabled(value);
|
||||
}
|
||||
@@ -297,9 +294,6 @@ export class View extends ViewCommon {
|
||||
this.nativeView.setContentDescription(value);
|
||||
}
|
||||
|
||||
[isUserInteractionEnabledProperty.getDefault](): boolean {
|
||||
return true;
|
||||
}
|
||||
[isUserInteractionEnabledProperty.setNative](value: boolean) {
|
||||
if (!value) {
|
||||
initializeDisabledListener();
|
||||
@@ -307,6 +301,9 @@ export class View extends ViewCommon {
|
||||
this.nativeView.setOnTouchListener(disableUserInteractionListener);
|
||||
} else {
|
||||
this.setOnTouchListener();
|
||||
if (!this.touchListenerIsSet) {
|
||||
this.nativeView.setOnTouchListener(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,15 +354,27 @@ export class View extends ViewCommon {
|
||||
switch (value) {
|
||||
case "left":
|
||||
lp.gravity = android.view.Gravity.LEFT | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
||||
if (lp.weight < 0) {
|
||||
lp.weight = -2;
|
||||
}
|
||||
break;
|
||||
case "center":
|
||||
lp.gravity = android.view.Gravity.CENTER_HORIZONTAL | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
||||
if (lp.weight < 0) {
|
||||
lp.weight = -2;
|
||||
}
|
||||
break;
|
||||
case "right":
|
||||
lp.gravity = android.view.Gravity.RIGHT | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
||||
if (lp.weight < 0) {
|
||||
lp.weight = -2;
|
||||
}
|
||||
break;
|
||||
case "stretch":
|
||||
lp.gravity = android.view.Gravity.FILL_HORIZONTAL | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK);
|
||||
if (lp.weight < 0) {
|
||||
lp.weight = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
nativeView.setLayoutParams(lp);
|
||||
@@ -383,15 +392,27 @@ export class View extends ViewCommon {
|
||||
switch (value) {
|
||||
case "top":
|
||||
lp.gravity = android.view.Gravity.TOP | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
||||
if (lp.height < 0) {
|
||||
lp.height = -2;
|
||||
}
|
||||
break;
|
||||
case "middle":
|
||||
lp.gravity = android.view.Gravity.CENTER_VERTICAL | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
||||
if (lp.height < 0) {
|
||||
lp.height = -2;
|
||||
}
|
||||
break;
|
||||
case "bottom":
|
||||
lp.gravity = android.view.Gravity.BOTTOM | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
||||
if (lp.height < 0) {
|
||||
lp.height = -2;
|
||||
}
|
||||
break;
|
||||
case "stretch":
|
||||
lp.gravity = android.view.Gravity.FILL_VERTICAL | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK);
|
||||
if (lp.height < 0) {
|
||||
lp.height = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
nativeView.setLayoutParams(lp);
|
||||
@@ -419,14 +440,16 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[zIndexProperty.getDefault](): number {
|
||||
return org.nativescript.widgets.ViewHelper.getZIndex(this.nativeView);
|
||||
return 0;
|
||||
}
|
||||
[zIndexProperty.setNative](value: number) {
|
||||
org.nativescript.widgets.ViewHelper.setZIndex(this.nativeView, value);
|
||||
}
|
||||
|
||||
[backgroundInternalProperty.getDefault](): android.graphics.drawable.Drawable {
|
||||
return this.nativeView.getBackground();
|
||||
const nativeView = this.nativeView;
|
||||
const drawable = nativeView.getBackground();
|
||||
return drawable ? drawable.getConstantState().newDrawable(nativeView.getResources()) : null;
|
||||
}
|
||||
[backgroundInternalProperty.setNative](value: android.graphics.drawable.Drawable | Background) {
|
||||
this._redrawNativeBackground(value);
|
||||
@@ -449,10 +472,12 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
_redrawNativeBackground(value: android.graphics.drawable.Drawable | Background): void {
|
||||
if (value instanceof android.graphics.drawable.Drawable) {
|
||||
this.nativeView.setBackground(value);
|
||||
} else {
|
||||
if (value instanceof Background) {
|
||||
androidBackground.onBackgroundOrBorderPropertyChanged(this);
|
||||
} else {
|
||||
const nativeView = this.nativeView;
|
||||
org.nativescript.widgets.ViewHelper.setBackground(nativeView, value);
|
||||
nativeView.setPadding(this._defaultPaddingLeft, this._defaultPaddingTop, this._defaultPaddingRight, this._defaultPaddingBottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -497,10 +522,12 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
|
||||
public _removeViewFromNativeVisualTree(child: ViewCommon): void {
|
||||
super._removeViewFromNativeVisualTree(child);
|
||||
|
||||
if (this.nativeView && child.nativeView) {
|
||||
this.nativeView.removeView(child.nativeView);
|
||||
const nativeView = this.nativeView;
|
||||
const childView = child.nativeView;
|
||||
if (nativeView && childView) {
|
||||
nativeView.removeView(childView);
|
||||
if (traceEnabled()) {
|
||||
traceWrite(`${this}.nativeView.removeView(${child}.nativeView)`, traceCategories.VisualTreeEvents);
|
||||
traceWrite(`${nativeView}.removeView(${childView})`, traceCategories.VisualTreeEvents);
|
||||
traceNotifyEvent(child, "childInLayoutRemovedFromNativeVisualTree");
|
||||
}
|
||||
}
|
||||
@@ -523,7 +550,7 @@ function createNativePercentLengthProperty(options: NativePercentLengthPropertyO
|
||||
const { getter, setter, auto = 0 } = options;
|
||||
let setPixels, getPixels, setPercent;
|
||||
if (getter) {
|
||||
View.prototype[getter] = function(this: View): PercentLength {
|
||||
View.prototype[getter] = function (this: View): PercentLength {
|
||||
if (options) {
|
||||
setPixels = options.setPixels;
|
||||
getPixels = options.getPixels;
|
||||
@@ -539,7 +566,7 @@ function createNativePercentLengthProperty(options: NativePercentLengthPropertyO
|
||||
}
|
||||
}
|
||||
if (setter) {
|
||||
View.prototype[setter] = function(this: View, length: PercentLength) {
|
||||
View.prototype[setter] = function (this: View, length: PercentLength) {
|
||||
if (options) {
|
||||
setPixels = options.setPixels;
|
||||
getPixels = options.getPixels;
|
||||
@@ -564,51 +591,39 @@ function createNativePercentLengthProperty(options: NativePercentLengthPropertyO
|
||||
}
|
||||
|
||||
createNativePercentLengthProperty({
|
||||
getter: marginTopProperty.getDefault,
|
||||
setter: marginTopProperty.setNative,
|
||||
get getPixels() { return org.nativescript.widgets.ViewHelper.getMarginTop },
|
||||
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginTop },
|
||||
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginTopPercent }
|
||||
});
|
||||
|
||||
createNativePercentLengthProperty({
|
||||
getter: marginRightProperty.getDefault,
|
||||
setter: marginRightProperty.setNative,
|
||||
get getPixels() { return org.nativescript.widgets.ViewHelper.getMarginRight },
|
||||
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginRight },
|
||||
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginRightPercent }
|
||||
});
|
||||
|
||||
createNativePercentLengthProperty({
|
||||
getter: marginBottomProperty.getDefault,
|
||||
setter: marginBottomProperty.setNative,
|
||||
get getPixels() { return org.nativescript.widgets.ViewHelper.getMarginBottom },
|
||||
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginBottom },
|
||||
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginBottomPercent }
|
||||
});
|
||||
|
||||
createNativePercentLengthProperty({
|
||||
getter: marginLeftProperty.getDefault,
|
||||
setter: marginLeftProperty.setNative,
|
||||
get getPixels() { return org.nativescript.widgets.ViewHelper.getMarginLeft },
|
||||
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginLeft },
|
||||
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginLeftPercent }
|
||||
});
|
||||
|
||||
createNativePercentLengthProperty({
|
||||
getter: widthProperty.getDefault,
|
||||
setter: widthProperty.setNative,
|
||||
auto: -1, //android.view.ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
get getPixels() { return org.nativescript.widgets.ViewHelper.getWidth },
|
||||
get setPixels() { return org.nativescript.widgets.ViewHelper.setWidth },
|
||||
get setPercent() { return org.nativescript.widgets.ViewHelper.setWidthPercent }
|
||||
});
|
||||
|
||||
createNativePercentLengthProperty({
|
||||
getter: heightProperty.getDefault,
|
||||
setter: heightProperty.setNative,
|
||||
auto: -1, //android.view.ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
get getPixels() { return org.nativescript.widgets.ViewHelper.getHeight },
|
||||
get setPixels() { return org.nativescript.widgets.ViewHelper.setHeight },
|
||||
get setPercent() { return org.nativescript.widgets.ViewHelper.setHeightPercent }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user