Post

Replies

Boosts

Views

Activity

PresentationDetent to auto-size sheet to the height of the contained Views
(Also submitted as FB19359821) I suggest a PresentationDetent.sizeToFit or PresentationDetent.contentSize that automatically sizes the sheet to the height of the contained Views. This seems to be a common requirement for many app developers and it would be nice if this would be supported out of the box without fiddling around with the usual GeometryReader in background -> make available the height with a preference key -> .presentationDetents([.height(…)]) workarounds.
Topic: UI Frameworks SubTopic: SwiftUI
0
1
30
1w
Mitigating overlapping text for sticky section headers for a plain List in iOS 26
When preparing SwiftUI code that uses List with .listStyle(.plain) for iOS 26, the by-default sticky section headers combined with the new translucent top-bars often causes unpleasantly overlapping text: Two questions here: Is there a modifier to make section headers non-sticky? This would be helpful for cases where the translucent bar is a good fit and the section titles don't need to be sticky/pinned. I found .listStyle(.grouped) can be an alternative in some cases, but this adds a gray background / additional padding to the section titles. Is there a way to get a blurry material behind the section headers when they are sticking to the top bar? This would be good for cases where the section header is important content-wise (like in the two-column example above or for a data list categorized using sections that should be always visible as a point of reference) I found the scroll edge effects and .scrollEdgeEffectStyle(.hard, for: .top) does the trick for the top bar but doesn't affect attached sticky section headers (maybe it should?). Also I played around with .toolbarBackground(...) but this didn't do anything useful for a nav bar in my experiments.
Topic: UI Frameworks SubTopic: SwiftUI
4
0
97
2w
Adaptive automatic corner radius in containers with insets/paddings
With the correct corner radius changing in iOS 26, I wondered if there is a way to get properly rounded corners inside containers like sheets without hard-coding a constant value. Here's the results of some experiments I did, example code below. The new in Beta 4 ConcentricRectangle seems nice. Notable here is that it doesn't pick up the larger corner radii from the device corners: If you want all the corners rounded, the isUniform parameter of ConcentricRectangle seems helpful. It doesn't apply the corners in a View in the middle though, not sure if this is an oversight or if this has some purpose: ContainerRelativeShape looks ... interesting ... as of Beta 4, with the larger bottom corners rounded according to the device corners, but the actual bottom corners not fitting the device corners. With ContainerRelativeShape one can also get the middle part to have proper rounded corners in this example ... if you set the outer .containerShape(RoundedRectangle(cornerRadius: 36)) yourself. Notable here is that it then actually adapts all corners of the last card to the larger device corner radius - why it does that even with the smaller radius being explicitly set as containerShape is beyond my imagination. ContainerRelativeShape and ConcentricRectangle both feel quite similar to me, but different in ways that are not clear to me after reading the documentation. I wouldn't know when to pick which / I am not sure if these two should really be two separate things... Any insights here? I was also hoping to find a way to read the cornerRadius (both device corner radius and sheet container radius) for more complex custom-shaped views, but currently there seems no way to do that. The new in iOS 26 Beta 4 GeometryReader containerCornerInsets sounded a bit like it, but it seems of no use here, it's always zero. docs talk about windowing controls and values can be seen on iPad when the red/yellow/green window buttons become visible, so it seems unrelated here. Example code AdaptiveCorners.swift import SwiftUI enum Experiment: String, CaseIterable, Identifiable { case form case concentricRect case uniformConcentricRect case containerRelative case containerRelativeWithContainerShape case containerCornerInsets var title: String { self.rawValue } var id: String { self.rawValue } } struct ContentView: View { @State var experiment : Experiment? = .concentricRect var body: some View { NavigationStack { Form { Picker("Experiment", selection: $experiment) { ForEach(Experiment.allCases, id: \.self) { experiment in Text(experiment.title).tag(experiment) } } .pickerStyle(.inline) } } .sheet(item: $experiment) { experiment in Group { switch(experiment) { case .form: Form { Section { Text("Form + Section") Text("Form + Section") } } case .concentricRect: ShapeView { ConcentricRectangle() } case .uniformConcentricRect: ShapeView { ConcentricRectangle(corners: .concentric, isUniform: true) } case .containerRelative: ShapeView { ContainerRelativeShape() } case .containerRelativeWithContainerShape: ShapeView { ContainerRelativeShape() } .containerShape(RoundedRectangle(cornerRadius: 36)) case .containerCornerInsets: GeometryReader { geometry in Form { Text(String(describing: geometry.containerCornerInsets)) } } } } .presentationDetents([.medium, .large]) } } } struct ShapeView<S : Shape> : View { @ViewBuilder let content: () -> S var body: some View { ScrollView([.vertical]) { VStack { HStack { content() .fill(Color.yellow) .frame(height: 80) .frame(maxWidth: .infinity) content() .fill(Color.orange) .frame(height: 80) .frame(maxWidth: .infinity) } content() .fill(Color.green) .frame(height: 80) .frame(maxWidth: .infinity) } .padding() } } } #Preview { ContentView() }
Topic: UI Frameworks SubTopic: SwiftUI
2
0
403
3w
Stacked-sheets vs. nav-stack-in-a-sheet for navigation hierarchies on top of a map
I couldn't help noticing that the Maps and Find My apps make extensive use of "sheets stacked on top of each other" to represent its navigation hierarchy, with a "new content comes in from the bottom" orientation instead of a navigation stack with "new content comes in from the right side" oriented transitions. I'm interested in this topic because I have a similar navigation-hierarchy-over-a-map case in my app (with a custom map view though) and I'm torn back and forth between the approach of replicating the "stacked sheets" vs. putting a navigation stack in a sheet, esp. with the navstack approach being way more attainable with the iOS 26 glass design. I couldn't find any guidance for this kind of UI in the Human Interface Guidelines; I'm leaning towards the navstack-approach for my app; but in terms of the behavior of the SwiftUI container views in this scenario it seems a little bit of an uphill path. Any thoughts on what pattern should be preferred for presenting a deep navigational hierarchy on top of a map-like view?
Topic: Design SubTopic: General
1
0
233
3w
Sheet-like presentation on the side on iPad
Is there a way to get a sheet on the side over an interactive view with a proper glass background on iPad? Ideally, including being able to drag the sheet between medium/large-height sizes (like a sheet with presentationDetents on iPhone), similar to the Maps app: I tried the NavigationSplitView like in the NavigationCookbook example. This is somewhat like it, but it's too narrow (sidebar-like) and doesn't get the full navigation bar: I also played around with .sheet and .presentationDetents and the related modifiers, thinking I could make the sheet appear to the side; but no luck here. It seems to have all the correct behaviors, but it's always presented form-like in the center: Example code for the sheet: import SwiftUI import MapKit struct ContentView: View { var body: some View { Map() .sheet(isPresented: .constant(true)) { NavigationStack { VStack { Text("Hello") NavigationLink("Show Foo") { Text("Foo") .navigationTitle("Foo") .containerBackground(Color.clear, for: .navigation) } } } .presentationDetents([.medium, .large]) .presentationBackgroundInteraction(.enabled) } } } I also tried placing the NavigationStack as an overlay and putting a .glassEffect behind it. From the first sight, this looks okay-ish on beta 3, but seems prone to tricky gotchas and edge cases around the glass effects and related transitions. Seems like not a good approach to me, building such navigational containers myself has been a way too big time-sink for me in the past... Anyway, example code for the overlay approach: import SwiftUI import MapKit struct ContentView: View { var body: some View { Map() .overlay(alignment: .topLeading) { NavigationStack { VStack { Text("Hello") NavigationLink("Show Foo") { ScrollView { VStack { ForEach(1...30, id: \.self) { no in Button("Hello world") {} .buttonStyle(.bordered) } } .frame(maxWidth: .infinity) } .navigationTitle("Foo") .containerBackground(Color.clear, for: .navigation) } } .containerBackground(Color.clear, for: .navigation) } .frame(width: 400) .frame(height: 600) .glassEffect(.regular, in: .rect(cornerRadius: 22)) .padding() } } } Do I miss something here or is this not possible currently with built-in means of the SwiftUI API?
Topic: UI Frameworks SubTopic: SwiftUI
2
1
242
Jul ’25
Keeping the glass-style background inside a sheet with presentationDetents when navigating inside the sheet
Is there a way to keep the glass-style background on iOS 26 for a sheet with .presentationDetents when you navigate into a NavigationStack inside the sheet? Root level with glass: After following a NavigationLink inside the stack, the background is always opaque: The UI I'm building is somewhat similar to the Maps app, which resorts to showing another sheet on top of the main sheet when you select a location on the Map). I'm trying to get a similar look but with a proper navigation hierarchy inside the sheet's stack. Example code: import SwiftUI import MapKit struct ContentView: View { var body: some View { Map() .sheet(isPresented: .constant(true)) { NavigationStack { VStack { Text("Hello") NavigationLink("Show Foo") { Text("Foo") .navigationTitle("Foo") .presentationBackground(Color.clear) } } } .presentationDetents([.medium, .large]) .presentationBackgroundInteraction(.enabled) } } } #Preview { ContentView() }
Topic: UI Frameworks SubTopic: SwiftUI
1
0
190
Jul ’25
How to accept “Apple Media Services Terms and Conditions" for TestFlight/IAP when it always gives an "no connection" error?
I am testing an app with in-app-purchases via TestFlight. Recently, when I try to test buying an in-app-purchase, a prompt "Apple Media Services Terms and Conditions have changed” started to appear which is always followed by an error “no connection” (internet connection is working fine). How can one resolve this situation and get back to a working setup for testing in-app-purchases? I already tried this to no avail: different internet connection/type restarting the device, using another device signing out of iCloud and back in again
5
1
1.4k
Mar ’22
@State + didSet Property Observer
)Hi,I noticed that when you declare a view property as @State and add a didSet block to it, it will have no effect: @State var someStateValue : Int = 0 { didSet { print(someStateValue) // &lt;-- never called } }Makes sense because the property itself will be the State property wrapper and not the value.But still, it would be nice to have a way to add code to such a property being changed.Is there any way to react on a change of a @State property without making it @Published/using a ObservableObject?(same question was asked here: https://stackoverflow.com/questions/56550713/how-can-i-run-an-action-when-a-state-changes )Greetings,Ralf
1
0
11k
Sep ’19