Provide views, controls, and layout structures for declaring your app's user interface using SwiftUI.

Posts under SwiftUI tag

200 Posts

Post

Replies

Boosts

Views

Activity

String catalogs in packages
We have separated much of our UI into different packages to reduce complexity and compile time. When we recently tested using new .xcstrings string catalogs, we hit an unexpected problem. Strings extracted from SwiftUI components like Text or Button are extracted into the Localizable.xcstrings in the same package, but the default behaviour of Text(_ key:tableName:bundle:comment:) is to use Bundle.main. When the default behaviour of the string extraction isn't to extract to the main app target, this introduces a very fragile system where it's easy to add code that looks localised, but ends up failing lookup at runtime. I don't feel comfortable that we will always remember to define the correct module every time we create a Text. Also, other components like Button doesn't have an init that takes a Bundle, so we would also have to remember that Button(_ titleKey:action:) can now only be used in a package if we make sure that the main bundle contains a matching key. Is there a way for us to make sure that strings are always extracted to the same place as they are resolved against by default? Either by having strings in packages extracted to an xcstrings file in the main app or having Text default to resolving against the module bundle by default?
4
4
2.2k
Jun ’25
Error querying optional Codable with SwiftData
I'm building a SwiftUI app using SwiftData. In my app I have a Customer model with an optional codable structure Contact. Below is a simplified version of my model: @Model class Customer { var name: String = "" var contact: Contact? init(name: String, contact: Contact? = nil) { self.name = name self.contact = contact } struct Contact: Codable, Equatable { var phone: String var email: String var allowSMS: Bool } } I'm trying to query all the Customers that have a contact with @Query. For example: @Query(filter: #Predicate<Customer> { customer in customer.contact != nil }) var customers: [Customer] However no matter how I set the predicate I always get an error: BugDemo crashed due to an uncaught exception NSInvalidArgumentException. Reason: keypath contact not found in entity Customer. How can I fix this so that I'm able to filter by contact not nil in my Model?
2
0
204
Jun ’25
.navigationTitle disappears when using .toolbar and List inside NavigationStack (iOS 26 beta)
.navigationTitle disappears when using .toolbar and List inside NavigationStack (iOS 26 beta) Summary In iOS 26 beta, using .navigationTitle() inside a NavigationStack fails to render the title when combined with a .toolbar and a List. The title initially appears as expected after launch, but disappears after a second state transition triggered by a button press. This regression does not occur in iOS 18. Steps to Reproduce Use the SwiftUI code sample below (see viewmodel and Reload button for state transitions). Run the app on an iOS 26 simulator (e.g., iPhone 16). On launch, the view starts in .loading state (shows a ProgressView). After 1 second, it transitions to .loaded and displays the title correctly. Tap the Reload button — this sets the state back to .loading, then switches it to .loaded again after 1 second. ❌ After this second transition to .loaded, the navigation title disappears and does not return. Actual Behavior The navigation title displays correctly after the initial launch transition from .loading → .loaded. However, after tapping the “Reload” button and transitioning .loading → .loaded a second time, the title no longer appears. This suggests a SwiftUI rendering/layout invalidation issue during state-driven view diffing involving .toolbar and List. Expected Behavior The navigation title “Loaded Data” should appear and remain visible every time the view is in .loaded state. ✅ GitHub Gist including Screen Recording 👉 View Gist with full details Sample Code import SwiftUI struct ContentView: View { private let vm = viewmodel() var body: some View { NavigationStack { VStack { switch vm.state { case .loading: ProgressView("Loading...") case .loaded: List { ItemList() } Button("Reload") { vm.state = .loading DispatchQueue.main.asyncAfter(deadline: .now() + 1) { vm.state = .loaded } } .navigationTitle("Loaded Data") } } .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Menu { Text("hello") } label: { Image(systemName: "gearshape.fill") } } } } } } struct ItemList: View { var body: some View { Text("Item 1") Text("Item 2") Text("Item 3") } } @MainActor @Observable class viewmodel { enum State { case loading case loaded } var state: State = .loading init() { DispatchQueue.main.asyncAfter(deadline: .now() + 1) { self.state = .loaded } } }
2
1
170
Jun ’25
New to macOS Development. How Do I Build a Timeline Editor UI Like Logic Pro?
Hi everyone, I’m new to macOS development and working on an app idea that needs a timeline-based editor interface, similar to what you see in Logic Pro or Final Cut. The UI I want to build would have: A horizontal beat ruler that follows BPM and shows beat positions Several vertical tracks stacked below it (for things like events or markers) Horizontal zooming and scrolling A preview panel on the right side that stays in sync with the timeline I’m currently trying this in SwiftUI, but I’m running into some limitations and wondering if AppKit would be a better fit, or maybe a hybrid of the two. My questions: Where should I start when building something like this? What’s the best way to make the beat ruler and all track layers scroll together? How should I handle zooming in/out and syncing the display to a BPM timeline? Is there a clean way to integrate AppKit for the timeline view while keeping SwiftUI elsewhere?
1
0
109
Jun ’25
How to inject parameter dependency at runtime in iOS App Intent
I am trying to create an App Intent that lets a user select a day in the itinerary of a trip. The trip has to be chosen before the days available can be displayed. When the PlanActivityIntentDemo intent is ran from the shortcuts app, the trip selected is not injected into the appropriate TripItineraryDayQueryDemo Entity Query. Is there a way to get the selected trip to be injected at run time from shortcuts app. Here's some code for illustration: // Entity Definition: import AppIntents struct ShortcutsItineraryDayEntityDemo: Identifiable, Hashable, AppEntity { typealias DefaultQuery = TripItineraryDayQueryDemo static var typeDisplayRepresentation: TypeDisplayRepresentation = "Trip Itinerary Day" var displayRepresentation: DisplayRepresentation { "Trip Day" } var id: String static var defaultQuery: DefaultQuery { TripItineraryDayQueryDemo() } init() { self.id = UUID().uuidString } } struct TripItineraryDayQueryDemo: EntityQuery { // This only works in shortcut editor but not at runtime. Why? How can I fix this issue? @IntentParameterDependency<PlanActivityIntentDemo>(\.$tripEntity) var tripEntity @IntentParameterDependency<PlanActivityIntentDemo>(\.$title) var intentTitle func entities(for identifiers: [ShortcutsItineraryDayEntityDemo.ID]) async throws -> [ShortcutsItineraryDayEntityDemo] { print("entities being called with identifiers: \(identifiers)") // This method is called when the app needs to fetch entities based on identifiers. let tripsStore = TripsStore() guard let trip = tripEntity?.tripEntity.trip, let itineraryId = trip.firstItineraryId else { print("No trip or itinerary ID can be found for the selected trip.") return [] } return [] // return empty for this demo } func suggestedEntities() async throws -> [ShortcutsItineraryDayEntityDemo] { print("suggested itinerary days being called") let tripsStore = TripsStore() guard let trip = tripEntity?.tripEntity.trip, let itineraryId = trip.firstItineraryId else { print("No trip or itinerary ID found for the selected trip.") return [] } return [] } } struct PlanActivityIntentDemo: AppIntent { static var title: LocalizedStringResource { "Plan New Activity" } // The selected trip fails to get injected when intent is run from shortcut app @Parameter(title: "Trip", description: "The trip to plan an activity for", requestValueDialog: "Which trip would you like to plan an activity for?") var tripEntity: ShortcutsTripEntity @Parameter(title: "Activity Title", description: "The title of the activity", requestValueDialog: "What do you want to do or see?") var title: String @Parameter(title: "Activity Day", description: "Activity Day") var activityDay: ShortcutsItineraryDayEntity func perform() async throws -> some ProvidesDialog { // This is a demo intent, so we won't actually perform any actions. .result(dialog: "Activity '\(title)' planned") } }
0
1
121
Jun ’25
New WebView (Xcode 26 beta) doesn't resize when NavigationSplitView sidebar appears
I'm using the new Swifty WebView in 26.0 beta (17A5241e). Previously, I would wrap WKWebView in a ViewRepresentable and place it in the detail area of a NavigationSplitView. The page content correctly shrunk when the sidebar was opened. Now, the page content takes up the full width of the NavigationSplitView and the sidebar hovers over the page content with a translucent effect. This is in spite of setting .navigationSplitViewStyle(.balanced). Code below. I believe this is a problem with the new WebView not respecting size hints from parent views in the hierarchy. This is because if I replace the WebView with a centered Text view, it shifts over correctly when the sidebar is opened. struct OccludingNavSplitView: View { var body: some View { NavigationSplitView { Text("Sidebar") } detail: { WebView(url: URL(string: "https://www.google.com")!) } .navigationSplitViewStyle(.balanced) } } #Preview("Occluding sidebar") { OccludingNavSplitView() }
2
0
87
Jun ’25
TabView on IPAD (IOS18.1)
Dear friends, I am trying to use IOS18 API for TabView. Below code works well on simulator Iphone 16 Pro Max. But, it failed to show UI on simulator Ipad Pro 13 . TabView(selection: $selectedTab) { Tab("Test1", systemImage: "bubble.left.and.bubble.right", value: .translation) { TestViewOne() } Tab("Test2", systemImage: "character.textbox", value: .ruby) { TestViewTwo() } Tab("Test3", systemImage: "person.crop.circle", value: .browser) { TestViewThree() } } There are 3 tabs, none of them can show the view (TestViewOne TestViewTwo TestViewThree ) until pressing button 4 (red 4 in the attached image). The view could show in the sidebar area instead of normal UI area, Is there any suggestions for this? thank you very much!
1
0
70
Jun ’25
Scroll to top does not perform well with NavigationBarItem.TitleDisplayMode.large
Dear all, The scroll to top functionality of the tabItem does not scroll to the actual top of the view, when a list / scrollView is embedded in a tabView. Tapping the tabItem brings the view to the mid-point of the navigationTitle, leaving the navigationTitle half-blurred in the new iOS26: I believe that the same issue was present in previous iOS versions as well. Do you experience the same problem, or am I doing something wrong? The code is below. var body: some View { TabView { NavigationStack { List { ForEach(0..<100) { i in Text(i.formatted()) } } .navigationBarTitleDisplayMode(.large) .navigationTitle("List") } .tabItem { Label("List", systemImage: "list") // Tapping here while the list is scrolled down does not bring the entire list to the actual top } } } }
2
0
86
Jun ’25
Use @AppStorage with Arrays
Hey, I know you can write @AppStorage("username") var username: String = "Anonymous" to access a Value, stored In the User Defaults, and you can also overwrite him by changing the value of username. I was wondering if there is any workaround to use @AppStorage with Arrays. Because I don't find anything, but I have a lot of situations where I would use it. Thanks! Max
2
1
1.3k
Jun ’25
Displaying an editing hierarchy in macOS
The SwiftUI Navigation structures work in ways that are not intuitive to me. For example, I am trying to display a set of data that represents rankings contained in a balloting system that I have created. The ballots all have candidates that are ranked from highest preference to lowest. Normally, I try to work backwards in SwiftUI, so I built the ballot editor to take a binding to the ballot itself: struct BallotEditor: View { @Binding var ballot: Election.Ballot var maxRank: Int var body: some View { VStack { ForEach($ballot.rankings) { $ranking in CandidateRankingPicker(maxRanking: maxRank, ranking: $ranking) } } } } This is embedded into a view with a list of ballots: struct BallotsView: View { @Binding var document: ElectionDocument var body: some View { List($document.ballots) { $ballot in NavigationLink { BallotEditor(ballot: $ballot, maxRank: document.election.candidates.count) .padding() } label: { BallotListElementView(ballot: ballot) } } } } This portion works in the editor. When the ballot is selected, the editor populates the selected candidate choices, and the editing works. However, when I attempt to insert BallotsView into a TabView, the NavigationLink stops working as expected. I didn't think NavigationLink was the proper way to do this, but it had been working. TabView { Tab("Ballots", systemImage: "menucard") { BallotsView(document: $document) } Tab { CandidateView() } label: { Text("Candidates") } .tabViewStyle(.sidebarAdaptable) } This is my third iteration. I have tried using a List with selection, but in that case, I am unable to pass the binding to the detail view. I just don't understand how this works, and I am preparing a version in Cocoa so that I don't have to deal with it anymore.
2
0
65
Jun ’25
Animated Custom Transitions Crash using Swift 6
When you apply an animation to a custom Transition in Swift 6, it is likely that that the app will crash with a SwiftUI.AsyncRenderer dispatch_assert_queue_fail error. Non-animated Transitions do not crash nor do animated system transitions. If you use ViewModifiers to create an AnyTransition with the .modifier(active:, identity:) static method, there is no problem. I used the example Transition in the docs for Transition to illustrate this problem. I'm using Xcode 16.2 RC and Swift 6, running iOS 18.1.1 on an iPhone 16 Pro. I've created two separate Previews that illustrate what specifically crashes the app and what doesn't as well as a workaround for this bug. func generateRandomString() -> String { let characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" return String((0..<10).compactMap { _ in characters.randomElement() }) } // MARK: Works extension AnyTransition { struct RotatingFadeTransitionModifier: ViewModifier { let opacity: CGFloat let rotation: Angle func body(content: Content) -> some View { content .opacity(opacity) .rotationEffect(rotation) } } static var rotatingFade: AnyTransition { .asymmetric( insertion: .modifier( active: RotatingFadeTransitionModifier(opacity: 0, rotation: .degrees(30)), identity: RotatingFadeTransitionModifier(opacity: 1, rotation: .zero) ), removal: .modifier( active: RotatingFadeTransitionModifier(opacity: 0, rotation: .degrees(-30)), identity: RotatingFadeTransitionModifier(opacity: 1, rotation: .zero) ) ) } } struct WorkingTransitionView: View { @State private var text: String = "some string" var body: some View { VStack(spacing: 32) { Text("system transition: \(text)") .id(text) .transition(.slide) // Gets the explicit Button animation applied instead of // the transition animation Text("animated system transition: \(text)") .id(text) .transition(.slide.animation(.bouncy(duration: 0.5))) Text("custom transition: \(text)") .id(text) .transition(.rotatingFade) Text("animated custom transition: \(text)") .id(text) .transition(.rotatingFade.animation(.bouncy( extraBounce: 0.5))) Button("animated randomize - safe") { withAnimation(.smooth(duration: 5.45, extraBounce: 0.15)) { text = generateRandomString() } } } } } // MARK: Crashes struct RotatingFadeTransition: Transition { func body(content: Content, phase: TransitionPhase) -> some View { content .opacity(phase.isIdentity ? 1.0 : 0.0) .rotationEffect(phase.rotation) } } extension TransitionPhase { fileprivate var rotation: Angle { switch self { case .willAppear: .degrees(30) case .identity: .zero case .didDisappear: .degrees(-30) } } } struct CrashingTransitionView: View { @State private var text: String = "some string" @State private var presentCustomTransitionText: Bool = false @State private var presentAnimatedCustomTransitionText: Bool = false var body: some View { VStack(spacing: 32) { Text("on 1-5 attempts generally, animated custom Transitions will crash with a SwiftUI.AsyncRenderer dispatch_assert_queue_fail") Divider() textWithSafeSystemTransition if presentCustomTransitionText { textWithCustomTransition } if presentAnimatedCustomTransitionText { textWithAnimatedCustomTransition } Divider() Text("Randomization") Button("randomize - won't crash non-animated custom transition text") { text = generateRandomString() } Button("animated randomize - will crash any custom transition text") { withAnimation(.smooth(duration: 0.45, extraBounce: 0.15)) { text = generateRandomString() } } Divider() Text("Text Presentation") Button("present non-animated custom transition text") { presentCustomTransitionText = true } Button("present animated custom transition text") { presentAnimatedCustomTransitionText = true } } } private var textWithSafeSystemTransition: some View { Text("safe, system transition: \(text)") .id(text) .transition(.slide) } private var textWithCustomTransition: some View { Text("safe text, custom transition: \(text)") .id(text) .transition(RotatingFadeTransition()) } private var textWithAnimatedCustomTransition: some View { Text("crashing text: \(text)") .id(text) .transition(RotatingFadeTransition().animation(.smooth)) } } #Preview("Working Code") { WorkingTransitionView() } #Preview("Crashing Code") { CrashingTransitionView() }
3
1
478
Jun ’25
SwiftUI buttons behind NSToolbarView are not clickable on macOS 26 beta
Overview Starting with macOS 26 beta 1, a new NSGlassContainerView is added inside NSToolbarView. This view intercepts mouse events, so any SwiftUI Button (or other interactive view) overlaid on the title‑bar / toolbar area no longer receives clicks. (The same code works fine on macOS 15 and earlier.) Filed as FB18201935 via Feedback Assistant. Reproduction (minimal project) macOS 15 or earlier → button is clickable macOS 26 beta → button cannot be clicked (no highlight, no action call) @main struct Test_macOS26App: App { init() { // Uncomment to work around the issue (see next section) // enableToolbarClickThrough() } var body: some Scene { WindowGroup { ContentView() } .windowStyle(.hiddenTitleBar) // ⭐️ hide the title bar } } struct ContentView: View { var body: some View { NavigationSplitView { List { Text("sidebar") } } detail: { HSplitView { listWithOverlay listWithOverlay } } } private var listWithOverlay: some View { List(0..<30) { Text("item: \($0)") } .overlay(alignment: .topTrailing) { // ⭐️ overlay in the toolbar area Button("test") { print("test") } .glassEffect() .ignoresSafeArea() } } } Investigation In Xcode View Hierarchy Debugger, a layer chain NSToolbarView > NSGlassContainerView sits in front of the button. -[NSView hitTest:] on NSGlassContainerView returns itself, so the event never reaches the SwiftUI layer. Swizzling hitTest: to return nil when the result is the view itself makes the click go through: func enableToolbarClickThrough() { guard let cls = NSClassFromString("NSGlassContainerView"), let m = class_getInstanceMethod(cls, #selector(NSView.hitTest(_:))) else { return } typealias Fn = @convention(c)(AnyObject, Selector, NSPoint) -> Unmanaged<NSView>? let origIMP = unsafeBitCast(method_getImplementation(m), to: Fn.self) let block: @convention(block)(AnyObject, NSPoint) -> NSView? = { obj, pt in guard let v = origIMP(obj, #selector(NSView.hitTest(_:)), pt)?.takeUnretainedValue() else { return nil } return v === (obj as AnyObject) ? nil : v // ★ make the container transparent } method_setImplementation(m, imp_implementationWithBlock(block)) } Questions / Call for Feedback Is this an intentional behavioral change? If so, what is the recommended public API or pattern for allowing clicks to reach views overlaid behind the toolbar? Any additional data points or confirmations are welcome—please reply if you can reproduce the issue or know of an official workaround. Thanks in advance!
2
0
185
Jun ’25
SwiftUI app crashes (EXC_BAD_ACCESS) when view hierarchy becomes too large.
Hey! Our team is experiencing some issue in a large SwiftUI application. When loading large views, the app crashes with a EXC_BAD_ACCESS signal. This signal can be reported by Xcode either on the @main attribute, inside a view hierarchy, or any order property that is accessed in the view hierarchy. After some investigation we found several possible workarounds: Splitting up the view into smaller subviews Wrapping parts of the view into an AnyView, which isn't ideal. However, this only temporarily solved the issue. As the app becomes bigger, we run into this problem more frequently. When trying to reproduce this issue in a clean Xcode project, I came up with the following: struct ContentView: View { var body: some View { Text("Hello") .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} } } When running this, the app immediately crashes on an iPhone 14 (YMMV on different (newer) devices). Of course such a view is not very likely to occur, but in total a view hierarchy could have this many view modifiers. Is there some limit we should we aware of? How can we circumvent this? Thanks!
0
0
48
Jun ’25
iOS 18 beta bug: NavigationStack pushes the same view twice
Hello, community and Apple engineers. I need your help. Our app has the following issue: NavigationStack pushes a view twice if the NavigationStack is inside TabView and NavigationStack uses a navigation path of custom Hashable elements. Our app works with issues in Xcode 18 Beta 13 + iOS 18.0. The same issue happened on previous beta versions of Xcode 18. The issue isn’t represented in iOS 17.x and everything worked well before iOS 18.0 beta releases. I was able to represent the same issue in a clear project with two simple views. I will paste the code below. Several notes: We use a centralised routing system in our app where all possible routes for navigation path are implemented in a View extension called withAppRouter(). We have a enum RouterDestination that contains all possible routes and is resolved in withAppRouter() extension. We use Router class that contains @Published var path: [RouterDestination] = [] and this @Published property is bound to NavigationStack. In the real app, we need to have an access to this path property for programmatic navigation purposes. Our app uses @ObservableObject / @StateObject approach. import SwiftUI struct ContentView: View { @StateObject private var router = Router() var body: some View { TabView { NavigationStack(path: $router.path) { NavigationLink(value: RouterDestination.next, label: { Label("Next", systemImage: "plus.circle.fill") }) .withAppRouter() } } } } enum RouterDestination: Hashable { case next } struct SecondView: View { var body: some View { Text("Screen 2") } } class Router: ObservableObject { @Published var path: [RouterDestination] = [] } extension View { func withAppRouter() -> some View { navigationDestination(for: RouterDestination.self) { destination in switch destination { case .next: return SecondView() } } } } Below you can see the GIF with the issue: What I tried to do: Use iOS 17+ @Observable approach. It didn’t help. Using @State var path: [RouterDestination] = [] directly inside View seems to help. But it is not what we want as we need this property to be @Published and located inside Router class where we can get an access to it, and use for programmatic navigation if needed. I ask Apple engineers to help with that, please, and if it is a bug of iOS 18 beta, then please fix it in the next versions of iOS 18.0
12
4
1.8k
Jun ’25
SwiftUI window top left aligned on macOS 26 beta 1
We ran into a bug with our app Bezel (https://getbezel.app). When running on macOS Tahoe, windows would get partially clipped. This is because we have SwiftUI views that are larger than the window size, our SwiftUI views are supposed to be centered, which they are on macOS 13, 14, 15. But on macOS 26 (beta 1), the window contents are top-left aligned. This seems to be a bug, I have submitted FB18201269. This is my code: WindowGroup { ZStack { Color.green ZStack { Color.yellow Text("Hi") } .aspectRatio(1, contentMode: .fill) .border(.red) } } This first screenshot shows the old behavior on macOS 15: This second screenshot shows the new behavior on macOS 26 (beta 1) Can anyone confirm if this is indeed a bug, or if this an intended change in behavior?
1
0
65
Jun ’25
button is pressed when starting scrolling in iOS 18
On iOS 18, while on a modal screen, if the scrolling starts on a button, that button gets pressed, outside of a modal this doesn't reproduce, also not reproducible on older iOS versions, neither on modals or outside of them. The code to reproduce the issue: import SwiftUI struct ContentView: View { @State var presentModal = false var body: some View { Button(action: { presentModal = true }, label: { Text("open modal") }) .sheet(isPresented: $presentModal, content: { ScrollView { ForEach(0..<100, id: \.self) { index in Button(action: { print("Button \(index) tapped!") }) { Text("Button \(index)") .frame(maxWidth: .infinity) .frame(height: 100) .background(randomColor(for: index)) .padding(.horizontal) } } } }) } func randomColor(for index: Int) -> Color { let hue = Double(index % 100) / 100.0 return Color(hue: hue, saturation: 0.8, brightness: 0.8) } } #Preview { ContentView() }
7
6
670
Jun ’25
Detect when tab bar minimizes (.tabBarMinimizeBehavior)
Hi! I'm working on a iOS 26 SwiftUI prototype that adds an element to the content of a screen only when the tab bar is fully visible and not minimized (via .tabBarMinimizeBehavior). Is there any way to detect when a tab bar is minimized? My hope is that I can use a ternary operator to display something only when a boolean is true. Here's some code to illustrate my idea: struct ContentView: View { @State var isTabBarMinimized: Bool = false var body: some View { TabView { Tab("View1", systemImage: "rainbow") { // Only appears when tab bar is fully visible Color.blue .opacity(isTabBarMinimized? 0 : 1 ) } Tab("View2", systemImage: "rainbow") { View2() } Tab("View3", systemImage: "rainbow") { View3() } Tab("View4", systemImage: "rainbow") { View4() } } .tabBarMinimizeBehavior(.onScrollDown) } }
1
0
133
Jun ’25
How to do full width .sheet() on iOS 26+ with small presentation detents?
For certain contexts, I'd like to still have my .sheet() be full width even when it's at a small height. In iOS 26, the sheet is inset from the edges at small detents and expands to full width at larger detents. For example, I have a view where I have a .sheet() that has a height of about 200pts and it contains a horizontally scrolling picker that extends past the bounds of the screen. I'd like the .sheet to expand all the way to the edge when at these small detents, like it would previous to iOS 26. Is it possible to configure this? This change will break a number of existing designs :( A new ViewModifier such as enum PresentationWidth { case dynamic, fixed } func presentationWidth(_ width: PresentationWidth) -> some View would be very nice.
1
2
87
Jun ’25