I'm trying to achieve a specific UI design in SwiftUI where the bottom section of my List has a different background color than the top section. For example in the Medications portion of the Health app, the Your Medications Section has a different background than the top Log Section. How do I achieve this?: Here some example code. I wonder if I am supposed to use two Lists instead. If I use two Lists though and nest it in a ScrollView, the height of the lists needs to be specified. I am working with dynamic content, though so I don't think that is ideal. class ProtocolMedication {} // Example model struct HomeView: View { @Query private var protocolMedications: [ProtocolMedication] var body: some View { NavigationStack { List { // Upper sections with default background Section { Text(Content 1) } header: { Text(Log) } // Bottom section that needs different background Section { ForEach(protocolMedications) { medication in Text(medication.name) } } header: {
Search results for
SwiftUI List performance
50,605 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi,I create e swiftUI app on xcode.On the first view I display a list of all my films.On the second view, I display a toggle that dynamically change json value if the film was seen and I display a slider to note the film.I try to create a toggle on the first view to display only not showed films... I have the toggle but I fail to link to json attribute to list only these films...Can you help me ?My project : https://github.com/thomjlg/Films-APPJSON file : https://gist.githubusercontent.com/thomjlg/0782e9e8e27c346af3600bff9923f294/raw/9705fb0c6b40eae59578755b86e331bea257972b/films2.json
Hello, I have a TabView containing multiple views where one of them contains a list of items. The digital crown on the apple watch does not allow me to scroll the items in the tabview but only scrolls the list of items. Is there any way to disable that the scrolling of the list is done by the wheel or even a way to prioritize the digital crown to scroll the tabView and not the list? Thanks
I have a sample test project at https://github.com/EricG-Personal/grdb_test.gitIn ContentView.swift, I currently have one list that shows all of the items in the Database.Below that, I would like another list that shows all of the unique 'names' from the test table.I am getting lost in the details between GRBD, Combine, and SwiftUI and am not sure what the code would look like to provide the second list with the data it needs from the database while using GRDBCombine.
I'm a researcher and consultant for the web & mobile-native platform app accessibility in South Korea. in our team, each member takes charge for each platform, web, android, iOS. I'm in charge swiftUI. I tried to make a list that can reorder following next steps. I made a Custom View struct adopting View Protocol I declared variable property named 'fruit', type of [String] as @State. I declared VStack at the body as root layout. List container is in the VStack. ForEach(DynamicContentView) is iterated as Text() component into that List. for the 'ForEach', I used 'onMove(perform:)' modifier for implementing reorder by drag and drop. And last, for the 'List' container, I used 'environment' modifier to assign a 'EditMode.active' value to 'editMode' environment. There didn't seem to be any problems without using VoiceOver. but, there's some problem with VoiceOver. VoiceOver doesn't announce a dropped item's location(e.g. moved above Item, moved below Item)
There's a nasty SwiftUI bug in which a TextField disappears if placed in a HStack within a List.List { ForEach(0...200, id: .self) { index in HStack { Text(Text (index)) TextField(Test, text: .constant(TextField (index))) } }}- Screenshot: https://i.stack.imgur.com/HARDF.png- Video: https://recordit.co/X12uGct7gDThis happens when TextField is placed within a HStack / VStack / ZStack / .overlay() / .background(). It does not happen when TextField is the only child of ForEach. I have filed a bug (FB7500885) but I'm looking for ideas from the community to work around it. Here is what I've tried so far:Setting an explicit .frame() on TextFieldSetting .fixedSized() on TextFieldUsing a UITextField wrapped in a UIViewConvertible, with or without layout constraintsIs there anything else I could try?
Appears that it's well known issue/feature that still exists. Stack Overflow - https://stackoverflow.com/questions/63934037/swiftui-navigationlink-cell-in-a-form-stays-highlighted-after-detail-pop/67282150#67282150 The problem for me was that I had other SwiftUI view located between NavigationView and List and that issue arises. Don't know why, but if that view would be moved below List then the row is deselected without problem when returning from child view. But I found solution that fixed this behaviour. Added to that SwiftUI view that is between NavigationView and List, .zIndex() modifier that must be higher than for the List and now rows is deselected correctly. struct MostPopularView: View { var body: some View { VStack(alignment: .leading, spacing: 20) { SelectPeriodView() .padding(.horizontal) .onChange(of: mostPopularViewModel.selectedPeriod, perform: { _ in self.loadData() }) .zIndex(1.0) List(mostPopularViewModel.artic
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I want to display a list of 'contacts' in my app, loaded from a local Core Data sqlite database. Currently, I use UIKit, and with UITableView's cell reuse, even with 5000+ rows, the memory usage is great ... it loads at about 80MB and stays around that no matter how much I scroll up or down the list. I implemented the same list with SwiftUI List, and the memory usage while scrolling is very different ... the initial load is about the same, but each time I go down the whole list, it adds 20-30MB to the memory usage (according to Xcode). Is this a side-effect of using SwiftUI's List, or am I doing something wrong here? Here's the implementation: struct CJContactsListView: View { @SectionedFetchRequest var sectionContacts: SectionedFetchResults init() { let fetchRequest = Person.allContactsFetchRequest() _sectionContacts = SectionedFetchRequest(fetchRequest: fetchRequest, sectionIdentifier: .normalizedSectionLetter!, animation: .default) } v
How would remove the delete button in SwiftUI List rows when in Edit Mode? Note the hamburger button on the right of the row that allows rows to be re-ordered needs to continue to function.Background - Want a list that has the re-order rows functions always enabled. Edit mode seems to enable this (i.e. leave List in edit mode) however do not want the red delete button on each row.
iOS 14 introduces some laziness in certain views, like for example there are now lazy variants of HStack and VStack. I’ve been working on a SwiftUI-version of an app of mine and the findings of my research for these bugs led me to believe that Apple added some lazy optimisations to Lists as well. Unfortunately those optimisations seem to be breaking selection and presentation of detail views to a degree that they would be show stoppers for any universal app relying on List and its automatic promotion to being a split view on iPad. I filed this as FB8521674 in the Apple Feedback App. I am posting the full report here as well as these findings might be helpful to other developers who were as stuck as I am, hoping that Apple will fix this issue . Bug Report On iPad, List is supposed to present the destination of NavigationLinks when the link’s tag matches the selection binding’s value. But that only occurs if the referenced row is presently visible. Setting selection programma
I'm currently learning Swift and SwiftUI. I'm working at a MacOS app that will need to visualize a number of traces. The user must be able to scroll along the X axis of any of the traces and the other ones should be scrolling synchronously (think about a visualization similar to Apple's own Instruments app). I'm using SwiftUI Charts framework for visualizing the traces, this on MacOS 14.0 (beta at the time of writing) and Xcode 15 beta 6. The app is also built against the latest MacOS target (explicitly to use the new Charts functionalities). My implementation manages to correctly synchronize the scrolling of the separate charts using a binding in combination with the chartScrollPosition method, however the scrolling performance is really terrible (the scrolling movement is sluggish and jittery). If I disable the synchronization by removing the binding and chartScrollPosition calls, the charts can be scrolled independently with no performance issues. I have the feeling that
I'm note sure if this is well-known-issue or not but it is very odd. The problem can be reproduced with Apple's example code navigationBarItems(leading:trailing:) As you can see, list separators has extra leading space that looks like they are indented for some reason. I test above code with Playground, iPhone 13/15.3.1 they are the same. I did messing around the code and found that applying .navigationBarTitle(), .navigationBarItems() to List causes the problem. They must apply to each List item. Very odd though. This means almost all List sample code that wrapping with NavigationView are WRONG. Here is a fix I found. Although I'm not sure if I can call this is a bug but definitely either document or implementation is wrong. Could anyone explain this?
Hello, I narrowed down the problem and created a clean project. The code is below. I found similar issue on forum, it was fixed there eventually for a regular list. However it wasn't fixed for a list with children. Reproduces 100% of time, faced on macOS 11.1, I'm on 11.2 Beta (20D5029f) currently. Xcode Version 12.3 (12C33) Run the project, click the remove button 3 times - it crashes. Try and remove children part of the list, it stops crashing. The crash happens at SwiftUI`SwiftUI.OutlineListUpdater.init(base: SwiftUI.ListStyleDataSource) -> SwiftUI.OutlineListUpdater: Are there any temporary workarounds? import SwiftUI struct Item: Identifiable { let id: UUID let name: String let children: [Item]? init(id: UUID = UUID(), name: String = String(UUID().uuidString.prefix(6)), children: [Item]? = nil) { self.id = id self.name = name self.children = children } } class ViewModel: ObservableObject { @Published var items: [Item] = ViewModel.generateRandom() func remov
I am attempting to add a favorites feature to my app using a List( ) with sections. I have two arrays stored in an @EnvironmentObject which are iterated through to populate the favorites and other sections. When the arrays are modified, the content (button) moves as expected, but the action and formating does not change as expected.The screenshots below demonstrate the issue:1. Opening screen2. Clicking on the heart icon moves the item, but the color is not updated3. Clicking on the heart icon once it has moved behaves correctly, but adds the item to the favorites list a second timeThe expected behavior would be that the item moves and the action and format are updated on the first press. Here is the code for the page I am using:import SwiftUI struct ContentView: View { @EnvironmentObject var state: ApplicationState var body: some View { VStack{ List { Section(header: Text(Favorites)) { ForEach(state.favorites, id: .self) { favorite in HStack{ Button( action: { self.state.o
I am working with a simple SwiftUI List and I want to enable functionality that allows files and images to be dropped onto the List from outside the app. There is an onInsert modifier with List that allows for this, but I found that it works on macOS, but not when running the same view on iOS. I have sample code that I can't seem to post on this forum because it keeps giving me a validation error about This post contains sensitive language. Maybe this will work: Code to reproduce issue Is there anything I can do to make this work on iOS?