Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 7 additions & 27 deletions packages/core/ui/button/index.android.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ButtonBase } from './button-common';
import { PseudoClassHandler } from '../core/view';
import { paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, zIndexProperty, minWidthProperty, minHeightProperty } from '../styling/style-properties';
import { zIndexProperty, minWidthProperty, minHeightProperty, paddingInternalProperty } from '../styling/style-properties';
import { Length } from '../styling/length-shared';
import { textAlignmentProperty } from '../text-base';
import { CoreTypes } from '../../core-types';
Expand Down Expand Up @@ -123,32 +123,12 @@ export class Button extends ButtonBase {
return { value: dips, unit: 'px' };
}

[paddingTopProperty.getDefault](): CoreTypes.LengthType {
return { value: this._defaultPaddingTop, unit: 'px' };
}
[paddingTopProperty.setNative](value: CoreTypes.LengthType) {
org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0));
}

[paddingRightProperty.getDefault](): CoreTypes.LengthType {
return { value: this._defaultPaddingRight, unit: 'px' };
}
[paddingRightProperty.setNative](value: CoreTypes.LengthType) {
org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0));
}

[paddingBottomProperty.getDefault](): CoreTypes.LengthType {
return { value: this._defaultPaddingBottom, unit: 'px' };
}
[paddingBottomProperty.setNative](value: CoreTypes.LengthType) {
org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0));
}

[paddingLeftProperty.getDefault](): CoreTypes.LengthType {
return { value: this._defaultPaddingLeft, unit: 'px' };
}
[paddingLeftProperty.setNative](value: CoreTypes.LengthType) {
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));
[paddingInternalProperty.setNative](_value: string) {
const left = this.effectivePaddingLeft + Length.toDevicePixels(this.style.borderLeftWidth, 0);
const top = this.effectivePaddingTop + Length.toDevicePixels(this.style.borderTopWidth, 0);
const right = this.effectivePaddingRight + Length.toDevicePixels(this.style.borderRightWidth, 0);
const bottom = this.effectivePaddingBottom + Length.toDevicePixels(this.style.borderBottomWidth, 0);
this.nativeViewProtected.setPadding(left, top, right, bottom);
}

[zIndexProperty.setNative](value: number) {
Expand Down
93 changes: 18 additions & 75 deletions packages/core/ui/button/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ControlStateChangeListener } from '../core/control-state-change';
import { ButtonBase } from './button-common';
import { View, PseudoClassHandler } from '../core/view';
import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, directionProperty } from '../styling/style-properties';
import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, directionProperty, paddingInternalProperty } from '../styling/style-properties';
import { textAlignmentProperty, whiteSpaceProperty, textOverflowProperty } from '../text-base';
import { layout } from '../../utils';
import { CoreTypes } from '../../core-types';
Expand All @@ -28,8 +28,10 @@ export class Button extends ButtonBase {

public initNativeView(): void {
super.initNativeView();

this._tapHandler = TapHandlerImpl.initWithOwner(new WeakRef(this));
this.nativeViewProtected.addTargetActionForControlEvents(this._tapHandler, 'tap', UIControlEvents.TouchUpInside);
this._setDefaultPaddings(this.nativeViewProtected.contentEdgeInsets);
}

public disposeNativeView(): void {
Expand Down Expand Up @@ -86,12 +88,12 @@ export class Button extends ButtonBase {
[borderTopWidthProperty.setNative](value: CoreTypes.LengthType) {
const inset = this.nativeViewProtected.contentEdgeInsets;
const top = layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth);
this.nativeViewProtected.contentEdgeInsets = {
this.nativeViewProtected.contentEdgeInsets = new UIEdgeInsets({
top: top,
left: inset.left,
bottom: inset.bottom,
right: inset.right,
};
});
}

[borderRightWidthProperty.getDefault](): CoreTypes.LengthType {
Expand All @@ -103,12 +105,12 @@ export class Button extends ButtonBase {
[borderRightWidthProperty.setNative](value: CoreTypes.LengthType) {
const inset = this.nativeViewProtected.contentEdgeInsets;
const right = layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth);
this.nativeViewProtected.contentEdgeInsets = {
this.nativeViewProtected.contentEdgeInsets = new UIEdgeInsets({
top: inset.top,
left: inset.left,
bottom: inset.bottom,
right: right,
};
});
}

[borderBottomWidthProperty.getDefault](): CoreTypes.LengthType {
Expand All @@ -120,12 +122,12 @@ export class Button extends ButtonBase {
[borderBottomWidthProperty.setNative](value: CoreTypes.LengthType) {
const inset = this.nativeViewProtected.contentEdgeInsets;
const bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth);
this.nativeViewProtected.contentEdgeInsets = {
this.nativeViewProtected.contentEdgeInsets = new UIEdgeInsets({
top: inset.top,
left: inset.left,
bottom: bottom,
right: inset.right,
};
});
}

[borderLeftWidthProperty.getDefault](): CoreTypes.LengthType {
Expand All @@ -137,80 +139,21 @@ export class Button extends ButtonBase {
[borderLeftWidthProperty.setNative](value: CoreTypes.LengthType) {
const inset = this.nativeViewProtected.contentEdgeInsets;
const left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth);
this.nativeViewProtected.contentEdgeInsets = {
this.nativeViewProtected.contentEdgeInsets = new UIEdgeInsets({
top: inset.top,
left: left,
bottom: inset.bottom,
right: inset.right,
};
}

[paddingTopProperty.getDefault](): CoreTypes.LengthType {
return {
value: this.nativeViewProtected.contentEdgeInsets.top,
unit: 'px',
};
}
[paddingTopProperty.setNative](value: CoreTypes.LengthType) {
const inset = this.nativeViewProtected.contentEdgeInsets;
const top = layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth);
this.nativeViewProtected.contentEdgeInsets = {
top: top,
left: inset.left,
bottom: inset.bottom,
right: inset.right,
};
});
}

[paddingRightProperty.getDefault](): CoreTypes.LengthType {
return {
value: this.nativeViewProtected.contentEdgeInsets.right,
unit: 'px',
};
}
[paddingRightProperty.setNative](value: CoreTypes.LengthType) {
const inset = this.nativeViewProtected.contentEdgeInsets;
const right = layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth);
this.nativeViewProtected.contentEdgeInsets = {
top: inset.top,
left: inset.left,
bottom: inset.bottom,
right: right,
};
}

[paddingBottomProperty.getDefault](): CoreTypes.LengthType {
return {
value: this.nativeViewProtected.contentEdgeInsets.bottom,
unit: 'px',
};
}
[paddingBottomProperty.setNative](value: CoreTypes.LengthType) {
const inset = this.nativeViewProtected.contentEdgeInsets;
const bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth);
this.nativeViewProtected.contentEdgeInsets = {
top: inset.top,
left: inset.left,
bottom: bottom,
right: inset.right,
};
}

[paddingLeftProperty.getDefault](): CoreTypes.LengthType {
return {
value: this.nativeViewProtected.contentEdgeInsets.left,
unit: 'px',
};
}
[paddingLeftProperty.setNative](value: CoreTypes.LengthType) {
const inset = this.nativeViewProtected.contentEdgeInsets;
const left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth);
this.nativeViewProtected.contentEdgeInsets = {
top: inset.top,
left: left,
bottom: inset.bottom,
right: inset.right,
};
[paddingInternalProperty.setNative](_value: string) {
this.nativeViewProtected.contentEdgeInsets = new UIEdgeInsets({
top: layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth),
left: layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth),
bottom: layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth),
right: layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth),
});
}

[textAlignmentProperty.setNative](value: CoreTypes.TextAlignmentType) {
Expand Down
88 changes: 49 additions & 39 deletions packages/core/ui/core/view-base/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AlignSelf, Flex, FlexFlow, FlexGrow, FlexShrink, FlexWrapBefore, Order } from '../../layouts/flexbox-layout';
import { AlignSelf, FlexGrow, FlexShrink, FlexWrapBefore, Order } from '../../layouts/flexbox-layout';
import { Page } from '../../page';
import { CoreTypes, Trace } from '../../styling/styling-shared';
import { Property, CssProperty, CssAnimationProperty, InheritedProperty, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, initNativeView } from '../properties';
Expand All @@ -8,12 +8,10 @@ import { Binding } from '../bindable';
import { BindingOptions } from '../bindable/bindable-types';
import { Observable, PropertyChangeData, WrappedValue } from '../../../data/observable';
import { Style } from '../../styling/style';
import { paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty } from '../../styling/style-properties';
import type { ModalTransition } from '../../transition/modal-transition';

// TODO: Remove this import!
import { getClass } from '../../../utils/types';
import { unsetValue } from '../properties/property-shared';

import { profile } from '../../../profiling';

Expand Down Expand Up @@ -339,6 +337,17 @@ export abstract class ViewBase extends Observable {
private _style: Style;
private _isLoaded: boolean;

private _effectivePaddingTop: number = null;
private _effectivePaddingRight: number = null;
private _effectivePaddingBottom: number = null;
private _effectivePaddingLeft: number = null;

protected _defaultPaddingTop: number = 0;
protected _defaultPaddingRight: number = 0;
protected _defaultPaddingBottom: number = 0;
protected _defaultPaddingLeft: number = 0;
protected _isPaddingRelative: boolean;

/**
* @deprecated
*/
Expand Down Expand Up @@ -527,21 +536,11 @@ export abstract class ViewBase extends Observable {
public effectiveMarginRight: number;
public effectiveMarginBottom: number;
public effectiveMarginLeft: number;
public effectivePaddingTop: number;
public effectivePaddingRight: number;
public effectivePaddingBottom: number;
public effectivePaddingLeft: number;
public effectiveBorderTopWidth: number;
public effectiveBorderRightWidth: number;
public effectiveBorderBottomWidth: number;
public effectiveBorderLeftWidth: number;

public _defaultPaddingTop: number;
public _defaultPaddingRight: number;
public _defaultPaddingBottom: number;
public _defaultPaddingLeft: number;
public _isPaddingRelative: boolean;

/**
* @private
* Module name when the view is a module root. Otherwise, it is undefined.
Expand Down Expand Up @@ -637,6 +636,38 @@ export abstract class ViewBase extends Observable {
this.className = v;
}

get effectivePaddingTop(): number {
return this._effectivePaddingTop != null ? this._effectivePaddingTop : this._defaultPaddingTop;
}
set effectivePaddingTop(v: number) {
this._effectivePaddingTop = v;
}

get effectivePaddingRight(): number {
return this._effectivePaddingRight != null ? this._effectivePaddingRight : this._defaultPaddingRight;
}
set effectivePaddingRight(v: number) {
this._effectivePaddingRight = v;
}

get effectivePaddingBottom(): number {
return this._effectivePaddingBottom != null ? this._effectivePaddingBottom : this._defaultPaddingBottom;
}
set effectivePaddingBottom(v: number) {
this._effectivePaddingBottom = v;
}

get effectivePaddingLeft(): number {
return this._effectivePaddingLeft != null ? this._effectivePaddingLeft : this._defaultPaddingLeft;
}
set effectivePaddingLeft(v: number) {
this._effectivePaddingLeft = v;
}

getEffectivePaddingShorthand(): string {
return `${this.effectivePaddingTop} ${this.effectivePaddingRight} ${this.effectivePaddingBottom} ${this.effectivePaddingLeft}`;
}

/**
* Returns the child view with the specified id.
*/
Expand Down Expand Up @@ -724,6 +755,10 @@ export abstract class ViewBase extends Observable {
}
}

public _setDefaultPaddings(insets: any): void {
// Overridden
}

public _suspendNativeUpdates(type: SuspendType): void {
if (type) {
this._suspendNativeUpdatesCount = this._suspendNativeUpdatesCount | type;
Expand Down Expand Up @@ -1176,24 +1211,7 @@ export abstract class ViewBase extends Observable {
nativeView.defaultPaddings = DEFAULT_VIEW_PADDINGS.get(className);
}

this._defaultPaddingTop = result.top;
this._defaultPaddingRight = result.right;
this._defaultPaddingBottom = result.bottom;
this._defaultPaddingLeft = result.left;

const style = this.style;
if (!paddingTopProperty.isSet(style)) {
this.effectivePaddingTop = this._defaultPaddingTop;
}
if (!paddingRightProperty.isSet(style)) {
this.effectivePaddingRight = this._defaultPaddingRight;
}
if (!paddingBottomProperty.isSet(style)) {
this.effectivePaddingBottom = this._defaultPaddingBottom;
}
if (!paddingLeftProperty.isSet(style)) {
this.effectivePaddingLeft = this._defaultPaddingLeft;
}
this._setDefaultPaddings(result);
}
}
} else {
Expand Down Expand Up @@ -1536,18 +1554,10 @@ ViewBase.prototype.effectiveMarginTop = 0;
ViewBase.prototype.effectiveMarginRight = 0;
ViewBase.prototype.effectiveMarginBottom = 0;
ViewBase.prototype.effectiveMarginLeft = 0;
ViewBase.prototype.effectivePaddingTop = 0;
ViewBase.prototype.effectivePaddingRight = 0;
ViewBase.prototype.effectivePaddingBottom = 0;
ViewBase.prototype.effectivePaddingLeft = 0;
ViewBase.prototype.effectiveBorderTopWidth = 0;
ViewBase.prototype.effectiveBorderRightWidth = 0;
ViewBase.prototype.effectiveBorderBottomWidth = 0;
ViewBase.prototype.effectiveBorderLeftWidth = 0;
ViewBase.prototype._defaultPaddingTop = 0;
ViewBase.prototype._defaultPaddingRight = 0;
ViewBase.prototype._defaultPaddingBottom = 0;
ViewBase.prototype._defaultPaddingLeft = 0;
ViewBase.prototype._isViewBase = true;
ViewBase.prototype.recycleNativeView = 'never';
ViewBase.prototype.reusable = false;
Expand Down
Loading
Loading