Skip to content

Safe area insets are not respected when setting overrideUserInterfaceStyle on a MessageView in iOS 17 #532

Open
@jmarr

Description

@jmarr

In my app, I'm setting overrideUserInterfaceStyle on my MessageView to force a dark appearance when the app is in light mode.

However, when doing this on iOS 17, the MessageView no longer respects the safe area of the view controller it's being presented in. The MessageView is presented correctly on iOS 16.

I've attached a sample project that reproduces the issue. Run the sample project on a simulator or device running iOS 17 that has a bottom safe area inset. Tap the Show Message button and you'll see the message overlaps the safe area, as shown in the screenshot below. If you comment out the line that sets overrideUserInterfaceStyle or present the message while in dark mode, the message will correctly appear above the safe area.

Screenshot showing message overlapping safe area

In stepping through the code, it looks like after calling container.layoutIfNeeded() on line 100 of TopBottomAnimation.swift, the frame of container is changed and no longer overlapping the safe area, so the safe area isn't taken into account by the call to adjustMargins.

Looking at the constraints, I don't see why container would no longer be filling its parent view, but I did notice that after the call to layoutIfNeeded, container.hasAmbigousLayout() returns true. I highly suspect this is an iOS bug.

FWIW, I did discover that container lays out correctly if I call container.superview.layoutIfNeeded() instead of container.layoutIfNeeded(), so that might be a potential fix / workaround.

I don't understand why this only occurs when setting overrideUserInterfaceStyle, but there is a comment for overrideUserInterfaceStyle in UIView.h that says "Starting in iOS 17, this also affects any nested view controllers and subviews of those view controllers.", so Apple did make changes to the behavior of that property in iOS 17.

For my own app, I'm now configuring the MessageView with the appearance I want without using overrideInterfaceStyle, but I wanted to file an issue here so you can potentially look into it further and so anyone else seeing this behavior can learn how to work around it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions