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

SwiftUI Documentation

Posts under SwiftUI subtopic

Post

Replies

Boosts

Views

Activity

A Summary of the WWDC25 Group Lab - SwiftUI
At WWDC25 we launched a new type of Lab event for the developer community - Group Labs. A Group Lab is a panel Q&A designed for a large audience of developers. Group Labs are a unique opportunity for the community to submit questions directly to a panel of Apple engineers and designers. Here are the highlights from the WWDC25 Group Lab for SwiftUI. What's your favorite new feature introduced to SwiftUI this year? The new rich text editor, a collaborative effort across multiple Apple teams. The safe area bar, simplifying the management of scroll view insets, safe areas, and overlays. NavigationLink indicator visibility control, a highly requested feature now available and back-deployed. Performance improvements to existing components (lists, scroll views, etc.) that come "for free" without requiring API adoption. Regarding performance profiling, it's recommended to use the new SwiftUI Instruments tool when you have a good understanding of your code and notice a performance drop after a specific change. This helps build a mental map between your code and the profiler's output. The "cause-and-effect graph" in the tool is particularly useful for identifying what's triggering expensive view updates, even if the issue isn't immediately apparent in your own code. My app is primarily UIKit-based, but I'm interested in adopting some newer SwiftUI-only scene types like MenuBarExtra or using SwiftUI-exclusive features. Is there a better way to bridge these worlds now? Yes, "scene bridging" makes it possible to use SwiftUI scenes from UIKit or AppKit lifecycle apps. This allows you to display purely SwiftUI scenes from your existing UIKit/AppKit code. Furthermore, you can use SwiftUI scene-specific modifiers to affect those scenes. Scene bridging is a great way to introduce SwiftUI into your apps. This also allows UIKit apps brought to Vision OS to integrate volumes and immersive spaces. It's also a great way to customize your experience with Assistive Access API. Can you please share any bad practices we should avoid when integrating Liquid Glass in our SwiftUI Apps? Avoid these common mistakes when integrating liquid glass: Overlapping Glass: Don't overlap liquid glass elements, as this can create visual artifacts. Scrolling Content Collisions: Be cautious when using liquid glass within scrolling content to prevent collisions with toolbar and navigation bar glass. Unnecessary Tinting: Resist the urge to tint the glass for branding or other purposes. Liquid glass should primarily be used to draw attention and convey meaning. Improper Grouping: Use the GlassEffectContainer to group related glass elements. This helps the system optimize rendering by limiting the search area for glass interactions. Navigation Bar Tinting: Avoid tinting navigation bars for branding, as this conflicts with the liquid glass effect. Instead, move branding colors into the content of the scroll view. This allows the color to be visible behind the glass at the top of the view, but it moves out of the way as the user scrolls, allowing the controls to revert to their standard monochrome style for better readability. Thanks for improving the performance of SwiftUI List this year. How about LazyVStack in ScrollView? Does it now also reuse the views inside the stack? Are there any best practices for improving the performance when using LazyVStack with large number of items? SwiftUI has improved scroll performance, including idle prefetching. When using LazyVStack with a large number of items, ensure your ForEach returns a static number of views. If you're returning multiple views within the ForEach, wrap them in a VStack to signal to SwiftUI that it's a single row, allowing for optimizations. Reuse is handled as an implementation detail within SwiftUI. Use the performance instrument to identify expensive views and determine how to optimize your app. If you encounter performance issues or hitches in scrolling, use the new SwiftUI Instruments tool to diagnose the problem. Implementing the new iOS 26 tab bar seems to have very low contrast when darker content is underneath, is there anything we should be doing to increase the contrast for tab bars? The new design is still in beta. If you're experiencing low contrast issues, especially with darker content underneath, please file feedback. It's generally not recommended to modify standard system components. As all apps on the platform are adopting liquid glass, feedback is crucial for tuning the experience based on a wider range of apps. Early feedback, especially regarding contrast and accessibility, is valuable for improving the system for all users. If I’m starting a new multi-platform app (iOS/iPadOS/macOS) that will heavily depend on UIKit/AppKit for the core structure and components (split, collection, table, and outline views), should I still use SwiftUI to manage the app lifecycle? Why? Even if your new multi-platform app heavily relies on UIKit/AppKit for core structure and components, it's generally recommended to still use SwiftUI to manage the app lifecycle. This sets you up for easier integration of SwiftUI components in the future and allows you to quickly adopt new SwiftUI features. Interoperability between SwiftUI and UIKit/AppKit is a core principle, with APIs to facilitate going back and forth between the two frameworks. Scene bridging allows you to bring existing SwiftUI scenes into apps that use a UIKit lifecycle, or vice versa. Think of it not as a binary choice, but as a mix of whatever you need. I’d love to know more about the matchedTransitionSource API you’ve added - is it a native way to have elements morph from a VStack to a sheet for example? What is the use case for it? The matchedTransitionSource API helps connect different views during transitions, such as when presenting popovers or other presentations from toolbar items. It's a way to link the user interaction to the presented content. For example, it can be used to visually connect an element in a VStack to a sheet. It can also be used to create a zoom effect where an element appears to enlarge, and these transitions are fully interactive, allowing users to swipe. It creates a nice, polished experience for the user. Support for this API has been added to toolbar items this year, and it was already available for standard views.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
739
Jun ’25
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
3
0
453
30m
SwiftData & CloudKit: Arrays of Codable Structs Causing NSKeyedUnarchiveFromData Error
I have SwiftData models containing arrays of Codable structs that worked fine before adding CloudKit capability. I believe they are the reason I started seeing errors after enabling CloudKit. Example model: @Model final class ProtocolMedication { var times: [SchedulingTime] = [] // SchedulingTime is Codable // other properties... } After enabling CloudKit, I get this error logged to the console: 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release CloudKit Console shows this times data as "plain text" instead of "bplist" format. Other struct/enum properties display correctly (I think) as "bplist" in CloudKit Console. The local SwiftData storage handled these arrays fine - this issue only appeared with CloudKit integration. What's the recommended approach for storing arrays of Codable structs in SwiftData models that sync with CloudKit?
3
1
122
4h
Concentric corners not working
I want the gray view to have concentric corners with the device border. That works. Then I want the blue rectangle to have concentric corners with the gray view. That does not work. Instead the blue rectangle is also concentric with the device border. Once I add other content like a Text element, the corner radius breaks. How can I make this work? .containerShape does not take a ConcentricContainerShape. struct ContentView: View { var body: some View { List { Text("Content") } .overlay(alignment: .bottom) { content } .ignoresSafeArea(.all, edges: .bottom) } var content: some View { VStack(alignment: .leading) { Rectangle() .foregroundStyle(.blue) .frame(width: 100, height: 100) .clipShape(.rect(corners: .concentric, isUniform: true)) Text("Custom Container") } .padding(20) .frame(maxWidth: .infinity, alignment: .leading) .background(Color.gray, in: .rect(corners: .concentric, isUniform: true)) .padding(15) } }
2
0
69
16h
Preventing animation glitch when dismissing a Menu with glassEffect
Hi everyone, I’m running into a strange animation glitch when using a Menu inside a glassEffect container. Here’s a minimal example: import SwiftUI struct ContentView: View { @Namespace private var namespace var body: some View { ZStack { Image(.background) .resizable() .frame(maxWidth: .infinity, maxHeight: .infinity) .ignoresSafeArea() GlassEffectContainer { HStack { Button("b1") {} Button("b2") {} Button("b3") {} Button("b4") {} Button("b5") {} Menu { Button("t1") { } Button("t2") { } Button("t3") { } Button("t4") { } Button("t5") { } } label: { Text("Menu") } } } .padding(.horizontal) .frame(height: 50) .glassEffect() } } } What happens: The bar looks fine initially: When you open the Menu, the entire bar morphs into the menu: When dismissing, the bar briefly animates into a solid rectangle before reapplying the glass effect: Questions: Is there a way to prevent that brief rectangle animation when dismissing the menu? If not, is it possible to avoid the morphing altogether and have the menu simply overlay on top of the bar instead of replacing it? Any ideas or workarounds would be greatly appreciated!
0
0
181
19h
Popovers are broken on Catalyst builds without portrait support
On macOS 15.2, any Mac Catalyst project that does not support portrait iPad orientation will no longer be able to successfully show the contents of any popover controls. This does not appear to be a problem on earlier versions of macOS and it only affects Mac Catalyst builds, not "Designed for iPad" builds. STEPS TO REPRODUCE Create a project that utilizes Mac Catalyst. Create a simple button that shows a popover with simple content. Remove Portrait as a supported orientation. Run the project on macOS 15.2 as a Mac Catalyst build. Note that the content inside the popover is not shown the popover is shown. Run the project as Designed for iPad. Note that the popover content shows correctly.
3
2
297
20h
Button Glass Style Incorrect in Sheet + ScrollView on Mac Catalyst 26
Hi everyone! I've encountered an issue when using Sheet + ScrollView on Mac Catalyst: the buttons in the toolbar appear with an abnormal gray color. import SwiftUI struct ContentView: View { var body: some View { VStack { } .sheet(isPresented: .constant(true)) { Sheet() } } } struct Sheet: View { var body: some View { NavigationStack { ScrollView { // <-- no issue if use List } .toolbar { Button(action: {}) { // <-- 👀 weird gray color Image(systemName: "checkmark") } } } } } Steps to Reproduce: On macOS 26.0 beta 9, use Xcode 26.0 beta 7 to create an iOS project and enable Mac Catalyst. Paste the code above. Select the Mac Catalyst scheme and run the project. The buttons in the toolbar show a strange gray appearance. If you change the ScrollView to a List in the code, the issue does not occur. FB20120285
0
0
196
1d
SwiftData and CloudKit: NSKeyedUnarchiveFromData Error
I just made a small test app that uses SwiftData with CloudKit capability. I created a simple Book model as seen below. It looks like enums and structs when used with CloudKit capability all trigger this error: 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release I fixed the error by using genreRaw String and using a computed property to use it in the app, but it popped back up after adding the ReadingProgress struct Should I ignore the error and assume Apple still supports enums and codable structs when using SwiftData with CloudKit? import SwiftData @Model class Book { var title: String = "" var author: String = "" var genreRaw: String = Genre.fantasy.rawValue var review: String = "" var rating: Int = 3 var progress: ReadingProgress? var genre: Genre { get { Genre(rawValue: genreRaw) ?? Genre.fantasy } set { genreRaw = newValue.rawValue } } init(title: String, author: String, genre: Genre, review: String, rating: Int, progress: ReadingProgress? = nil) { self.title = title self.author = author self.genre = genre self.review = review self.rating = rating self.progress = progress } } struct ReadingProgress: Codable { var currentPage: Int var totalPages: Int var isFinished: Bool var percentComplete: Double { guard totalPages > 0 else { return 0 } return Double(currentPage) / Double(totalPages) * 100 } } enum Genre: String, Codable, CaseIterable { case fantasy case scienceFiction case mystery case romance var displayName: String { switch self { case .fantasy: return "Fantasy" case .scienceFiction: return "Science Fiction" case .mystery: return "Mystery" case .romance: return "Romance" } } }
0
1
214
1d
WebView makes website content unaccessible on the top/bottom edges
I'm being faced with an issue when using SwiftUI's WebView on iOS 26. In many websites, the top/bottom content is unaccessible due to being under the app's toolbars. It feels like the WebView doesn't really understand the safe areas where it's being shown, because the content should start right below the navigation bar, and only when the user scrolls down, the content should move under the bar (but it's always reachable if the users scroll back up). Here's a demo of the issue: Here's a 'fix' by ensuring that the content of the WebView never leaves its bounds. But as you can see, it feels out of place on iOS 26 (would be fine on previous OS versions if you had a fully opaque toolbar): Code: struct ContentView: View { var body: some View { NavigationStack { WebView(url: URL(string: "https://apple.com")).toolbar { ToolbarItem(placement: .primaryAction) { Button("Top content covered, unaccessible.") {} } } } } } Does anyone know if there's a way to fix it using some sort of view modifier combination or it's just broken as-is?
6
1
152
1d
SwiftUI #Previews: How to populate with data
Suppose you have a view: struct Library: View { @State var books = [] var body: some View { VStack { ... Button("add Book") { .... } } } Such that Library view holds a Book array that gets populated internally via a button that opens a modal – or something alike. How can I use #Peviews to preview Library with a pre-populated collection? Suppose I have a static books – dummy – array in my code just for that; still, what's the best way to use that to preview the Library view?
4
0
61
1d
The new navigationLinkIndicatorVisibility modifier crashes on < iOS 26
This new modifier is supposedly backported to iOS 17, but on attempting to use it on the latest iOS 18.5, this happens: Symbol not found: _$s7SwiftUI17EnvironmentValuesV33_navigationIndicatorVisibilityABIAA0G0OvpMV This happens with any usage of the modifier. An availability check won't save you either. The cruelest part of this is that I only need the modifier on iOS 26, lmao. Am I just missing something?
Topic: UI Frameworks SubTopic: SwiftUI
7
0
162
1d
iOS 26 navigationTransition .zoom issue
When I dismiss a view presented with .navigationTransition(.zoom), the source view gets a weird background (black or white depending on the appearance) for a couple of seconds, and then it disappears. Here’s a simple code example. import SwiftUI struct NavigationTransition: View { @Namespace private var namespace @State private var isSecondViewPresented = false var body: some View { NavigationStack { ZStack { DetailView(namespace: namespace) .onTapGesture { isSecondViewPresented = true } } .fullScreenCover(isPresented: $isSecondViewPresented) { SecondView() .navigationTransition(.zoom(sourceID: "world", in: namespace)) } } } } struct DetailView: View { var namespace: Namespace.ID var body: some View { ZStack { Color.blue Text("Hello World!") .foregroundStyle(.white) .matchedTransitionSource(id: "world", in: namespace) } .ignoresSafeArea() } } struct SecondView: View { var body: some View { ZStack { Color.green Image(systemName: "globe") .foregroundStyle(Color.red) } .ignoresSafeArea() } } #Preview { NavigationTransition() }
2
4
107
1d
SwiftUI List optional refreshable
Currently refreshable modifier does not support nil as a value and there's no way of disabling refreshable without recreating the whole view. There are a few posts showing how refreshable could be optionally disabled on scrollViews using: \EnvironmentValues.refresh as? WritableKeyPath<EnvironmentValues, RefreshAction?> https://stackoverflow.com/a/77587703 However, this approach doesn't seem to work with Lists. Has anyone find any solutions for this?
0
0
129
1d
Source view disappearing when interrupting a zoom navigation transition
When I use the .zoom transition in a navigation stack, I get a glitch when interrupting the animation by swiping back before it completes. When doing this, the source view disappears. I can still tap it to trigger the navigation again, but its not visible on screen. This seems to be a regression in iOS 26, as it works as expected when testing on iOS 18. Has someone else seen this issue and found a workaround? Is it possible to disable interrupting the transition? Filed a feedback on the issue FB19601591 Screen recording: https://share.icloud.com/photos/04cio3fEcbR6u64PAgxuS2CLQ Example code @State var showDetail = false @Namespace var namespace var body: some View { NavigationStack { ScrollView { showDetailButton } .navigationTitle("Title") .navigationBarTitleDisplayMode(.inline) .navigationDestination(isPresented: $showDetail) { Text("Detail") .navigationTransition(.zoom(sourceID: "zoom", in: namespace)) } } } var showDetailButton: some View { Button { showDetail = true } label: { Text("Show detail") .padding() .background(.green) .matchedTransitionSource(id: "zoom", in: namespace) } } }
Topic: UI Frameworks SubTopic: SwiftUI
4
3
79
2d
macOS 26: retain cycle detected when navigation link label contains a Swift Chart
I'm running into an issue where my application will hang when switching tabs. The issue only seems to occur when I include a Swift Chart in a navigation label. The application does not hang If I replace the chart with a text field. This appears to only hang when running on macOS 26. When running on iOS (simulator) or visionOS (simulator, on-device) I do not observe a hang. The same code does not hang on macOS 15. Has any one seen this behavior? The use case is that my root view is a TabView where the first tab is a summary of events that have occurred. This summary is embedded in a NavigationStack and has a graph of events over the last week. I want the user to be able to click that graph to get additional information regarding the events (ie: a detail page or break down of events). Initially, the summary view loads fine and displays appropriately. However, when I switch to a different tab, the application will hang when I switch back to the summary view tab. In Xcode I see the following messages === AttributeGraph: cycle detected through attribute 162104 === === AttributeGraph: cycle detected through attribute 162104 === === AttributeGraph: cycle detected through attribute 162104 === === AttributeGraph: cycle detected through attribute 162104 === === AttributeGraph: cycle detected through attribute 162104 === A simple repro is the following import SwiftUI import Charts @main struct chart_cycle_reproApp: App { var body: some Scene { WindowGroup { TabView { Tab("Chart", systemImage: "chart.bar") { NavigationStack { NavigationLink { Text("this is an example of clicking the chart") } label: { Chart { BarMark( x: .value("date", "09/03"), y: .value("birds", 3) ) // additional marks trimmed } .frame(minHeight: 200, maxHeight: .infinity) } } } Tab("List", systemImage: "list.bullet") { Text("This is an example") } } } } }
0
0
117
2d
HideAllTips launch argument does not work in xctestplan
The launch argument -com.apple.TipKit.HideAllTips 1 does not work if it is defined in xctestplan arguments passed on launch. I tested it with the apple provided example app, where I created simple UI test and added xctestplan with launch argument -com.apple.TipKit.HideAllTips 1. The app does not hide the tips when it is running the UI Tests. Is there any solution that works? Thanks for reply.
1
0
34
2d
tabViewBottomAccessory selective hidden bug
import SwiftUI struct ContentView: View { @State private var selection = 1 var body: some View { TabView(selection: $selection) { Tab("1", systemImage: "1.circle", value: 1) { Text("Tab 1") } Tab("2", systemImage: "2.circle", value: 2) { Text("Tab 2") } } .tabViewBottomAccessory { if selection == 1 { Text("Bottom Bar for Tab 1") } } } } With this structure, I'm supposing when I select tab 2, the bottom accessory will be hidden, but it is not hidden for the first time, after I click back to tab 1, then click tab 2, it is hidden. I think this is a bug?
0
0
51
2d
Changing the color of SwiftUI Link
Hi, I have trouble changing the color of the text of Link in SwiftUI. I tried with this code: Link("https://www.mylink.com/", destination: URL(string: "https://www.mylink.com/")!) .foregroundColor(Color.green) and this code: HStack(spacing: 0) { Link("https://www.mylink.com/", destination: URL(string: "https://www.mylink.com/")!) } .foregroundColor(Color.green) The link keeps getting the accent color. EDIT: I want to add that it used to work and I think the issue came with a beta of Xcode 26. I think that was around the beta 4 or beta 5. Is it a change of the APIs or a bug?
Topic: UI Frameworks SubTopic: SwiftUI
0
0
69
2d
How to use iOS15-specific modifiers in SwiftUI on iOS 14 and earlier?
There are many new iOS15-specific modifiers that were added in SwiftUI. For example, we have a .focused() modifier, which can be used like this: TextField("Username", text: $username) .focused($focusedField, equals: .username) However, this code fails to compile if the app supports iOS 14 and earlier. How can I make this code to compile? Ideally, I'd like to do something like this: TextField("Username", text: $username) #if os(iOS, 15.0, *) .focused($focusedField, equals: .username) #endif But obviously this won't work because #if os() can only specify the target OS, not the version.. Thanks!
3
0
5.9k
3d
SwiftUI TextField input is super laggy for SwiftData object
have a SwiftUI View where I can edit financial transaction information. The data is stored in SwiftData. If I enter a TextField element and start typing, it is super laggy and there are hangs of 1-2 seconds between each input (identical behaviour if debugger is detached). On the same view I have another TextField that is just attached to a @State variable of that view and TextField updates of that value work flawlessly. So somehow the hangs must be related to my SwiftData object but I cannot figure out why. This used to work fine until a few months ago and then I could see the performance degrading. I have noticed that when I use a placeholder variable like @State private var transactionSubject: String = "" and link that to the TextField, the performance is back to normal. I am then using .onSubmit { self.transaction.subject = self.transactionSubject } to update the value in the end but this again causes a 1 s hang. :/ Below the original code sample with some unnecessary stuff removed: struct EditTransactionView: View { @Environment(\.modelContext) var modelContext @Environment(\.dismiss) var dismiss @State private var testValue: String = "" @Bindable var transaction: Transaction init(transaction: Transaction) { self.transaction = transaction let transactionID = transaction.transactionID let parentTransactionID = transaction.transactionMasterID _childTransactions = Query(filter: #Predicate<Transaction> {item in item.transactionMasterID == transactionID }, sort: \Transaction.date, order: .reverse) _parentTransactions = Query(filter: #Predicate<Transaction> {item in item.transactionID == parentTransactionID }, sort: \Transaction.date, order: .reverse) print(_parentTransactions) } //Function to keep text length in limits func limitText(_ upper: Int) { if self.transaction.icon.count > upper { self.transaction.icon = String(self.transaction.icon.prefix(upper)) } } var body: some View { ZStack { Form{ Section{ //this one hangs TextField("Amount", value: $transaction.amount, format: .currency(code: Locale.current.currency?.identifier ?? "USD")) //this one works perfectly TextField("Test", text: $testValue) HStack{ TextField("Enter subject", text: $transaction.subject) .onAppear(perform: { UITextField.appearance().clearButtonMode = .whileEditing }) Divider() TextField("Select icon", text: $transaction.icon) .keyboardType(.init(rawValue: 124)!) .multilineTextAlignment(.trailing) } } } .onDisappear(){ if transaction.amount == 0 { // modelContext.delete(transaction) } } .onChange(of: selectedItem, loadPhoto) .navigationTitle("Transaction") .navigationBarTitleDisplayMode(.inline) .toolbar{ Button("Cancel", systemImage: "trash"){ modelContext.delete(transaction) dismiss() } } .sheet(isPresented: $showingImagePickerView){ ImagePickerView(isPresented: $showingImagePickerView, image: $image, sourceType: .camera) } .onChange(of: image){ let data = image?.pngData() if !(data?.isEmpty ?? false) { transaction.photo = data } } .onAppear(){ cameraManager.requestPermission() setDefaultVendor() setDefaultCategory() setDefaultGroup() } .sheet(isPresented: $showingAmountEntryView){ AmountEntryView(amount: $transaction.amount) } } } }
2
0
111
3d
Toolbar bottomBar in DocumentGroup App disappears
In my own fairly complex DocumentGroup app, I've been having a problem with bottom bar items appearing briefly when first drawn, and then disappearing. This seems to be caused by the invalidation of one or more views in the hierarchy. In Apple's own WritingApp, which is designed to demonstrate DocumentGroup, adding a bottom bar item to the toolbar demonstrates the problem: This toolbar is on the StoryView: ToolbarItem() { Button("Show Story", systemImage: "book") { isShowingSheet.toggle() } .sheet(isPresented: $isShowingSheet) { StorySheet(story: document.story, isShowingSheet: $isShowingSheet) .presentationSizing(.page) } } // This does not persist ToolbarItem(placement: .bottomBar) { Button("Foo") { } } } My 'Foo' button is new. What happens is that it persists for a few seconds; its disappearance coincides with the writing of the file to disk, it seems. I would dearly like it to persist! I've tried adding an ID, setting the toolbar visibility and so on, but no luck. Anyone had this working?
Topic: UI Frameworks SubTopic: SwiftUI
0
0
102
3d