Skip to content

Safe-area adjustment incorrectly expands a centered Text background #964

Description

@Kyle-Ye

Description

When a Text view with a background is displayed as the root content of a full-screen iPhone app, OpenSwiftUI incorrectly applies the root safe-area insets while resolving the centered view in its local coordinate space.

Because the text is centered and does not touch any safe-area edge, those insets should not affect its bounds. The incorrect adjustment expands the resolved text container and its red background vertically.

SwiftUI preserves the intrinsic bounds of the text for the same code.

This issue may not be visible in a smaller fixed-size snapshot, such as 200 × 200, because the incorrect safe-area adjustment is exposed by a regular app-sized layout.

Reproduction

import OpenSwiftUI

@main
struct ExampleApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .background(Color.red)
    }
}

Expected behavior

The red background should tightly match the intrinsic bounds of the text, as it does with SwiftUI.

Expected behavior using SwiftUI

Actual behavior

OpenSwiftUI expands the red background vertically into a large rectangle while the text remains centered inside it.

Actual behavior using OpenSwiftUI

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: layoutLayout, geometry, safe area, alignment, stacks, or sizing.impact: visual-diffVisual mismatch, screenshot diff, or rendering fidelity issue.type: bugSomething is not working correctly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions