Skip to content

Commit 80f3120

Browse files
authored
chore: updated layout tests to wait for native layer layout (#11143)
1 parent 3646f1a commit 80f3120

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Image } from '@nativescript/core/ui/image';
22
import { StackLayout } from '@nativescript/core/ui/layouts/stack-layout';
33
import { GridLayout } from '@nativescript/core/ui/layouts/grid-layout';
4-
import { PropertyChangeData, Utils } from '@nativescript/core';
4+
import { PropertyChangeData } from '@nativescript/core';
55
import * as utils from '@nativescript/core/utils';
66
import * as TKUnit from '../../tk-unit';
77
import { getColor } from '../../ui-helper';
@@ -27,8 +27,6 @@ if (__ANDROID__) {
2727
appHelpers.initImageCache(Application.android.startActivity, appHelpers.CacheMode.memory); // use memory cache only.
2828
}
2929

30-
const expectLayoutRequest = __APPLE__ && Utils.SDK_VERSION >= 18;
31-
3230
export const test_Image_Members = function () {
3331
const image = new ImageModule.Image();
3432
TKUnit.assert(types.isUndefined(image.src), 'Image.src is defined');
@@ -269,17 +267,17 @@ export const test_SettingImageSourceWhenSizedToParentDoesNotRequestLayout = ios(
269267

270268
let mainPage = helper.getCurrentPage();
271269
mainPage.content = host;
272-
TKUnit.waitUntilReady(() => host.isLoaded);
270+
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());
273275

274276
let called = false;
275277
image.requestLayout = () => (called = true);
276278
image.src = '~/assets/logo.png';
277279

278-
if (expectLayoutRequest) {
279-
TKUnit.assertTrue(called, 'image.requestLayout should be called.');
280-
} else {
281-
TKUnit.assertFalse(called, 'image.requestLayout should not be called.');
282-
}
280+
TKUnit.assertFalse(called, 'image.requestLayout should not be called.');
283281
});
284282

285283
export const test_SettingImageSourceWhenFixedWidthAndHeightDoesNotRequestLayout = ios(() => {
@@ -291,17 +289,17 @@ export const test_SettingImageSourceWhenFixedWidthAndHeightDoesNotRequestLayout
291289

292290
let mainPage = helper.getCurrentPage();
293291
mainPage.content = host;
294-
TKUnit.waitUntilReady(() => host.isLoaded);
292+
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());
295297

296298
let called = false;
297299
image.requestLayout = () => (called = true);
298300
image.src = '~/assets/logo.png';
299301

300-
if (expectLayoutRequest) {
301-
TKUnit.assertTrue(called, 'image.requestLayout should be called.');
302-
} else {
303-
TKUnit.assertFalse(called, 'image.requestLayout should not be called.');
304-
}
302+
TKUnit.assertFalse(called, 'image.requestLayout should not be called.');
305303
});
306304

307305
export const test_SettingImageSourceWhenSizedToContentShouldInvalidate = ios(() => {

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import * as helper from '../../ui-helper';
66

77
const testDir = 'ui/label';
88

9-
const expectLayoutRequest = __APPLE__ && Utils.SDK_VERSION >= 18;
10-
119
export class LabelTest extends testModule.UITest<Label> {
1210
public create(): Label {
1311
const label = new Label();
@@ -603,7 +601,11 @@ export class LabelTest extends testModule.UITest<Label> {
603601

604602
let mainPage = helper.getCurrentPage();
605603
mainPage.content = host;
606-
TKUnit.waitUntilReady(() => host.isLoaded);
604+
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());
607609

608610
let called = false;
609611
label.requestLayout = () => (called = true);
@@ -618,7 +620,7 @@ export class LabelTest extends testModule.UITest<Label> {
618620
}
619621

620622
public test_SettingTextWhenInFixedSizeGridShouldNotRequestLayout() {
621-
this.requestLayoutFixture(expectLayoutRequest, '', (label) => {
623+
this.requestLayoutFixture(false, '', (label) => {
622624
label.textWrap = false;
623625
let host = new GridLayout();
624626
host.width = 100;
@@ -629,7 +631,7 @@ export class LabelTest extends testModule.UITest<Label> {
629631
}
630632

631633
public test_ChangingTextWhenInFixedSizeGridShouldNotRequestLayout() {
632-
this.requestLayoutFixture(expectLayoutRequest, 'Hello World', (label) => {
634+
this.requestLayoutFixture(false, 'Hello World', (label) => {
633635
label.textWrap = false;
634636
let host = new GridLayout();
635637
host.width = 100;
@@ -640,7 +642,7 @@ export class LabelTest extends testModule.UITest<Label> {
640642
}
641643

642644
public test_SettingTextWhenFixedWidthAndHeightDoesNotRequestLayout() {
643-
this.requestLayoutFixture(expectLayoutRequest, '', (label) => {
645+
this.requestLayoutFixture(false, '', (label) => {
644646
label.textWrap = false;
645647
let host = new StackLayout();
646648
label.width = 100;
@@ -651,7 +653,7 @@ export class LabelTest extends testModule.UITest<Label> {
651653
}
652654

653655
public test_ChangingTextWhenFixedWidthAndHeightDoesNotRequestLayout() {
654-
this.requestLayoutFixture(expectLayoutRequest, 'Hello World', (label) => {
656+
this.requestLayoutFixture(false, 'Hello World', (label) => {
655657
label.textWrap = false;
656658
let host = new StackLayout();
657659
label.width = 100;
@@ -692,7 +694,7 @@ export class LabelTest extends testModule.UITest<Label> {
692694
}
693695

694696
public test_ChangingTextOnSingleLineTextWhenWidthIsSizedToParentAndHeightIsSizedToContentShouldNotRequestLayout() {
695-
this.requestLayoutFixture(expectLayoutRequest, 'Hello World', (label) => {
697+
this.requestLayoutFixture(false, 'Hello World', (label) => {
696698
label.textWrap = false;
697699
let host = new StackLayout();
698700
host.width = 100;

0 commit comments

Comments
 (0)