Skip to content

Conversation

@fhasse95
Copy link
Contributor

This PR changes the alert view modifier to match the iOS behavior if no / an empty title is used.

Example SwiftUI code to test the changes:

struct ExampleView: View {
    @State private var showAlert: Bool = false
    
    var body: some View {
        Button("Show Alert") {
            self.showAlert = true
        }.alert("", isPresented: self.$showAlert) {
            Button("Yes") { }
            Button("No") { }
            Button("Cancel", role: .cancel) { }
        }
    }
}

iOS:

Android (Before):

Android (After):


Thank you for contributing to the Skip project! Please use this space to describe your change and add any labels (bug, enhancement, documentation, etc.) to help categorize your contribution.

Skip Pull Request Checklist:

  • REQUIRED: I have signed the Contributor Agreement
  • REQUIRED: I have tested my change locally with swift test
  • OPTIONAL: I have tested my change on an iOS simulator or device
  • OPTIONAL: I have tested my change on an Android emulator or device

@cla-bot cla-bot bot added the cla-signed label Jan 18, 2026
Copy link
Member

@marcprux marcprux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall, and thanks for the screenshots! Just one question about the change to an optional init Text parameter…

}

public func alert(_ title: Text, isPresented: Binding<Bool>, @ViewBuilder actions: () -> any View) -> any View {
public func alert(_ title: Text?, isPresented: Binding<Bool>, @ViewBuilder actions: () -> any View) -> any View {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change to an optional Text parameter? That doesn't match the View.alert on Darwin, where it isn't optional, so I assume it wouldn't compile for iOS if you pass a nil argument (unless I'm missing another extension somewhere)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out!

You’re right, View.alert on Darwin does indeed not accept an optional Text. I initially made the parameter optional so I could forward the “empty title” case by passing nil from the other overloads.

However, after revisiting this, I realized that this isn’t necessary as I can derive the underlying string from the Text via localizedTextString() and then handle the empty title case directly when calling the AlertPresentation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. I'll give this a trial run tonight (or maybe tomorrow) and then approve it.

I assume there aren't any corresponding https://github.com/skiptools/skip-fuse-ui/blob/main/Sources/SkipSwiftUI/Text/Text.swift changes that need to be made, since we aren't adding or removing any public API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks! 😊

Yes, as far as I’m aware, no corresponding changes in SkipFuse are needed, as the adjustments are limited to the internal SkipUI implementation and don’t affect the public API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants