Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for 'presentationSizing' in iOS 18 #94

Open
bradleyandrew opened this issue Dec 17, 2024 · 0 comments
Open

Add Support for 'presentationSizing' in iOS 18 #94

bradleyandrew opened this issue Dec 17, 2024 · 0 comments

Comments

@bradleyandrew
Copy link

bradleyandrew commented Dec 17, 2024

With iOS 18 Apple introduced the 'presentationSizing' presentation modifier as per this documentation:
https://developer.apple.com/documentation/swiftui/view/presentationsizing(_:)

When presenting a .sheet in iOS 17, the default was to present it as full height of the iPad Display.
When presenting a .sheet in iOS 18, the default is to present it as half height of the iPad Display.

'WhatsNewView' is presented as a sheet and defaults to the smaller sized version on iOS 18.

If you include a number of 'WhatsNew.Feature' in a 'WhatsNew', a user will be forced to scroll through them on a smaller sheet in iOS 18 rather than having them presented at full height with zero scroll as they would display in iOS 17.

I apply this to my views that are used as a .sheet to solve for this issue on various iOS Versions:

extension View {
    
    func pageSheetSizing() -> some View {
        if #available(iOS 18.0, *) {
            AnyView(self.presentationSizing(.page))
        } else {
            // Fallback on earlier versions
            AnyView(self)
        }
    }
    
}

I initally tired to get it to work like this with the code below, but it did not work as 'pageSheetSizing' needs to be applied to the actual view:
.whatsNewSheet().pageSheetSizing()

I ended up settling on a custom implementation of '.whatsNewSheet()' and used it like this on the view I wanted to apply it to:

        .sheet(item: .init(
            get: { self.whatsNewIsDismissed == true ? nil : whatsNewEnvironment.whatsNew() },
            set: { self.whatsNewIsDismissed = $0 == nil }
        )) { whatsNew in
            WhatsNewView(whatsNew: whatsNew, versionStore: whatsNewEnvironment.whatsNewVersionStore, layout: whatsNewEnvironment.defaultLayout)
                .pageSheetSizing()
        }

This works to present a full height sheet in iOS 17 and iOS 18.

It would be good to have native support for this in WhatsNewKit, perhaps in 'WhatsNew.Layout' where you could specify the desired 'PresentationSizing'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant