mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
recycling now happens only if nativeView and android properties are not accessed. (#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.
This commit is contained in:
@@ -18,4 +18,4 @@ export abstract class ButtonBase extends TextBase implements ButtonDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
ButtonBase.prototype.recycleNativeView = true;
|
||||
ButtonBase.prototype.recycleNativeView = "auto";
|
||||
@@ -39,7 +39,7 @@ function initializeClickListener(): void {
|
||||
}
|
||||
|
||||
export class Button extends ButtonBase {
|
||||
nativeView: android.widget.Button;
|
||||
nativeViewProtected: android.widget.Button;
|
||||
|
||||
private _stateListAnimator: any;
|
||||
private _highlightedHandler: (args: TouchGestureEventData) => void;
|
||||
@@ -55,13 +55,13 @@ export class Button extends ButtonBase {
|
||||
}
|
||||
|
||||
public initNativeView(): void {
|
||||
const nativeView = this.nativeView;
|
||||
const nativeView = this.nativeViewProtected;
|
||||
(<any>nativeView).clickListener.owner = this;
|
||||
super.initNativeView();
|
||||
}
|
||||
|
||||
public disposeNativeView() {
|
||||
(<any>this.nativeView).clickListener.owner = null;
|
||||
(<any>this.nativeViewProtected).clickListener.owner = null;
|
||||
super.disposeNativeView();
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ export class Button extends ButtonBase {
|
||||
super.resetNativeView();
|
||||
|
||||
if (this._stateListAnimator && APILEVEL >= 21) {
|
||||
(<any>this.nativeView).setStateListAnimator(this._stateListAnimator);
|
||||
(<any>this.nativeViewProtected).setStateListAnimator(this._stateListAnimator);
|
||||
this._stateListAnimator = undefined;
|
||||
}
|
||||
}
|
||||
@@ -97,41 +97,41 @@ export class Button extends ButtonBase {
|
||||
return { value: this._defaultPaddingTop, unit: "px" }
|
||||
}
|
||||
[paddingTopProperty.setNative](value: Length) {
|
||||
org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0));
|
||||
org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0));
|
||||
}
|
||||
|
||||
[paddingRightProperty.getDefault](): Length {
|
||||
return { value: this._defaultPaddingRight, unit: "px" }
|
||||
}
|
||||
[paddingRightProperty.setNative](value: Length) {
|
||||
org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0));
|
||||
org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0));
|
||||
}
|
||||
|
||||
[paddingBottomProperty.getDefault](): Length {
|
||||
return { value: this._defaultPaddingBottom, unit: "px" }
|
||||
}
|
||||
[paddingBottomProperty.setNative](value: Length) {
|
||||
org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0));
|
||||
org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0));
|
||||
}
|
||||
|
||||
[paddingLeftProperty.getDefault](): Length {
|
||||
return { value: this._defaultPaddingLeft, unit: "px" }
|
||||
}
|
||||
[paddingLeftProperty.setNative](value: Length) {
|
||||
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));
|
||||
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));
|
||||
}
|
||||
|
||||
[zIndexProperty.setNative](value: number) {
|
||||
// API >= 21
|
||||
if (APILEVEL >= 21) {
|
||||
const nativeView = this.nativeView;
|
||||
const nativeView = this.nativeViewProtected;
|
||||
if (!this._stateListAnimator) {
|
||||
this._stateListAnimator = (<any>nativeView).getStateListAnimator();
|
||||
}
|
||||
(<any>nativeView).setStateListAnimator(null);
|
||||
}
|
||||
|
||||
org.nativescript.widgets.ViewHelper.setZIndex(this.nativeView, value);
|
||||
org.nativescript.widgets.ViewHelper.setZIndex(this.nativeViewProtected, value);
|
||||
}
|
||||
|
||||
[textAlignmentProperty.setNative](value: TextAlignment) {
|
||||
|
||||
@@ -9,21 +9,21 @@ import {
|
||||
export * from "./button-common";
|
||||
|
||||
export class Button extends ButtonBase {
|
||||
public nativeView: UIButton;
|
||||
public nativeViewProtected: UIButton;
|
||||
|
||||
private _tapHandler: NSObject;
|
||||
private _stateChangedHandler: ControlStateChangeListener;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.nativeView = UIButton.buttonWithType(UIButtonType.System);
|
||||
this.nativeViewProtected = UIButton.buttonWithType(UIButtonType.System);
|
||||
|
||||
this._tapHandler = TapHandlerImpl.initWithOwner(new WeakRef(this));
|
||||
this.nativeView.addTargetActionForControlEvents(this._tapHandler, "tap", UIControlEvents.TouchUpInside);
|
||||
this.nativeViewProtected.addTargetActionForControlEvents(this._tapHandler, "tap", UIControlEvents.TouchUpInside);
|
||||
}
|
||||
|
||||
get ios() {
|
||||
return this.nativeView;
|
||||
return this.nativeViewProtected;
|
||||
}
|
||||
|
||||
public onUnloaded() {
|
||||
@@ -37,7 +37,7 @@ export class Button extends ButtonBase {
|
||||
_updateHandler(subscribe: boolean) {
|
||||
if (subscribe) {
|
||||
if (!this._stateChangedHandler) {
|
||||
this._stateChangedHandler = new ControlStateChangeListener(this.nativeView, (s: string) => {
|
||||
this._stateChangedHandler = new ControlStateChangeListener(this.nativeViewProtected, (s: string) => {
|
||||
this._goToVisualState(s);
|
||||
});
|
||||
}
|
||||
@@ -49,120 +49,120 @@ export class Button extends ButtonBase {
|
||||
|
||||
[borderTopWidthProperty.getDefault](): Length {
|
||||
return {
|
||||
value: this.nativeView.contentEdgeInsets.top,
|
||||
value: this.nativeViewProtected.contentEdgeInsets.top,
|
||||
unit: "px"
|
||||
};
|
||||
}
|
||||
[borderTopWidthProperty.setNative](value: Length) {
|
||||
let inset = this.nativeView.contentEdgeInsets;
|
||||
let inset = this.nativeViewProtected.contentEdgeInsets;
|
||||
let top = layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth);
|
||||
this.nativeView.contentEdgeInsets = { top: top, left: inset.left, bottom: inset.bottom, right: inset.right };
|
||||
this.nativeViewProtected.contentEdgeInsets = { top: top, left: inset.left, bottom: inset.bottom, right: inset.right };
|
||||
}
|
||||
|
||||
[borderRightWidthProperty.getDefault](): Length {
|
||||
return {
|
||||
value: this.nativeView.contentEdgeInsets.right,
|
||||
value: this.nativeViewProtected.contentEdgeInsets.right,
|
||||
unit: "px"
|
||||
};
|
||||
}
|
||||
[borderRightWidthProperty.setNative](value: Length) {
|
||||
let inset = this.nativeView.contentEdgeInsets;
|
||||
let inset = this.nativeViewProtected.contentEdgeInsets;
|
||||
let right = layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth);
|
||||
this.nativeView.contentEdgeInsets = { top: inset.top, left: inset.left, bottom: inset.bottom, right: right };
|
||||
this.nativeViewProtected.contentEdgeInsets = { top: inset.top, left: inset.left, bottom: inset.bottom, right: right };
|
||||
}
|
||||
|
||||
[borderBottomWidthProperty.getDefault](): Length {
|
||||
return {
|
||||
value: this.nativeView.contentEdgeInsets.bottom,
|
||||
value: this.nativeViewProtected.contentEdgeInsets.bottom,
|
||||
unit: "px"
|
||||
};
|
||||
}
|
||||
[borderBottomWidthProperty.setNative](value: Length) {
|
||||
let inset = this.nativeView.contentEdgeInsets;
|
||||
let inset = this.nativeViewProtected.contentEdgeInsets;
|
||||
let bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth);
|
||||
this.nativeView.contentEdgeInsets = { top: inset.top, left: inset.left, bottom: bottom, right: inset.right };
|
||||
this.nativeViewProtected.contentEdgeInsets = { top: inset.top, left: inset.left, bottom: bottom, right: inset.right };
|
||||
}
|
||||
|
||||
[borderLeftWidthProperty.getDefault](): Length {
|
||||
return {
|
||||
value: this.nativeView.contentEdgeInsets.left,
|
||||
value: this.nativeViewProtected.contentEdgeInsets.left,
|
||||
unit: "px"
|
||||
};
|
||||
}
|
||||
[borderLeftWidthProperty.setNative](value: Length) {
|
||||
let inset = this.nativeView.contentEdgeInsets;
|
||||
let inset = this.nativeViewProtected.contentEdgeInsets;
|
||||
let left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth);
|
||||
this.nativeView.contentEdgeInsets = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right };
|
||||
this.nativeViewProtected.contentEdgeInsets = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right };
|
||||
}
|
||||
|
||||
[paddingTopProperty.getDefault](): Length {
|
||||
return {
|
||||
value: this.nativeView.contentEdgeInsets.top,
|
||||
value: this.nativeViewProtected.contentEdgeInsets.top,
|
||||
unit: "px"
|
||||
};
|
||||
}
|
||||
[paddingTopProperty.setNative](value: Length) {
|
||||
let inset = this.nativeView.contentEdgeInsets;
|
||||
let inset = this.nativeViewProtected.contentEdgeInsets;
|
||||
let top = layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth);
|
||||
this.nativeView.contentEdgeInsets = { top: top, left: inset.left, bottom: inset.bottom, right: inset.right };
|
||||
this.nativeViewProtected.contentEdgeInsets = { top: top, left: inset.left, bottom: inset.bottom, right: inset.right };
|
||||
}
|
||||
|
||||
[paddingRightProperty.getDefault](): Length {
|
||||
return {
|
||||
value: this.nativeView.contentEdgeInsets.right,
|
||||
value: this.nativeViewProtected.contentEdgeInsets.right,
|
||||
unit: "px"
|
||||
};
|
||||
}
|
||||
[paddingRightProperty.setNative](value: Length) {
|
||||
let inset = this.nativeView.contentEdgeInsets;
|
||||
let inset = this.nativeViewProtected.contentEdgeInsets;
|
||||
let right = layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth);
|
||||
this.nativeView.contentEdgeInsets = { top: inset.top, left: inset.left, bottom: inset.bottom, right: right };
|
||||
this.nativeViewProtected.contentEdgeInsets = { top: inset.top, left: inset.left, bottom: inset.bottom, right: right };
|
||||
}
|
||||
|
||||
[paddingBottomProperty.getDefault](): Length {
|
||||
return {
|
||||
value: this.nativeView.contentEdgeInsets.bottom,
|
||||
value: this.nativeViewProtected.contentEdgeInsets.bottom,
|
||||
unit: "px"
|
||||
};
|
||||
}
|
||||
[paddingBottomProperty.setNative](value: Length) {
|
||||
let inset = this.nativeView.contentEdgeInsets;
|
||||
let inset = this.nativeViewProtected.contentEdgeInsets;
|
||||
let bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth);
|
||||
this.nativeView.contentEdgeInsets = { top: inset.top, left: inset.left, bottom: bottom, right: inset.right };
|
||||
this.nativeViewProtected.contentEdgeInsets = { top: inset.top, left: inset.left, bottom: bottom, right: inset.right };
|
||||
}
|
||||
|
||||
[paddingLeftProperty.getDefault](): Length {
|
||||
return {
|
||||
value: this.nativeView.contentEdgeInsets.left,
|
||||
value: this.nativeViewProtected.contentEdgeInsets.left,
|
||||
unit: "px"
|
||||
};
|
||||
}
|
||||
[paddingLeftProperty.setNative](value: Length) {
|
||||
let inset = this.nativeView.contentEdgeInsets;
|
||||
let inset = this.nativeViewProtected.contentEdgeInsets;
|
||||
let left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth);
|
||||
this.nativeView.contentEdgeInsets = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right };
|
||||
this.nativeViewProtected.contentEdgeInsets = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right };
|
||||
}
|
||||
|
||||
[textAlignmentProperty.setNative](value: TextAlignment) {
|
||||
switch (value) {
|
||||
case "left":
|
||||
this.nativeView.titleLabel.textAlignment = NSTextAlignment.Left;
|
||||
this.nativeView.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left;
|
||||
this.nativeViewProtected.titleLabel.textAlignment = NSTextAlignment.Left;
|
||||
this.nativeViewProtected.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left;
|
||||
break;
|
||||
case "initial":
|
||||
case "center":
|
||||
this.nativeView.titleLabel.textAlignment = NSTextAlignment.Center;
|
||||
this.nativeView.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center;
|
||||
this.nativeViewProtected.titleLabel.textAlignment = NSTextAlignment.Center;
|
||||
this.nativeViewProtected.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center;
|
||||
break;
|
||||
case "right":
|
||||
this.nativeView.titleLabel.textAlignment = NSTextAlignment.Right;
|
||||
this.nativeView.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Right;
|
||||
this.nativeViewProtected.titleLabel.textAlignment = NSTextAlignment.Right;
|
||||
this.nativeViewProtected.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Right;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[whiteSpaceProperty.setNative](value: WhiteSpace) {
|
||||
const nativeView = this.nativeView.titleLabel;
|
||||
const nativeView = this.nativeViewProtected.titleLabel;
|
||||
switch (value) {
|
||||
case "normal":
|
||||
nativeView.lineBreakMode = NSLineBreakMode.ByWordWrapping;
|
||||
@@ -183,7 +183,7 @@ export class Button extends ButtonBase {
|
||||
return super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
}
|
||||
|
||||
let nativeView = this.nativeView;
|
||||
let nativeView = this.nativeViewProtected;
|
||||
if (nativeView) {
|
||||
const width = layout.getMeasureSpecSize(widthMeasureSpec);
|
||||
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
|
||||
|
||||
Reference in New Issue
Block a user