From 3522ae0034783dbf2202c9d1fac44fe0e3a6b0d9 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 19 Nov 2026 15:08:53 +0000 Subject: [PATCH] fix: preserve intrinsic Apple row text beside growers --- docs/api-migrations.md | 10 ++++++++++ .../Sources/LUIAppleBackend/LUISwiftUIRoot.swift | 10 ++++++---- .../LUIAppleBackendTests.swift | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docs/api-migrations.md b/docs/api-migrations.md index e8b001b9..99d09a3b 100644 --- a/docs/api-migrations.md +++ b/docs/api-migrations.md @@ -1,5 +1,15 @@ # LUI API migration guide +### Apple row intrinsic text priority + +Non-growing `text`, `heading`, and `paragraph` children in Apple rows now +retain intrinsic width ahead of growing siblings, without requiring +`single-line`. For example, `row [button ~grow:1.0 ~text:"Tab" []; +text ~value:"✓" []]` keeps its trailing glyph visible. No wire or caller +changes are required. Flexible containers keep their existing priority; +growing text still shares the growing-child priority. Explicit `single-line` +priority is unchanged. Android and web layout are unchanged. + ### Foreground accent ink compatibility `primary` and `accent` in a foreground slot retain their accent ink color; diff --git a/platform/apple/Sources/LUIAppleBackend/LUISwiftUIRoot.swift b/platform/apple/Sources/LUIAppleBackend/LUISwiftUIRoot.swift index 8d9be866..4d64a95d 100644 --- a/platform/apple/Sources/LUIAppleBackend/LUISwiftUIRoot.swift +++ b/platform/apple/Sources/LUIAppleBackend/LUISwiftUIRoot.swift @@ -6441,13 +6441,14 @@ enum LUIRowLayoutPolicy { } static func childLayoutPriority( + kind: LUINodeKind? = nil, grow: Double?, styleClass: String? ) -> Double { - // Grow children take remaining width before non-growing flexible - // containers (including empty rows/columns). Explicit single-line - // content keeps its higher intrinsic priority; all growers stay equal. - max((grow ?? 0) > 0 ? 0.5 : 0, + // Intrinsic text precedes growers; flexible containers remain last. + let growing = (grow ?? 0) > 0 + let intrinsicText = kind == .text || kind == .heading || kind == .paragraph + return max(growing ? 0.5 : (intrinsicText ? 1 : 0), LUITextLinePolicy.layoutPriority(styleClass: styleClass)) } @@ -6530,6 +6531,7 @@ private struct LUIRowView: View { maxHeight: cross == "stretch" ? .infinity : nil ) .layoutPriority(LUIRowLayoutPolicy.childLayoutPriority( + kind: child?.kind, grow: child?.grow, styleClass: child?.styleClass )) diff --git a/platform/apple/Tests/LUIAppleBackendTests/LUIAppleBackendTests.swift b/platform/apple/Tests/LUIAppleBackendTests/LUIAppleBackendTests.swift index b5727380..87f6eb8f 100644 --- a/platform/apple/Tests/LUIAppleBackendTests/LUIAppleBackendTests.swift +++ b/platform/apple/Tests/LUIAppleBackendTests/LUIAppleBackendTests.swift @@ -1713,6 +1713,20 @@ struct LUISwiftUIBackendTests { @Test("growing Row children preserve intrinsic trailing controls") func growingRowChildrenPreserveTrailingControls() { + let growingButton = LUIRowLayoutPolicy.childLayoutPriority( + kind: .button, grow: 1, styleClass: nil) + for kind in [LUINodeKind.text, .heading, .paragraph] { + #expect(LUIRowLayoutPolicy.childLayoutPriority( + kind: kind, grow: nil, styleClass: nil) > growingButton) + #expect(LUIRowLayoutPolicy.childLayoutPriority( + kind: kind, grow: 0, styleClass: "secondary") > growingButton) + #expect(LUIRowLayoutPolicy.childLayoutPriority( + kind: kind, grow: 1, styleClass: nil) == growingButton) + } + for kind in [LUINodeKind.row, .column, .spacer] { + #expect(LUIRowLayoutPolicy.childLayoutPriority( + kind: kind, grow: nil, styleClass: nil) == 0) + } #expect(LUIRowLayoutPolicy.childLayoutPriority( grow: nil, styleClass: nil