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:
@@ -191,7 +191,7 @@ export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor<
|
||||
valueChanged(owner, oldValue, value);
|
||||
}
|
||||
|
||||
if (owner.nativeView && !(defaultValueKey in owner)) {
|
||||
if (owner.nativeViewProtected && !(defaultValueKey in owner)) {
|
||||
owner[defaultValueKey] = owner[getDefault] ? owner[getDefault]() : defaultValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,11 +143,12 @@ export abstract class ViewBase extends Observable {
|
||||
/**
|
||||
* read-only. If you want to set out-of-band the nativeView use the setNativeView method.
|
||||
*/
|
||||
public nativeViewProtected: any;
|
||||
public recycleNativeView: "always" | "never" | "auto";
|
||||
|
||||
public nativeView: any;
|
||||
|
||||
public bindingContext: any;
|
||||
public recycleNativeView: boolean;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the name of the constructor function for this instance. E.g. for a Button class this will return "Button".
|
||||
*/
|
||||
|
||||
@@ -126,14 +126,13 @@ function putNativeView(context: Object, view: ViewBase): void {
|
||||
list = [];
|
||||
typeMap.set(typeName, list);
|
||||
}
|
||||
list.push(new WeakRef(view.nativeView));
|
||||
list.push(new WeakRef(view.nativeViewProtected));
|
||||
}
|
||||
|
||||
export abstract class ViewBase extends Observable implements ViewBaseDefinition {
|
||||
public static loadedEvent = "loaded";
|
||||
public static unloadedEvent = "unloaded";
|
||||
|
||||
private _recycleNativeView: boolean;
|
||||
private _iosView: Object;
|
||||
private _androidView: Object;
|
||||
private _style: Style;
|
||||
@@ -142,10 +141,12 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
||||
private _visualState: string;
|
||||
private _inlineStyleSelector: SelectorCore;
|
||||
private __nativeView: any;
|
||||
private _disableNativeViewRecycling: boolean;
|
||||
public domNode: DOMNode;
|
||||
|
||||
public recycleNativeView: "always" | "never" | "auto";
|
||||
public bindingContext: any;
|
||||
public nativeView: any;
|
||||
public nativeViewProtected: any;
|
||||
public parent: ViewBase;
|
||||
public isCollapsed; // Default(false) set in prototype
|
||||
|
||||
@@ -211,19 +212,16 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
||||
this._style = new Style(this);
|
||||
}
|
||||
|
||||
get nativeView(): any {
|
||||
this._disableNativeViewRecycling = true;
|
||||
return this.nativeViewProtected;
|
||||
}
|
||||
|
||||
// TODO: Use Type.prototype.typeName instead.
|
||||
get typeName(): string {
|
||||
return types.getClass(this);
|
||||
}
|
||||
|
||||
get recycleNativeView(): boolean {
|
||||
return this._recycleNativeView;
|
||||
}
|
||||
|
||||
set recycleNativeView(value: boolean) {
|
||||
this._recycleNativeView = typeof value === "boolean" ? value : booleanConverter(value);
|
||||
}
|
||||
|
||||
get style(): Style {
|
||||
return this._style;
|
||||
}
|
||||
@@ -232,10 +230,12 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
||||
}
|
||||
|
||||
get android(): any {
|
||||
this._disableNativeViewRecycling = true;
|
||||
return this._androidView;
|
||||
}
|
||||
|
||||
get ios(): any {
|
||||
// this._disableNativeViewRecycling = true;
|
||||
return this._iosView;
|
||||
}
|
||||
|
||||
@@ -638,7 +638,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
||||
if (this._styleScope === view._styleScope) {
|
||||
view._setStyleScope(null);
|
||||
}
|
||||
|
||||
|
||||
if (view.isLoaded) {
|
||||
view.onUnloaded();
|
||||
}
|
||||
@@ -670,16 +670,20 @@ 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);
|
||||
const nativeView = this.nativeViewProtected;
|
||||
if (nativeView && isAndroid) {
|
||||
const recycle = this.recycleNativeView;
|
||||
if (recycle === "always" || (recycle === "auto" && !this._disableNativeViewRecycling)) {
|
||||
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();
|
||||
}
|
||||
this.resetNativeView();
|
||||
}
|
||||
|
||||
if (this._cssState) {
|
||||
this._cancelAllAnimations();
|
||||
}
|
||||
@@ -702,7 +706,8 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
||||
|
||||
let nativeView;
|
||||
if (isAndroid) {
|
||||
if (this._recycleNativeView) {
|
||||
const recycle = this.recycleNativeView;
|
||||
if (recycle === "always" || (recycle === "auto" && !this._disableNativeViewRecycling)) {
|
||||
nativeView = <android.view.View>getNativeView(context, this.typeName);
|
||||
}
|
||||
|
||||
@@ -751,7 +756,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
||||
|
||||
// This will account for nativeView that is created in createNativeView, recycled
|
||||
// or for backward compatability - set before _setupUI in iOS contructor.
|
||||
this.setNativeView(nativeView || this.nativeView);
|
||||
this.setNativeView(nativeView || this.nativeViewProtected);
|
||||
|
||||
if (this.parent) {
|
||||
let nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex);
|
||||
@@ -775,7 +780,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
||||
this._suspendNativeUpdates();
|
||||
// We may do a `this.resetNativeView()` here?
|
||||
}
|
||||
this.__nativeView = this.nativeView = value;
|
||||
this.__nativeView = this.nativeViewProtected = value;
|
||||
if (this.__nativeView) {
|
||||
this._suspendedUpdates = undefined;
|
||||
this.initNativeView();
|
||||
@@ -805,11 +810,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);
|
||||
const nativeView = this.nativeViewProtected;
|
||||
if (nativeView && isAndroid) {
|
||||
const recycle = this.recycleNativeView;
|
||||
if (recycle === "always" || (recycle === "auto" && !this._disableNativeViewRecycling)) {
|
||||
const nativeParent = isAndroid ? (<android.view.View>nativeView).getParent() : (<UIView>nativeView).superview;
|
||||
if (!nativeParent) {
|
||||
putNativeView(this._context, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -961,6 +969,7 @@ ViewBase.prototype._defaultPaddingRight = 0;
|
||||
ViewBase.prototype._defaultPaddingBottom = 0;
|
||||
ViewBase.prototype._defaultPaddingLeft = 0;
|
||||
ViewBase.prototype._isViewBase = true;
|
||||
ViewBase.prototype.recycleNativeView = "never";
|
||||
|
||||
// Removing from visual tree does +1, adding to visual tree does -1, see parentChanged
|
||||
// Removing the nativeView does +1, adding the nativeView does -1, see set nativeView
|
||||
|
||||
@@ -59,7 +59,7 @@ function initializeTouchListener(): void {
|
||||
});
|
||||
}
|
||||
|
||||
let nativeView = owner.nativeView;
|
||||
let nativeView = owner.nativeViewProtected;
|
||||
if (!nativeView || !nativeView.onTouchEvent) {
|
||||
return false;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ export class View extends ViewCommon {
|
||||
private touchListenerIsSet: boolean;
|
||||
private touchListener: android.view.View.OnTouchListener;
|
||||
|
||||
nativeView: android.view.View;
|
||||
nativeViewProtected: android.view.View;
|
||||
|
||||
// TODO: Implement unobserve that detach the touchListener.
|
||||
observe(type: GestureTypes, callback: (args: GestureEventData) => void, thisArg?: any): void {
|
||||
@@ -95,9 +95,9 @@ export class View extends ViewCommon {
|
||||
@profile
|
||||
public onUnloaded() {
|
||||
if (this.touchListenerIsSet) {
|
||||
this.nativeView.setOnTouchListener(null);
|
||||
this.nativeViewProtected.setOnTouchListener(null);
|
||||
this.touchListenerIsSet = false;
|
||||
this.nativeView.setClickable(this._isClickable);
|
||||
this.nativeViewProtected.setClickable(this._isClickable);
|
||||
}
|
||||
|
||||
this._cancelAllAnimations();
|
||||
@@ -110,19 +110,19 @@ export class View extends ViewCommon {
|
||||
|
||||
public initNativeView(): void {
|
||||
super.initNativeView();
|
||||
this._isClickable = this.nativeView.isClickable();
|
||||
this._isClickable = this.nativeViewProtected.isClickable();
|
||||
}
|
||||
|
||||
private setOnTouchListener() {
|
||||
if (this.nativeView && this.hasGestureObservers()) {
|
||||
if (this.nativeViewProtected && this.hasGestureObservers()) {
|
||||
this.touchListenerIsSet = true;
|
||||
if (this.nativeView.setClickable) {
|
||||
this.nativeView.setClickable(true);
|
||||
if (this.nativeViewProtected.setClickable) {
|
||||
this.nativeViewProtected.setClickable(true);
|
||||
}
|
||||
|
||||
initializeTouchListener();
|
||||
this.touchListener = this.touchListener || new TouchListener(this);
|
||||
this.nativeView.setOnTouchListener(this.touchListener);
|
||||
this.nativeViewProtected.setOnTouchListener(this.touchListener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,24 +131,24 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
get isLayoutValid(): boolean {
|
||||
if (this.nativeView) {
|
||||
return !this.nativeView.isLayoutRequested();
|
||||
if (this.nativeViewProtected) {
|
||||
return !this.nativeViewProtected.isLayoutRequested();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
|
||||
if (this.nativeView) {
|
||||
this.nativeView.layout(left, top, right, bottom);
|
||||
if (this.nativeViewProtected) {
|
||||
this.nativeViewProtected.layout(left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@profile
|
||||
public requestLayout(): void {
|
||||
super.requestLayout();
|
||||
if (this.nativeView) {
|
||||
return this.nativeView.requestLayout();
|
||||
if (this.nativeViewProtected) {
|
||||
return this.nativeViewProtected.requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
let view = this.nativeView;
|
||||
let view = this.nativeViewProtected;
|
||||
if (view) {
|
||||
view.measure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.setMeasuredDimension(view.getMeasuredWidth(), view.getMeasuredHeight());
|
||||
@@ -171,19 +171,19 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
let view = this.nativeView;
|
||||
let view = this.nativeViewProtected;
|
||||
if (view) {
|
||||
this.layoutNativeView(left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
_getCurrentLayoutBounds(): { left: number; top: number; right: number; bottom: number } {
|
||||
if (this.nativeView && !this.isCollapsed) {
|
||||
if (this.nativeViewProtected && !this.isCollapsed) {
|
||||
return {
|
||||
left: this.nativeView.getLeft(),
|
||||
top: this.nativeView.getTop(),
|
||||
right: this.nativeView.getRight(),
|
||||
bottom: this.nativeView.getBottom()
|
||||
left: this.nativeViewProtected.getLeft(),
|
||||
top: this.nativeViewProtected.getTop(),
|
||||
right: this.nativeViewProtected.getRight(),
|
||||
bottom: this.nativeViewProtected.getBottom()
|
||||
};
|
||||
} else {
|
||||
return { left: 0, top: 0, right: 0, bottom: 0 };
|
||||
@@ -191,36 +191,36 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
public getMeasuredWidth(): number {
|
||||
if (this.nativeView) {
|
||||
return this.nativeView.getMeasuredWidth();
|
||||
if (this.nativeViewProtected) {
|
||||
return this.nativeViewProtected.getMeasuredWidth();
|
||||
}
|
||||
|
||||
return super.getMeasuredWidth();
|
||||
}
|
||||
|
||||
public getMeasuredHeight(): number {
|
||||
if (this.nativeView) {
|
||||
return this.nativeView.getMeasuredHeight();
|
||||
if (this.nativeViewProtected) {
|
||||
return this.nativeViewProtected.getMeasuredHeight();
|
||||
}
|
||||
|
||||
return super.getMeasuredHeight();
|
||||
}
|
||||
|
||||
public focus(): boolean {
|
||||
if (this.nativeView) {
|
||||
return this.nativeView.requestFocus();
|
||||
if (this.nativeViewProtected) {
|
||||
return this.nativeViewProtected.requestFocus();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public getLocationInWindow(): Point {
|
||||
if (!this.nativeView || !this.nativeView.getWindowToken()) {
|
||||
if (!this.nativeViewProtected || !this.nativeViewProtected.getWindowToken()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let nativeArray = (<any>Array).create("int", 2);
|
||||
this.nativeView.getLocationInWindow(nativeArray);
|
||||
this.nativeViewProtected.getLocationInWindow(nativeArray);
|
||||
return {
|
||||
x: layout.toDeviceIndependentPixels(nativeArray[0]),
|
||||
y: layout.toDeviceIndependentPixels(nativeArray[1]),
|
||||
@@ -228,12 +228,12 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
public getLocationOnScreen(): Point {
|
||||
if (!this.nativeView || !this.nativeView.getWindowToken()) {
|
||||
if (!this.nativeViewProtected || !this.nativeViewProtected.getWindowToken()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let nativeArray = (<any>Array).create("int", 2);
|
||||
this.nativeView.getLocationOnScreen(nativeArray);
|
||||
this.nativeViewProtected.getLocationOnScreen(nativeArray);
|
||||
return {
|
||||
x: layout.toDeviceIndependentPixels(nativeArray[0]),
|
||||
y: layout.toDeviceIndependentPixels(nativeArray[1]),
|
||||
@@ -241,16 +241,16 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
public getLocationRelativeTo(otherView: ViewCommon): Point {
|
||||
if (!this.nativeView || !this.nativeView.getWindowToken() ||
|
||||
!otherView.nativeView || !otherView.nativeView.getWindowToken() ||
|
||||
this.nativeView.getWindowToken() !== otherView.nativeView.getWindowToken()) {
|
||||
if (!this.nativeViewProtected || !this.nativeViewProtected.getWindowToken() ||
|
||||
!otherView.nativeViewProtected || !otherView.nativeViewProtected.getWindowToken() ||
|
||||
this.nativeViewProtected.getWindowToken() !== otherView.nativeViewProtected.getWindowToken()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let myArray = (<any>Array).create("int", 2);
|
||||
this.nativeView.getLocationOnScreen(myArray);
|
||||
this.nativeViewProtected.getLocationOnScreen(myArray);
|
||||
let otherArray = (<any>Array).create("int", 2);
|
||||
otherView.nativeView.getLocationOnScreen(otherArray);
|
||||
otherView.nativeViewProtected.getLocationOnScreen(otherArray);
|
||||
return {
|
||||
x: layout.toDeviceIndependentPixels(myArray[0] - otherArray[0]),
|
||||
y: layout.toDeviceIndependentPixels(myArray[1] - otherArray[1]),
|
||||
@@ -279,45 +279,45 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[isEnabledProperty.setNative](value: boolean) {
|
||||
this.nativeView.setEnabled(value);
|
||||
this.nativeViewProtected.setEnabled(value);
|
||||
}
|
||||
|
||||
[originXProperty.getDefault](): number {
|
||||
return this.nativeView.getPivotX();
|
||||
return this.nativeViewProtected.getPivotX();
|
||||
}
|
||||
[originXProperty.setNative](value: number) {
|
||||
org.nativescript.widgets.OriginPoint.setX(this.nativeView, value);
|
||||
org.nativescript.widgets.OriginPoint.setX(this.nativeViewProtected, value);
|
||||
}
|
||||
|
||||
[originYProperty.getDefault](): number {
|
||||
return this.nativeView.getPivotY();
|
||||
return this.nativeViewProtected.getPivotY();
|
||||
}
|
||||
[originYProperty.setNative](value: number) {
|
||||
org.nativescript.widgets.OriginPoint.setY(this.nativeView, value);
|
||||
org.nativescript.widgets.OriginPoint.setY(this.nativeViewProtected, value);
|
||||
}
|
||||
|
||||
[automationTextProperty.getDefault](): string {
|
||||
return this.nativeView.getContentDescription();
|
||||
return this.nativeViewProtected.getContentDescription();
|
||||
}
|
||||
[automationTextProperty.setNative](value: string) {
|
||||
this.nativeView.setContentDescription(value);
|
||||
this.nativeViewProtected.setContentDescription(value);
|
||||
}
|
||||
|
||||
[isUserInteractionEnabledProperty.setNative](value: boolean) {
|
||||
if (!value) {
|
||||
initializeDisabledListener();
|
||||
// User interaction is disabled -- we stop it and we do not care whether someone wants to listen for gestures.
|
||||
this.nativeView.setOnTouchListener(disableUserInteractionListener);
|
||||
this.nativeViewProtected.setOnTouchListener(disableUserInteractionListener);
|
||||
} else {
|
||||
this.setOnTouchListener();
|
||||
if (!this.touchListenerIsSet) {
|
||||
this.nativeView.setOnTouchListener(null);
|
||||
this.nativeViewProtected.setOnTouchListener(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[visibilityProperty.getDefault](): Visibility {
|
||||
let nativeVisibility = this.nativeView.getVisibility();
|
||||
let nativeVisibility = this.nativeViewProtected.getVisibility();
|
||||
switch (nativeVisibility) {
|
||||
case android.view.View.VISIBLE:
|
||||
return "visible";
|
||||
@@ -332,13 +332,13 @@ export class View extends ViewCommon {
|
||||
[visibilityProperty.setNative](value: Visibility) {
|
||||
switch (value) {
|
||||
case "visible":
|
||||
this.nativeView.setVisibility(android.view.View.VISIBLE);
|
||||
this.nativeViewProtected.setVisibility(android.view.View.VISIBLE);
|
||||
break;
|
||||
case "hidden":
|
||||
this.nativeView.setVisibility(android.view.View.INVISIBLE);
|
||||
this.nativeViewProtected.setVisibility(android.view.View.INVISIBLE);
|
||||
break;
|
||||
case "collapse":
|
||||
this.nativeView.setVisibility(android.view.View.GONE);
|
||||
this.nativeViewProtected.setVisibility(android.view.View.GONE);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Invalid visibility value: ${value}. Valid values are: visible, hidden, collapse.`);
|
||||
@@ -346,17 +346,17 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[opacityProperty.getDefault](): number {
|
||||
return this.nativeView.getAlpha();
|
||||
return this.nativeViewProtected.getAlpha();
|
||||
}
|
||||
[opacityProperty.setNative](value: number) {
|
||||
this.nativeView.setAlpha(float(value));
|
||||
this.nativeViewProtected.setAlpha(float(value));
|
||||
}
|
||||
|
||||
[horizontalAlignmentProperty.getDefault](): HorizontalAlignment {
|
||||
return <HorizontalAlignment>org.nativescript.widgets.ViewHelper.getHorizontalAlignment(this.nativeView);
|
||||
return <HorizontalAlignment>org.nativescript.widgets.ViewHelper.getHorizontalAlignment(this.nativeViewProtected);
|
||||
}
|
||||
[horizontalAlignmentProperty.setNative](value: HorizontalAlignment) {
|
||||
const nativeView = this.nativeView;
|
||||
const nativeView = this.nativeViewProtected;
|
||||
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
|
||||
// Set only if params gravity exists.
|
||||
if (lp.gravity !== undefined) {
|
||||
@@ -391,10 +391,10 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[verticalAlignmentProperty.getDefault](): VerticalAlignment {
|
||||
return <VerticalAlignment>org.nativescript.widgets.ViewHelper.getVerticalAlignment(this.nativeView);
|
||||
return <VerticalAlignment>org.nativescript.widgets.ViewHelper.getVerticalAlignment(this.nativeViewProtected);
|
||||
}
|
||||
[verticalAlignmentProperty.setNative](value: VerticalAlignment) {
|
||||
const nativeView = this.nativeView;
|
||||
const nativeView = this.nativeViewProtected;
|
||||
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
|
||||
// Set only if params gravity exists.
|
||||
if (lp.gravity !== undefined) {
|
||||
@@ -429,34 +429,34 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[rotateProperty.setNative](value: number) {
|
||||
org.nativescript.widgets.ViewHelper.setRotate(this.nativeView, float(value));
|
||||
org.nativescript.widgets.ViewHelper.setRotate(this.nativeViewProtected, float(value));
|
||||
}
|
||||
|
||||
[scaleXProperty.setNative](value: number) {
|
||||
org.nativescript.widgets.ViewHelper.setScaleX(this.nativeView, float(value));
|
||||
org.nativescript.widgets.ViewHelper.setScaleX(this.nativeViewProtected, float(value));
|
||||
}
|
||||
|
||||
[scaleYProperty.setNative](value: number) {
|
||||
org.nativescript.widgets.ViewHelper.setScaleY(this.nativeView, float(value));
|
||||
org.nativescript.widgets.ViewHelper.setScaleY(this.nativeViewProtected, float(value));
|
||||
}
|
||||
|
||||
[translateXProperty.setNative](value: dip) {
|
||||
org.nativescript.widgets.ViewHelper.setTranslateX(this.nativeView, layout.toDevicePixels(value));
|
||||
org.nativescript.widgets.ViewHelper.setTranslateX(this.nativeViewProtected, layout.toDevicePixels(value));
|
||||
}
|
||||
|
||||
[translateYProperty.setNative](value: dip) {
|
||||
org.nativescript.widgets.ViewHelper.setTranslateY(this.nativeView, layout.toDevicePixels(value));
|
||||
org.nativescript.widgets.ViewHelper.setTranslateY(this.nativeViewProtected, layout.toDevicePixels(value));
|
||||
}
|
||||
|
||||
[zIndexProperty.getDefault](): number {
|
||||
return 0;
|
||||
}
|
||||
[zIndexProperty.setNative](value: number) {
|
||||
org.nativescript.widgets.ViewHelper.setZIndex(this.nativeView, value);
|
||||
org.nativescript.widgets.ViewHelper.setZIndex(this.nativeViewProtected, value);
|
||||
}
|
||||
|
||||
[backgroundInternalProperty.getDefault](): android.graphics.drawable.Drawable {
|
||||
const nativeView = this.nativeView;
|
||||
const nativeView = this.nativeViewProtected;
|
||||
const drawable = nativeView.getBackground();
|
||||
return drawable ? drawable.getConstantState().newDrawable(nativeView.getResources()) : null;
|
||||
}
|
||||
@@ -465,7 +465,7 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[minWidthProperty.setNative](value: Length) {
|
||||
if (this.parent instanceof CustomLayoutView && this.parent.nativeView) {
|
||||
if (this.parent instanceof CustomLayoutView && this.parent.nativeViewProtected) {
|
||||
this.parent._setChildMinWidthNative(this);
|
||||
} else {
|
||||
this._setMinWidthNative(this.minWidth);
|
||||
@@ -473,7 +473,7 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[minHeightProperty.setNative](value: Length) {
|
||||
if (this.parent instanceof CustomLayoutView && this.parent.nativeView) {
|
||||
if (this.parent instanceof CustomLayoutView && this.parent.nativeViewProtected) {
|
||||
this.parent._setChildMinHeightNative(this);
|
||||
} else {
|
||||
this._setMinHeightNative(this.minHeight);
|
||||
@@ -484,7 +484,7 @@ export class View extends ViewCommon {
|
||||
if (value instanceof Background) {
|
||||
androidBackground.onBackgroundOrBorderPropertyChanged(this);
|
||||
} else {
|
||||
const nativeView = this.nativeView;
|
||||
const nativeView = this.nativeViewProtected;
|
||||
org.nativescript.widgets.ViewHelper.setBackground(nativeView, value);
|
||||
nativeView.setPadding(this._defaultPaddingLeft, this._defaultPaddingTop, this._defaultPaddingRight, this._defaultPaddingBottom);
|
||||
|
||||
@@ -499,7 +499,7 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
export class CustomLayoutView extends View implements CustomLayoutViewDefinition {
|
||||
nativeView: android.view.ViewGroup;
|
||||
nativeViewProtected: android.view.ViewGroup;
|
||||
|
||||
public createNativeView() {
|
||||
return new org.nativescript.widgets.ContentLayout(this._context);
|
||||
@@ -508,11 +508,11 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
|
||||
public _addViewToNativeVisualTree(child: ViewCommon, atIndex: number = -1): boolean {
|
||||
super._addViewToNativeVisualTree(child);
|
||||
|
||||
if (this.nativeView && child.nativeView) {
|
||||
if (this.nativeViewProtected && child.nativeViewProtected) {
|
||||
if (traceEnabled()) {
|
||||
traceWrite(`${this}.nativeView.addView(${child}.nativeView, ${atIndex})`, traceCategories.VisualTreeEvents);
|
||||
}
|
||||
this.nativeView.addView(child.nativeView, atIndex);
|
||||
this.nativeViewProtected.addView(child.nativeViewProtected, atIndex);
|
||||
if (child instanceof View) {
|
||||
this._updateNativeLayoutParams(child);
|
||||
}
|
||||
@@ -538,8 +538,8 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
|
||||
public _removeViewFromNativeVisualTree(child: ViewCommon): void {
|
||||
super._removeViewFromNativeVisualTree(child);
|
||||
|
||||
const nativeView = this.nativeView;
|
||||
const childView = child.nativeView;
|
||||
const nativeView = this.nativeViewProtected;
|
||||
const childView = child.nativeViewProtected;
|
||||
if (nativeView && childView) {
|
||||
nativeView.removeView(childView);
|
||||
if (traceEnabled()) {
|
||||
@@ -573,7 +573,7 @@ function createNativePercentLengthProperty(options: NativePercentLengthPropertyO
|
||||
setPercent = options.setPercent || percentNotSupported;
|
||||
options = null;
|
||||
}
|
||||
const value = getPixels(this.nativeView);
|
||||
const value = getPixels(this.nativeViewProtected);
|
||||
if (value == auto) { // tslint:disable-line
|
||||
return "auto";
|
||||
} else {
|
||||
@@ -590,15 +590,15 @@ function createNativePercentLengthProperty(options: NativePercentLengthPropertyO
|
||||
options = null;
|
||||
}
|
||||
if (length == "auto") { // tslint:disable-line
|
||||
setPixels(this.nativeView, auto);
|
||||
setPixels(this.nativeViewProtected, auto);
|
||||
} else if (typeof length === "number") {
|
||||
setPixels(this.nativeView, layout.round(layout.toDevicePixels(length)));
|
||||
setPixels(this.nativeViewProtected, layout.round(layout.toDevicePixels(length)));
|
||||
} else if (length.unit == "dip") { // tslint:disable-line
|
||||
setPixels(this.nativeView, layout.round(layout.toDevicePixels(length.value)));
|
||||
setPixels(this.nativeViewProtected, layout.round(layout.toDevicePixels(length.value)));
|
||||
} else if (length.unit == "px") { // tslint:disable-line
|
||||
setPixels(this.nativeView, layout.round(length.value));
|
||||
setPixels(this.nativeViewProtected, layout.round(length.value));
|
||||
} else if (length.unit == "%") { // tslint:disable-line
|
||||
setPercent(this.nativeView, length.value);
|
||||
setPercent(this.nativeViewProtected, length.value);
|
||||
} else {
|
||||
throw new Error(`Unsupported PercentLength ${length}`);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ const PFLAG_MEASURED_DIMENSION_SET = 1 << 1;
|
||||
const PFLAG_LAYOUT_REQUIRED = 1 << 2;
|
||||
|
||||
export class View extends ViewCommon {
|
||||
nativeView: UIView;
|
||||
nativeViewProtected: UIView;
|
||||
private _hasTransfrom = false;
|
||||
private _privateFlags: number = PFLAG_LAYOUT_REQUIRED | PFLAG_FORCE_LAYOUT;
|
||||
private _cachedFrame: CGRect;
|
||||
@@ -113,7 +113,7 @@ export class View extends ViewCommon {
|
||||
|
||||
@profile
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
const view = this.nativeView;
|
||||
const view = this.nativeViewProtected;
|
||||
const width = layout.getMeasureSpecSize(widthMeasureSpec);
|
||||
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
|
||||
|
||||
@@ -163,11 +163,11 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
|
||||
if (!this.nativeView) {
|
||||
if (!this.nativeViewProtected) {
|
||||
return;
|
||||
}
|
||||
|
||||
let nativeView = this.nativeView;
|
||||
let nativeView = this.nativeViewProtected;
|
||||
|
||||
let frame = CGRectMake(layout.toDeviceIndependentPixels(left), layout.toDeviceIndependentPixels(top), layout.toDeviceIndependentPixels(right - left), layout.toDeviceIndependentPixels(bottom - top));
|
||||
this._setNativeViewFrame(nativeView, frame);
|
||||
@@ -187,11 +187,11 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
public getLocationInWindow(): Point {
|
||||
if (!this.nativeView || !this.nativeView.window) {
|
||||
if (!this.nativeViewProtected || !this.nativeViewProtected.window) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let pointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
|
||||
let pointInWindow = this.nativeViewProtected.convertPointToView(this.nativeViewProtected.bounds.origin, null);
|
||||
return {
|
||||
x: pointInWindow.x,
|
||||
y: pointInWindow.y
|
||||
@@ -199,12 +199,12 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
public getLocationOnScreen(): Point {
|
||||
if (!this.nativeView || !this.nativeView.window) {
|
||||
if (!this.nativeViewProtected || !this.nativeViewProtected.window) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let pointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
|
||||
let pointOnScreen = this.nativeView.window.convertPointToWindow(pointInWindow, null);
|
||||
let pointInWindow = this.nativeViewProtected.convertPointToView(this.nativeViewProtected.bounds.origin, null);
|
||||
let pointOnScreen = this.nativeViewProtected.window.convertPointToWindow(pointInWindow, null);
|
||||
return {
|
||||
x: pointOnScreen.x,
|
||||
y: pointOnScreen.y
|
||||
@@ -212,14 +212,14 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
public getLocationRelativeTo(otherView: ViewDefinition): Point {
|
||||
if (!this.nativeView || !this.nativeView.window ||
|
||||
!otherView.nativeView || !otherView.nativeView.window ||
|
||||
this.nativeView.window !== otherView.nativeView.window) {
|
||||
if (!this.nativeViewProtected || !this.nativeViewProtected.window ||
|
||||
!otherView.nativeViewProtected || !otherView.nativeViewProtected.window ||
|
||||
this.nativeViewProtected.window !== otherView.nativeViewProtected.window) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let myPointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
|
||||
let otherPointInWindow = otherView.nativeView.convertPointToView(otherView.nativeView.bounds.origin, null);
|
||||
let myPointInWindow = this.nativeViewProtected.convertPointToView(this.nativeViewProtected.bounds.origin, null);
|
||||
let otherPointInWindow = otherView.nativeViewProtected.convertPointToView(otherView.nativeViewProtected.bounds.origin, null);
|
||||
return {
|
||||
x: myPointInWindow.x - otherPointInWindow.x,
|
||||
y: myPointInWindow.y - otherPointInWindow.y
|
||||
@@ -227,7 +227,7 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
private _onSizeChanged(): void {
|
||||
let nativeView = this.nativeView;
|
||||
let nativeView = this.nativeViewProtected;
|
||||
if (!nativeView) {
|
||||
return;
|
||||
}
|
||||
@@ -253,13 +253,13 @@ export class View extends ViewCommon {
|
||||
newTransform = CGAffineTransformTranslate(newTransform, this.translateX, this.translateY);
|
||||
newTransform = CGAffineTransformRotate(newTransform, rotate * Math.PI / 180);
|
||||
newTransform = CGAffineTransformScale(newTransform, scaleX, scaleY);
|
||||
if (!CGAffineTransformEqualToTransform(this.nativeView.transform, newTransform)) {
|
||||
if (!CGAffineTransformEqualToTransform(this.nativeViewProtected.transform, newTransform)) {
|
||||
let updateSuspended = this._isPresentationLayerUpdateSuspeneded();
|
||||
if (!updateSuspended) {
|
||||
CATransaction.begin();
|
||||
}
|
||||
this.nativeView.transform = newTransform;
|
||||
this._hasTransfrom = this.nativeView && !CGAffineTransformEqualToTransform(this.nativeView.transform, CGAffineTransformIdentity);
|
||||
this.nativeViewProtected.transform = newTransform;
|
||||
this._hasTransfrom = this.nativeViewProtected && !CGAffineTransformEqualToTransform(this.nativeViewProtected.transform, CGAffineTransformIdentity);
|
||||
if (!updateSuspended) {
|
||||
CATransaction.commit();
|
||||
}
|
||||
@@ -268,9 +268,9 @@ export class View extends ViewCommon {
|
||||
|
||||
public updateOriginPoint(originX: number, originY: number) {
|
||||
let newPoint = CGPointMake(originX, originY);
|
||||
this.nativeView.layer.anchorPoint = newPoint;
|
||||
this.nativeViewProtected.layer.anchorPoint = newPoint;
|
||||
if (this._cachedFrame) {
|
||||
this._setNativeViewFrame(this.nativeView, this._cachedFrame);
|
||||
this._setNativeViewFrame(this.nativeViewProtected, this._cachedFrame);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,56 +290,56 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[isEnabledProperty.getDefault](): boolean {
|
||||
let nativeView = this.nativeView;
|
||||
let nativeView = this.nativeViewProtected;
|
||||
return nativeView instanceof UIControl ? nativeView.enabled : true;
|
||||
}
|
||||
[isEnabledProperty.setNative](value: boolean) {
|
||||
let nativeView = this.nativeView;
|
||||
let nativeView = this.nativeViewProtected;
|
||||
if (nativeView instanceof UIControl) {
|
||||
nativeView.enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
[originXProperty.getDefault](): number {
|
||||
return this.nativeView.layer.anchorPoint.x;
|
||||
return this.nativeViewProtected.layer.anchorPoint.x;
|
||||
}
|
||||
[originXProperty.setNative](value: number) {
|
||||
this.updateOriginPoint(value, this.originY);
|
||||
}
|
||||
|
||||
[originYProperty.getDefault](): number {
|
||||
return this.nativeView.layer.anchorPoint.y;
|
||||
return this.nativeViewProtected.layer.anchorPoint.y;
|
||||
}
|
||||
[originYProperty.setNative](value: number) {
|
||||
this.updateOriginPoint(this.originX, value);
|
||||
}
|
||||
|
||||
[automationTextProperty.getDefault](): string {
|
||||
return this.nativeView.accessibilityLabel;
|
||||
return this.nativeViewProtected.accessibilityLabel;
|
||||
}
|
||||
[automationTextProperty.setNative](value: string) {
|
||||
this.nativeView.accessibilityIdentifier = value;
|
||||
this.nativeView.accessibilityLabel = value;
|
||||
this.nativeViewProtected.accessibilityIdentifier = value;
|
||||
this.nativeViewProtected.accessibilityLabel = value;
|
||||
}
|
||||
|
||||
[isUserInteractionEnabledProperty.getDefault](): boolean {
|
||||
return this.nativeView.userInteractionEnabled;
|
||||
return this.nativeViewProtected.userInteractionEnabled;
|
||||
}
|
||||
[isUserInteractionEnabledProperty.setNative](value: boolean) {
|
||||
this.nativeView.userInteractionEnabled = value;
|
||||
this.nativeViewProtected.userInteractionEnabled = value;
|
||||
}
|
||||
|
||||
[visibilityProperty.getDefault](): Visibility {
|
||||
return this.nativeView.hidden ? Visibility.COLLAPSE : Visibility.VISIBLE;
|
||||
return this.nativeViewProtected.hidden ? Visibility.COLLAPSE : Visibility.VISIBLE;
|
||||
}
|
||||
[visibilityProperty.setNative](value: Visibility) {
|
||||
switch (value) {
|
||||
case Visibility.VISIBLE:
|
||||
this.nativeView.hidden = false;
|
||||
this.nativeViewProtected.hidden = false;
|
||||
break;
|
||||
case Visibility.HIDDEN:
|
||||
case Visibility.COLLAPSE:
|
||||
this.nativeView.hidden = true;
|
||||
this.nativeViewProtected.hidden = true;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Invalid visibility value: ${value}. Valid values are: "${Visibility.VISIBLE}", "${Visibility.HIDDEN}", "${Visibility.COLLAPSE}".`);
|
||||
@@ -347,10 +347,10 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[opacityProperty.getDefault](): number {
|
||||
return this.nativeView.alpha;
|
||||
return this.nativeViewProtected.alpha;
|
||||
}
|
||||
[opacityProperty.setNative](value: number) {
|
||||
let nativeView = this.nativeView;
|
||||
let nativeView = this.nativeViewProtected;
|
||||
let updateSuspended = this._isPresentationLayerUpdateSuspeneded();
|
||||
if (!updateSuspended) {
|
||||
CATransaction.begin();
|
||||
@@ -400,11 +400,11 @@ export class View extends ViewCommon {
|
||||
return 0;
|
||||
}
|
||||
[zIndexProperty.setNative](value: number) {
|
||||
this.nativeView.layer.zPosition = value;
|
||||
this.nativeViewProtected.layer.zPosition = value;
|
||||
}
|
||||
|
||||
[backgroundInternalProperty.getDefault](): UIColor {
|
||||
return this.nativeView.backgroundColor;
|
||||
return this.nativeViewProtected.backgroundColor;
|
||||
}
|
||||
[backgroundInternalProperty.setNative](value: UIColor | Background) {
|
||||
this._nativeBackgroundState = "invalid";
|
||||
@@ -420,10 +420,10 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
if (value instanceof UIColor) {
|
||||
this.nativeView.backgroundColor = value;
|
||||
this.nativeViewProtected.backgroundColor = value;
|
||||
} else {
|
||||
ios.createBackgroundUIColor(this, (color: UIColor) => {
|
||||
this.nativeView.backgroundColor = color;
|
||||
this.nativeViewProtected.backgroundColor = color;
|
||||
});
|
||||
this._setNativeClipToBounds();
|
||||
}
|
||||
@@ -437,22 +437,22 @@ export class View extends ViewCommon {
|
||||
|
||||
_setNativeClipToBounds() {
|
||||
let backgroundInternal = this.style.backgroundInternal;
|
||||
this.nativeView.clipsToBounds = backgroundInternal.hasBorderWidth() || backgroundInternal.hasBorderRadius();
|
||||
this.nativeViewProtected.clipsToBounds = backgroundInternal.hasBorderWidth() || backgroundInternal.hasBorderRadius();
|
||||
}
|
||||
}
|
||||
View.prototype._nativeBackgroundState = "unset";
|
||||
|
||||
export class CustomLayoutView extends View {
|
||||
|
||||
nativeView: UIView;
|
||||
nativeViewProtected: UIView;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.nativeView = UIView.new();
|
||||
this.nativeViewProtected = UIView.new();
|
||||
}
|
||||
|
||||
get ios(): UIView {
|
||||
return this.nativeView;
|
||||
return this.nativeViewProtected;
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
@@ -462,8 +462,8 @@ export class CustomLayoutView extends View {
|
||||
public _addViewToNativeVisualTree(child: View, atIndex: number): boolean {
|
||||
super._addViewToNativeVisualTree(child, atIndex);
|
||||
|
||||
const parentNativeView = this.nativeView;
|
||||
const childNativeView = child.nativeView;
|
||||
const parentNativeView = this.nativeViewProtected;
|
||||
const childNativeView = child.nativeViewProtected;
|
||||
|
||||
if (parentNativeView && childNativeView) {
|
||||
if (typeof atIndex !== "number" || atIndex >= parentNativeView.subviews.count) {
|
||||
@@ -481,8 +481,8 @@ export class CustomLayoutView extends View {
|
||||
public _removeViewFromNativeVisualTree(child: View): void {
|
||||
super._removeViewFromNativeVisualTree(child);
|
||||
|
||||
if (child.nativeView) {
|
||||
child.nativeView.removeFromSuperview();
|
||||
if (child.nativeViewProtected) {
|
||||
child.nativeViewProtected.removeFromSuperview();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user