FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(core): restore the per-side padding setNative protocol by edusperoni · Pull Request #11368 · NativeScript/NativeScript · GitHub

Repository navigation

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

Filter by extension

Filter by extension .ts  (9) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
78 changes: 72 additions & 6 deletions packages/core/ui/button/index.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 { zIndexProperty, minWidthProperty, minHeightProperty, paddingInternalProperty } from '../styling/style-properties';
import { zIndexProperty, minWidthProperty, minHeightProperty, paddingInternalProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, _hasPaddingSetNativeOverrides } 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,12 +123,78 @@ export class Button extends ButtonBase {
return { value: dips, unit: 'px' };
}

// When no subclass overrides the per-side handlers, they stage into
// _pendingPadding - which only exists while [paddingInternalProperty.setNative]
// runs - and all sides commit in one native write. An override takes ownership:
// the consolidated write stands down and each side applies individually, so an
// override that does not chain to super suppresses that side entirely.
private _pendingPadding: { top: number; right: number; bottom: number; left: number };

[paddingTopProperty.getDefault](): CoreTypes.LengthType {
return { value: this._defaultPaddingTop, unit: 'px' };
}

[paddingTopProperty.setNative](value: CoreTypes.LengthType) {
const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0);
if (this._pendingPadding) {
this._pendingPadding.top = padding;
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeViewProtected, padding);
}
}

[paddingRightProperty.getDefault](): CoreTypes.LengthType {
return { value: this._defaultPaddingRight, unit: 'px' };
}

[paddingRightProperty.setNative](value: CoreTypes.LengthType) {
const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0);
if (this._pendingPadding) {
this._pendingPadding.right = padding;
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeViewProtected, padding);
}
}

[paddingBottomProperty.getDefault](): CoreTypes.LengthType {
return { value: this._defaultPaddingBottom, unit: 'px' };
}

[paddingBottomProperty.setNative](value: CoreTypes.LengthType) {
const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0);
if (this._pendingPadding) {
this._pendingPadding.bottom = padding;
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeViewProtected, padding);
}
}

[paddingLeftProperty.getDefault](): CoreTypes.LengthType {
return { value: this._defaultPaddingLeft, unit: 'px' };
}

[paddingLeftProperty.setNative](value: CoreTypes.LengthType) {
const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0);
if (this._pendingPadding) {
this._pendingPadding.left = padding;
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeViewProtected, padding);
}
}

[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);
if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
// An override owns padding application; each side applies through its own handler.
return;
}
const nativeView = this.nativeViewProtected;
this._pendingPadding = { top: nativeView.getPaddingTop(), right: nativeView.getPaddingRight(), bottom: nativeView.getPaddingBottom(), left: nativeView.getPaddingLeft() };
(<any>this)[paddingTopProperty.setNative](this.style.paddingTop);
(<any>this)[paddingRightProperty.setNative](this.style.paddingRight);
(<any>this)[paddingBottomProperty.setNative](this.style.paddingBottom);
(<any>this)[paddingLeftProperty.setNative](this.style.paddingLeft);
nativeView.setPadding(this._pendingPadding.left, this._pendingPadding.top, this._pendingPadding.right, this._pendingPadding.bottom);
this._pendingPadding = null;
}

[zIndexProperty.setNative](value: number) {
Expand Down
116 changes: 109 additions & 7 deletions packages/core/ui/button/index.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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, directionProperty, paddingInternalProperty } from '../styling/style-properties';
import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, directionProperty, paddingInternalProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, _hasPaddingSetNativeOverrides } from '../styling/style-properties';
import { textAlignmentProperty, whiteSpaceProperty, textOverflowProperty } from '../text-base';
import { layout } from '../../utils';
import { CoreTypes } from '../../core-types';
Expand Down Expand Up @@ -147,13 +147,115 @@ export class Button extends ButtonBase {
});
}

// When no subclass overrides the per-side handlers, they stage into
// _pendingPadding - which only exists while [paddingInternalProperty.setNative]
// runs - and all sides commit in one native write. An override takes ownership:
// the consolidated write stands down and each side applies individually, so an
// override that does not chain to super suppresses that side entirely.
private _pendingPadding: { top: number; right: number; bottom: number; left: number };

[paddingTopProperty.getDefault](): CoreTypes.LengthType {
return {
value: this.nativeViewProtected.contentEdgeInsets.top,
unit: 'px',
};
}

[paddingTopProperty.setNative](_value: CoreTypes.LengthType) {
if (this._pendingPadding) {
this._pendingPadding.top = layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth);
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
const nativeView = this.nativeViewProtected;
const inset = nativeView.contentEdgeInsets;
nativeView.contentEdgeInsets = new UIEdgeInsets({
top: layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth),
right: inset.right,
bottom: inset.bottom,
left: inset.left,
});
}
}

[paddingRightProperty.getDefault](): CoreTypes.LengthType {
return {
value: this.nativeViewProtected.contentEdgeInsets.right,
unit: 'px',
};
}

[paddingRightProperty.setNative](_value: CoreTypes.LengthType) {
if (this._pendingPadding) {
this._pendingPadding.right = layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth);
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
const nativeView = this.nativeViewProtected;
const inset = nativeView.contentEdgeInsets;
nativeView.contentEdgeInsets = new UIEdgeInsets({
top: inset.top,
right: layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth),
bottom: inset.bottom,
left: inset.left,
});
}
}

[paddingBottomProperty.getDefault](): CoreTypes.LengthType {
return {
value: this.nativeViewProtected.contentEdgeInsets.bottom,
unit: 'px',
};
}

[paddingBottomProperty.setNative](_value: CoreTypes.LengthType) {
if (this._pendingPadding) {
this._pendingPadding.bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth);
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
const nativeView = this.nativeViewProtected;
const inset = nativeView.contentEdgeInsets;
nativeView.contentEdgeInsets = new UIEdgeInsets({
top: inset.top,
right: inset.right,
bottom: layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth),
left: inset.left,
});
}
}

[paddingLeftProperty.getDefault](): CoreTypes.LengthType {
return {
value: this.nativeViewProtected.contentEdgeInsets.left,
unit: 'px',
};
}

[paddingLeftProperty.setNative](_value: CoreTypes.LengthType) {
if (this._pendingPadding) {
this._pendingPadding.left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth);
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
const nativeView = this.nativeViewProtected;
const inset = nativeView.contentEdgeInsets;
nativeView.contentEdgeInsets = new UIEdgeInsets({
top: inset.top,
right: inset.right,
bottom: inset.bottom,
left: layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth),
});
}
}

[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),
});
if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
// An override owns padding application; each side applies through its own handler.
return;
}
const nativeView = this.nativeViewProtected;
const inset = nativeView.contentEdgeInsets;
this._pendingPadding = { top: inset.top, right: inset.right, bottom: inset.bottom, left: inset.left };
(<any>this)[paddingTopProperty.setNative](this.style.paddingTop);
(<any>this)[paddingRightProperty.setNative](this.style.paddingRight);
(<any>this)[paddingBottomProperty.setNative](this.style.paddingBottom);
(<any>this)[paddingLeftProperty.setNative](this.style.paddingLeft);
nativeView.contentEdgeInsets = new UIEdgeInsets(this._pendingPadding);
this._pendingPadding = null;
}

[textAlignmentProperty.setNative](value: CoreTypes.TextAlignmentType) {
Expand Down
88 changes: 81 additions & 7 deletions packages/core/ui/label/index.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Label as LabelDefinition } from '.';
import { Background } from '../styling/background';
import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, directionProperty, paddingInternalProperty } from '../styling/style-properties';
import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, directionProperty, paddingInternalProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, _hasPaddingSetNativeOverrides } from '../styling/style-properties';
import { booleanConverter } from '../core/view-base';
import { View, CSSType } from '../core/view';
import { CoreTypes } from '../../core-types';
Expand Down Expand Up @@ -228,13 +228,87 @@ export class Label extends TextBase implements LabelDefinition {
});
}

// When no subclass overrides the per-side handlers, they stage into
// _pendingPadding - which only exists while [paddingInternalProperty.setNative]
// runs - and all sides commit in one native write. An override takes ownership:
// the consolidated write stands down and each side applies individually, so an
// override that does not chain to super suppresses that side entirely.
private _pendingPadding: { top: number; right: number; bottom: number; left: number };

[paddingTopProperty.setNative](_value: CoreTypes.LengthType) {
if (this._pendingPadding) {
this._pendingPadding.top = layout.toDeviceIndependentPixels(this.effectivePaddingTop);
} else if (_hasPaddingSetNativeOverrides(this, Label.prototype)) {
const nativeView = this.nativeTextViewProtected;
const inset = nativeView.padding;
nativeView.padding = new UIEdgeInsets({
top: layout.toDeviceIndependentPixels(this.effectivePaddingTop),
right: inset.right,
bottom: inset.bottom,
left: inset.left,
});
}
}

[paddingRightProperty.setNative](_value: CoreTypes.LengthType) {
if (this._pendingPadding) {
this._pendingPadding.right = layout.toDeviceIndependentPixels(this.effectivePaddingRight);
} else if (_hasPaddingSetNativeOverrides(this, Label.prototype)) {
const nativeView = this.nativeTextViewProtected;
const inset = nativeView.padding;
nativeView.padding = new UIEdgeInsets({
top: inset.top,
right: layout.toDeviceIndependentPixels(this.effectivePaddingRight),
bottom: inset.bottom,
left: inset.left,
});
}
}

[paddingBottomProperty.setNative](_value: CoreTypes.LengthType) {
if (this._pendingPadding) {
this._pendingPadding.bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom);
} else if (_hasPaddingSetNativeOverrides(this, Label.prototype)) {
const nativeView = this.nativeTextViewProtected;
const inset = nativeView.padding;
nativeView.padding = new UIEdgeInsets({
top: inset.top,
right: inset.right,
bottom: layout.toDeviceIndependentPixels(this.effectivePaddingBottom),
left: inset.left,
});
}
}

[paddingLeftProperty.setNative](_value: CoreTypes.LengthType) {
if (this._pendingPadding) {
this._pendingPadding.left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft);
} else if (_hasPaddingSetNativeOverrides(this, Label.prototype)) {
const nativeView = this.nativeTextViewProtected;
const inset = nativeView.padding;
nativeView.padding = new UIEdgeInsets({
top: inset.top,
right: inset.right,
bottom: inset.bottom,
left: layout.toDeviceIndependentPixels(this.effectivePaddingLeft),
});
}
}

[paddingInternalProperty.setNative](_value: string) {
this.nativeTextViewProtected.padding = new UIEdgeInsets({
top: layout.toDeviceIndependentPixels(this.effectivePaddingTop),
right: layout.toDeviceIndependentPixels(this.effectivePaddingRight),
bottom: layout.toDeviceIndependentPixels(this.effectivePaddingBottom),
left: layout.toDeviceIndependentPixels(this.effectivePaddingLeft),
});
if (_hasPaddingSetNativeOverrides(this, Label.prototype)) {
// An override owns padding application; each side applies through its own handler.
return;
}
const nativeView = this.nativeTextViewProtected;
const padding = nativeView.padding;
this._pendingPadding = { top: padding.top, right: padding.right, bottom: padding.bottom, left: padding.left };
(<any>this)[paddingTopProperty.setNative](this.style.paddingTop);
(<any>this)[paddingRightProperty.setNative](this.style.paddingRight);
(<any>this)[paddingBottomProperty.setNative](this.style.paddingBottom);
(<any>this)[paddingLeftProperty.setNative](this.style.paddingLeft);
nativeView.padding = new UIEdgeInsets(this._pendingPadding);
this._pendingPadding = null;
}
}

Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL