Skip to content

Commit 7a3552a

Browse files
authored
fix(ios): layout validity status during layout changed event (#11218)
1 parent 43d8882 commit 7a3552a

5 files changed

Lines changed: 27 additions & 25 deletions

File tree

apps/automated/src/ui/image/image-tests.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,8 @@ export const test_SettingImageSourceWhenSizedToParentDoesNotRequestLayout = ios(
268268
let mainPage = helper.getCurrentPage();
269269
mainPage.content = host;
270270

271-
const nativeHostView = host.nativeViewProtected as UIView;
272-
273-
// Check if native view layer is still marked as dirty before proceeding
274-
TKUnit.waitUntilReady(() => host.isLoaded && nativeHostView?.layer && !nativeHostView.layer.needsLayout());
271+
// Check if view is loaded and layout is valid
272+
TKUnit.waitUntilReady(() => host.isLoaded && host.isLayoutValid);
275273

276274
let called = false;
277275
image.requestLayout = () => (called = true);
@@ -290,10 +288,8 @@ export const test_SettingImageSourceWhenFixedWidthAndHeightDoesNotRequestLayout
290288
let mainPage = helper.getCurrentPage();
291289
mainPage.content = host;
292290

293-
const nativeHostView = host.nativeViewProtected as UIView;
294-
295-
// Check if native view layer is still marked as dirty before proceeding
296-
TKUnit.waitUntilReady(() => host.isLoaded && nativeHostView?.layer && !nativeHostView.layer.needsLayout());
291+
// Check if view is loaded and layout is valid
292+
TKUnit.waitUntilReady(() => host.isLoaded && host.isLayoutValid);
297293

298294
let called = false;
299295
image.requestLayout = () => (called = true);

apps/automated/src/ui/label/label-tests.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,8 @@ export class LabelTest extends testModule.UITest<Label> {
602602
let mainPage = helper.getCurrentPage();
603603
mainPage.content = host;
604604

605-
const nativeHostView = host.nativeViewProtected as UIView;
606-
607-
// Check if native view layer is still marked as dirty before proceeding
608-
TKUnit.waitUntilReady(() => host.isLoaded && nativeHostView?.layer && !nativeHostView.layer.needsLayout());
605+
// Check if view is loaded and layout is valid
606+
TKUnit.waitUntilReady(() => host.isLoaded && host.isLayoutValid);
609607

610608
let called = false;
611609
label.requestLayout = () => (called = true);

apps/automated/src/ui/view/view-tests-layout-event.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ export function test_event_LayoutChanged_GetActualSize() {
1818
helper.do_PageTest_WithStackLayout_AndButton(test);
1919
}
2020

21+
export function test_event_LayoutChanged_IsLayoutValid() {
22+
const test = function (views: Array<View>) {
23+
let buttonLayoutChanged = false;
24+
let expectedValidResult;
25+
26+
views[1].on(View.layoutChangedEvent, (args) => {
27+
expectedValidResult = (args.object as View).isLayoutValid;
28+
buttonLayoutChanged = true;
29+
});
30+
31+
TKUnit.waitUntilReady(() => buttonLayoutChanged, 5);
32+
TKUnit.assertFalse(expectedValidResult);
33+
};
34+
35+
helper.do_PageTest_WithStackLayout_AndButton(test);
36+
}
37+
2138
export function test_event_LayoutChanged_Listeners() {
2239
const test = function (views: Array<View>) {
2340
let buttonLayoutChanged = false;

packages/core/ui/core/view/index.ios.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ export class View extends ViewCommon {
9595

9696
public measure(widthMeasureSpec: number, heightMeasureSpec: number): void {
9797
const measureSpecsChanged = this._setCurrentMeasureSpecs(widthMeasureSpec, heightMeasureSpec);
98-
const forceLayout = (this._privateFlags & PFLAG_FORCE_LAYOUT) === PFLAG_FORCE_LAYOUT;
99-
if (this.nativeViewProtected && (forceLayout || measureSpecsChanged)) {
98+
if (this.nativeViewProtected && (this.isLayoutRequested || measureSpecsChanged)) {
10099
// first clears the measured dimension flag
101100
this._privateFlags &= ~PFLAG_MEASURED_DIMENSION_SET;
102101

@@ -122,7 +121,7 @@ export class View extends ViewCommon {
122121
this.layoutNativeView(left, top, right, bottom);
123122
}
124123

125-
const needsLayout = boundsChanged || (this._privateFlags & PFLAG_LAYOUT_REQUIRED) === PFLAG_LAYOUT_REQUIRED;
124+
const needsLayout = boundsChanged || this.isLayoutRequired;
126125
if (needsLayout) {
127126
let position: Position;
128127

@@ -259,9 +258,8 @@ export class View extends ViewCommon {
259258

260259
get isLayoutValid(): boolean {
261260
if (this.nativeViewProtected) {
262-
return this._isLayoutValid;
261+
return !this.isLayoutRequested;
263262
}
264-
265263
return false;
266264
}
267265

packages/core/ui/core/view/view-common.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ export abstract class ViewCommon extends ViewBase {
128128
private _measuredWidth: number;
129129
private _measuredHeight: number;
130130

131-
protected _isLayoutValid: boolean;
132131
private _cssType: string;
133132

134133
private _localAnimations: Set<Animation>;
@@ -1009,7 +1008,7 @@ export abstract class ViewCommon extends ViewBase {
10091008
//END Style property shortcuts
10101009

10111010
get isLayoutValid(): boolean {
1012-
return this._isLayoutValid;
1011+
return false;
10131012
}
10141013

10151014
get cssType(): string {
@@ -1070,11 +1069,6 @@ export abstract class ViewCommon extends ViewBase {
10701069
}
10711070
}
10721071

1073-
public requestLayout(): void {
1074-
this._isLayoutValid = false;
1075-
super.requestLayout();
1076-
}
1077-
10781072
public abstract onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void;
10791073
public abstract onLayout(left: number, top: number, right: number, bottom: number): void;
10801074
public abstract layoutNativeView(left: number, top: number, right: number, bottom: number): void;
@@ -1111,7 +1105,6 @@ export abstract class ViewCommon extends ViewBase {
11111105
* Returns two booleans - the first if "boundsChanged" the second is "sizeChanged".
11121106
*/
11131107
_setCurrentLayoutBounds(left: number, top: number, right: number, bottom: number): { boundsChanged: boolean; sizeChanged: boolean } {
1114-
this._isLayoutValid = true;
11151108
const boundsChanged: boolean = this._oldLeft !== left || this._oldTop !== top || this._oldRight !== right || this._oldBottom !== bottom;
11161109
const sizeChanged: boolean = this._oldRight - this._oldLeft !== right - left || this._oldBottom - this._oldTop !== bottom - top;
11171110
this._oldLeft = left;

0 commit comments

Comments
 (0)