Skip to content

Commit 8c4796d

Browse files
authored
Merge branch 'main' into fix/multiwindow-followups
2 parents 2a4cdf3 + 2b2842e commit 8c4796d

17 files changed

Lines changed: 339 additions & 683 deletions

‎packages/core/ui/button/index.android.ts‎

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ButtonBase } from './button-common';
22
import { PseudoClassHandler } from '../core/view';
3-
import { zIndexProperty, minWidthProperty, minHeightProperty, paddingInternalProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, _hasPaddingSetNativeOverrides } from '../styling/style-properties';
3+
import { zIndexProperty, minWidthProperty, minHeightProperty, paddingInternalProperty } from '../styling/style-properties';
44
import { Length } from '../styling/length-shared';
55
import { textAlignmentProperty } from '../text-base';
66
import { CoreTypes } from '../../core-types';
@@ -123,78 +123,12 @@ export class Button extends ButtonBase {
123123
return { value: dips, unit: 'px' };
124124
}
125125

126-
// When no subclass overrides the per-side handlers, they stage into
127-
// _pendingPadding - which only exists while [paddingInternalProperty.setNative]
128-
// runs - and all sides commit in one native write. An override takes ownership:
129-
// the consolidated write stands down and each side applies individually, so an
130-
// override that does not chain to super suppresses that side entirely.
131-
private _pendingPadding: { top: number; right: number; bottom: number; left: number };
132-
133-
[paddingTopProperty.getDefault](): CoreTypes.LengthType {
134-
return { value: this._defaultPaddingTop, unit: 'px' };
135-
}
136-
137-
[paddingTopProperty.setNative](value: CoreTypes.LengthType) {
138-
const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0);
139-
if (this._pendingPadding) {
140-
this._pendingPadding.top = padding;
141-
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
142-
org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeViewProtected, padding);
143-
}
144-
}
145-
146-
[paddingRightProperty.getDefault](): CoreTypes.LengthType {
147-
return { value: this._defaultPaddingRight, unit: 'px' };
148-
}
149-
150-
[paddingRightProperty.setNative](value: CoreTypes.LengthType) {
151-
const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0);
152-
if (this._pendingPadding) {
153-
this._pendingPadding.right = padding;
154-
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
155-
org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeViewProtected, padding);
156-
}
157-
}
158-
159-
[paddingBottomProperty.getDefault](): CoreTypes.LengthType {
160-
return { value: this._defaultPaddingBottom, unit: 'px' };
161-
}
162-
163-
[paddingBottomProperty.setNative](value: CoreTypes.LengthType) {
164-
const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0);
165-
if (this._pendingPadding) {
166-
this._pendingPadding.bottom = padding;
167-
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
168-
org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeViewProtected, padding);
169-
}
170-
}
171-
172-
[paddingLeftProperty.getDefault](): CoreTypes.LengthType {
173-
return { value: this._defaultPaddingLeft, unit: 'px' };
174-
}
175-
176-
[paddingLeftProperty.setNative](value: CoreTypes.LengthType) {
177-
const padding = Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0);
178-
if (this._pendingPadding) {
179-
this._pendingPadding.left = padding;
180-
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
181-
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeViewProtected, padding);
182-
}
183-
}
184-
185126
[paddingInternalProperty.setNative](_value: string) {
186-
if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
187-
// An override owns padding application; each side applies through its own handler.
188-
return;
189-
}
190-
const nativeView = this.nativeViewProtected;
191-
this._pendingPadding = { top: nativeView.getPaddingTop(), right: nativeView.getPaddingRight(), bottom: nativeView.getPaddingBottom(), left: nativeView.getPaddingLeft() };
192-
(<any>this)[paddingTopProperty.setNative](this.style.paddingTop);
193-
(<any>this)[paddingRightProperty.setNative](this.style.paddingRight);
194-
(<any>this)[paddingBottomProperty.setNative](this.style.paddingBottom);
195-
(<any>this)[paddingLeftProperty.setNative](this.style.paddingLeft);
196-
nativeView.setPadding(this._pendingPadding.left, this._pendingPadding.top, this._pendingPadding.right, this._pendingPadding.bottom);
197-
this._pendingPadding = null;
127+
const left = this.effectivePaddingLeft + Length.toDevicePixels(this.style.borderLeftWidth, 0);
128+
const top = this.effectivePaddingTop + Length.toDevicePixels(this.style.borderTopWidth, 0);
129+
const right = this.effectivePaddingRight + Length.toDevicePixels(this.style.borderRightWidth, 0);
130+
const bottom = this.effectivePaddingBottom + Length.toDevicePixels(this.style.borderBottomWidth, 0);
131+
this.nativeViewProtected.setPadding(left, top, right, bottom);
198132
}
199133

200134
[zIndexProperty.setNative](value: number) {

‎packages/core/ui/button/index.ios.ts‎

Lines changed: 7 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ControlStateChangeListener } from '../core/control-state-change';
22
import { ButtonBase } from './button-common';
33
import { View, PseudoClassHandler } from '../core/view';
4-
import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, directionProperty, paddingInternalProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, _hasPaddingSetNativeOverrides } from '../styling/style-properties';
4+
import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, directionProperty, paddingInternalProperty } from '../styling/style-properties';
55
import { textAlignmentProperty, whiteSpaceProperty, textOverflowProperty } from '../text-base';
66
import { layout } from '../../utils';
77
import { CoreTypes } from '../../core-types';
@@ -147,115 +147,13 @@ export class Button extends ButtonBase {
147147
});
148148
}
149149

150-
// When no subclass overrides the per-side handlers, they stage into
151-
// _pendingPadding - which only exists while [paddingInternalProperty.setNative]
152-
// runs - and all sides commit in one native write. An override takes ownership:
153-
// the consolidated write stands down and each side applies individually, so an
154-
// override that does not chain to super suppresses that side entirely.
155-
private _pendingPadding: { top: number; right: number; bottom: number; left: number };
156-
157-
[paddingTopProperty.getDefault](): CoreTypes.LengthType {
158-
return {
159-
value: this.nativeViewProtected.contentEdgeInsets.top,
160-
unit: 'px',
161-
};
162-
}
163-
164-
[paddingTopProperty.setNative](_value: CoreTypes.LengthType) {
165-
if (this._pendingPadding) {
166-
this._pendingPadding.top = layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth);
167-
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
168-
const nativeView = this.nativeViewProtected;
169-
const inset = nativeView.contentEdgeInsets;
170-
nativeView.contentEdgeInsets = new UIEdgeInsets({
171-
top: layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth),
172-
right: inset.right,
173-
bottom: inset.bottom,
174-
left: inset.left,
175-
});
176-
}
177-
}
178-
179-
[paddingRightProperty.getDefault](): CoreTypes.LengthType {
180-
return {
181-
value: this.nativeViewProtected.contentEdgeInsets.right,
182-
unit: 'px',
183-
};
184-
}
185-
186-
[paddingRightProperty.setNative](_value: CoreTypes.LengthType) {
187-
if (this._pendingPadding) {
188-
this._pendingPadding.right = layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth);
189-
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
190-
const nativeView = this.nativeViewProtected;
191-
const inset = nativeView.contentEdgeInsets;
192-
nativeView.contentEdgeInsets = new UIEdgeInsets({
193-
top: inset.top,
194-
right: layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth),
195-
bottom: inset.bottom,
196-
left: inset.left,
197-
});
198-
}
199-
}
200-
201-
[paddingBottomProperty.getDefault](): CoreTypes.LengthType {
202-
return {
203-
value: this.nativeViewProtected.contentEdgeInsets.bottom,
204-
unit: 'px',
205-
};
206-
}
207-
208-
[paddingBottomProperty.setNative](_value: CoreTypes.LengthType) {
209-
if (this._pendingPadding) {
210-
this._pendingPadding.bottom = layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth);
211-
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
212-
const nativeView = this.nativeViewProtected;
213-
const inset = nativeView.contentEdgeInsets;
214-
nativeView.contentEdgeInsets = new UIEdgeInsets({
215-
top: inset.top,
216-
right: inset.right,
217-
bottom: layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth),
218-
left: inset.left,
219-
});
220-
}
221-
}
222-
223-
[paddingLeftProperty.getDefault](): CoreTypes.LengthType {
224-
return {
225-
value: this.nativeViewProtected.contentEdgeInsets.left,
226-
unit: 'px',
227-
};
228-
}
229-
230-
[paddingLeftProperty.setNative](_value: CoreTypes.LengthType) {
231-
if (this._pendingPadding) {
232-
this._pendingPadding.left = layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth);
233-
} else if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
234-
const nativeView = this.nativeViewProtected;
235-
const inset = nativeView.contentEdgeInsets;
236-
nativeView.contentEdgeInsets = new UIEdgeInsets({
237-
top: inset.top,
238-
right: inset.right,
239-
bottom: inset.bottom,
240-
left: layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth),
241-
});
242-
}
243-
}
244-
245150
[paddingInternalProperty.setNative](_value: string) {
246-
if (_hasPaddingSetNativeOverrides(this, Button.prototype)) {
247-
// An override owns padding application; each side applies through its own handler.
248-
return;
249-
}
250-
const nativeView = this.nativeViewProtected;
251-
const inset = nativeView.contentEdgeInsets;
252-
this._pendingPadding = { top: inset.top, right: inset.right, bottom: inset.bottom, left: inset.left };
253-
(<any>this)[paddingTopProperty.setNative](this.style.paddingTop);
254-
(<any>this)[paddingRightProperty.setNative](this.style.paddingRight);
255-
(<any>this)[paddingBottomProperty.setNative](this.style.paddingBottom);
256-
(<any>this)[paddingLeftProperty.setNative](this.style.paddingLeft);
257-
nativeView.contentEdgeInsets = new UIEdgeInsets(this._pendingPadding);
258-
this._pendingPadding = null;
151+
this.nativeViewProtected.contentEdgeInsets = new UIEdgeInsets({
152+
top: layout.toDeviceIndependentPixels(this.effectivePaddingTop + this.effectiveBorderTopWidth),
153+
left: layout.toDeviceIndependentPixels(this.effectivePaddingLeft + this.effectiveBorderLeftWidth),
154+
bottom: layout.toDeviceIndependentPixels(this.effectivePaddingBottom + this.effectiveBorderBottomWidth),
155+
right: layout.toDeviceIndependentPixels(this.effectivePaddingRight + this.effectiveBorderRightWidth),
156+
});
259157
}
260158

261159
[textAlignmentProperty.setNative](value: CoreTypes.TextAlignmentType) {

‎packages/core/ui/core/properties/index.ts‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ const enum ValueSource {
3535
Keyframe = 4,
3636
}
3737

38+
/** `sourceKey` of every registered `CssProperty`, by css name. */
39+
const cssValueSourceKeys: Record<string, symbol> = Object.create(null);
40+
41+
/**
42+
* Whether the style still carries what the cascade last wrote for the property.
43+
* A `CssProperty` keeps one value: a local value both suppresses the css write and
44+
* takes the slot, so clearing it leaves the property at its default with the css
45+
* value gone. The cascade has to write it again rather than skip it as unchanged.
46+
*/
47+
export function _isCssValueStillApplied(style: unknown, cssLocalName: string, value: unknown): boolean {
48+
const sourceKey = cssValueSourceKeys[cssLocalName];
49+
if (sourceKey === undefined) {
50+
// Applied through the view rather than the style; nothing to verify.
51+
return true;
52+
}
53+
54+
// A reset leaves no source behind, so it is in effect precisely when nothing else claimed the property.
55+
return style[sourceKey] === (isResetValue(value) ? undefined : ValueSource.Css);
56+
}
57+
3858
function print(map) {
3959
const symbols = Object.getOwnPropertySymbols(map);
4060
for (const symbol of symbols) {
@@ -755,6 +775,8 @@ export class CssProperty<T extends Style, U> {
755775
return;
756776
}
757777

778+
this._localValueVersion++;
779+
758780
const reset = isResetValue(newValue) || newValue === '';
759781
let value: U;
760782

@@ -939,6 +961,8 @@ export class CssProperty<T extends Style, U> {
939961
if (this.cssLocalName !== this.cssName) {
940962
Object.defineProperty(cls.prototype, this.cssLocalName, this.localValueDescriptor);
941963
}
964+
965+
cssValueSourceKeys[this.cssLocalName] = this.sourceKey;
942966
}
943967

944968
public isSet(instance: T): boolean {
@@ -1205,14 +1229,20 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
12051229
}
12061230
};
12071231

1208-
const setFunc = (valueSource: ValueSource) =>
1209-
function (this: T, boxedValue: any): void {
1232+
const setFunc = (valueSource: ValueSource) => {
1233+
const isLocalWrite = valueSource === ValueSource.Local;
1234+
1235+
return function (this: T, boxedValue: any): void {
12101236
const view = this.viewRef.get();
12111237
if (!view) {
12121238
Trace.write(`${boxedValue} not set to view's property because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn);
12131239
return;
12141240
}
12151241

1242+
if (isLocalWrite) {
1243+
this._localValueVersion++;
1244+
}
1245+
12161246
const reset = isResetValue(boxedValue) || boxedValue === '';
12171247
const currentValueSource: number = this[sourceKey] || ValueSource.Default;
12181248

@@ -1314,6 +1344,7 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
13141344
});
13151345
}
13161346
};
1347+
};
13171348

13181349
const setDefaultFunc = setFunc(ValueSource.Default);
13191350
const setInheritedFunc = setFunc(ValueSource.Inherited);

0 commit comments

Comments
 (0)