Search results for

SwiftUI List performance

50,605 results found

Post

Replies

Boosts

Views

Activity

SwiftUI - List multi selection move / reorder (works on Mac but not on iOS)
How can I enable multi-select and then move / reorder selected items in a List with ForEach (in SwiftUI)? I tried the following code. On Mac it works fine - it allows me to select multiple items, and then drag them all together to another place in the list. On iOS it allows me to move individual items with drag-and-drop, and allows me to enter Edit mode to select multiple items but when I try to move the selected items with drag-and-drop, they can be dragged but they can't be dropped elsewhere in the list: struct ExampleListView: View { @State var items = [Dave, Tom, Jeremy, Luke, Phil] @State var selectedItems: Set = .init() var body: some View { NavigationView { List(selection: $selectedItems) { ForEach(items, id: .self) { item in Text(item).tag(item) }.onMove(perform: move) } .navigationBarItems(trailing: EditButton()) } } func move(from source: IndexSet, to destination: Int) { items.move(fromOffsets: source, toOffset: destination) } } This code has the
1
0
1.5k
Mar ’24
SwiftUI List Row Background not Rendering Off Screen
Hi there! I've been able to get the .listRowBackground() modifier to work in SwiftUI (with iOS 15) but am experiencing a weird graphical issue where rows that start off screen do not have the correct background colour until they appear on screen then off again. Not sure if there is a way to force all elements to render but as far as I can see I am using the modifier correctly. Any help is greatly appreciated! Anthony Code: var body: some View { ZStack { Color.theme.darkTheme .edgesIgnoringSafeArea(.all) VStack { ForEach(Array(array.keys), id: .self) { key in List { ForEach(systemFaults[key]!, id: .self) { fault in GenericItemView(label: FAULT ID, item: (fault.faultID)) GenericItemView(label: IS ACTIVE, item: fault.isActive ? TRUE : FALSE) GenericItemView(label: SET COUNT, item: (fault.setCount)) GenericItemView(label: LAST TIMESTAMP, item: (fault.timestampSeconds) secs) } .listRowBackground(Color.theme.darkerAccent) } Spacer() } } } } Generic Item view is a simple HStack to display the text
3
0
1.5k
Jan ’22
Reply to What are the best state management practices for SwiftUI?
What performance ? Display speed ?I would be careful to draw quick conclusions, as SwiftUI is still very much evolving. What is true today maybe wrong tomorrow.I would not bother too much unless there is a clear performance issue.Or is it another performance aspect ?Note you should also consider ease of maintenance. SwiftUI designers recommend modular design.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’20
Swiftui - Pressing button in a list also actions another button
List(am.students) { item in HStack { Text(item.name).font(fancyFont) Spacer() Button(item.casual ? All Paid : Reverse All Paid) { // Issue: pressing this button also results in Remove button action being invoked. item.casual = !item.casual }.foregroundColor(Color(white: 0.15)) .padding(3) .overlay( RoundedRectangle(cornerRadius: 5) .stroke(Color(white: 0.5), lineWidth: 3) ) Spacer().frame(width: 40) Button(Remove) { Task { await am.delete(student: item) } }.foregroundColor(Color(white: 0.15)) .frame(width: 80) .padding(3) .overlay( RoundedRectangle(cornerRadius: 5) .stroke(Color(white: 0.5), lineWidth: 3) ) } } When All Paid button is pressed, the Remove button action also executes. At a guess, the list row executes everything? Mark
2
0
897
May ’24
Destination view for multiple list item in SwiftUI
I have list item, and all item destination view routed to EndView, how can I add multiple destination view for every item, for example: when I click the first item it will open EndView, when I click the second item it will open NewView...., any idea will be appreciated. Option: struct InnerOptionValues: Codable { var title: String var image: String var isAddSection: Bool var isUseToggle: Bool var headerTitle: String } extension Option { static let listValues: [InnerOptionValues] = [ .init(title: title1, image: image1, isAddSection: true, isUseToggle: false, headerTitle: ), .init(title: title2,image: image2, isAddSection: false, isUseToggle: false, headerTitle: ), .init(title: title3, image: image3, isAddSection: false, isUseToggle: false, headerTitle: ), .init(title: 4, image: image4, isAddSection: false, isUseToggle: false, headerTitle: ), .init(title: 5, image: image5, isAddSection: false, isUseToggle: false, headerTitle: ), ] InnerView: struct InnerView: View { let value: InnerOptionValues var bod
0
0
513
Apr ’21
SwiftUI List produces random offset when modifying content from a modal view presented above it
Backstory - I wanted to create a SwiftUI List with a collapsible header. Based on some StackOverflow answers for the basic idea, I came up with this (this is just a gist of the component): GeometryReader { proxy in List { SwiftUI.Section( header: Color.clear .frame(height: self.headerSize.height) .listRowInsets(EdgeInsets()) .anchorPreference(key: ScrollOffsetPreferenceKey.self, value: .bounds) { proxy[$0].origin } .onPreferenceChange(ScrollOffsetPreferenceKey.self, perform: self.handleOffsetChange), footer: self.blankFooterView ) {} self.content } .environment(.defaultMinListHeaderHeight, .leastNonzeroMagnitude) } In short, there's an empty section the size of the header in the List, based on which I get an offset while scrolling and can move the header accordingly And it has been working great, except the only problem so far is that if you have a screen with this component and there's another screen presented modally that causes modifications of the content of th
0
0
531
Aug ’22
Why the first item I tap on a SwiftUI List becomes nil when present it in a sheet
Can someone please explain why the first time I tap on an item from the list, the selectedItem?.name becomes nil? The second time it shows the right item name correctly but not the first time, why?. I was expecting that to have a value even the first time since I'm setting it in the onTapGesture method selectedItem = item. // model struct Item: Identifiable{ var id = UUID() var name:String } // SwiftUI struct UpdateStateProperty: View { var items:[Item] = [Item(name: Oranges), Item(name: Apples), Item(name: Cookies) ] @State private var presentView = false @State private var selectedItem: Item? var body: some View { List{ ForEach(items){ item in HStack{ Text(item.name) }.onTapGesture { selectedItem = item presentView.toggle() } } } .sheet(isPresented: $presentView){ Text((selectedItem?.name) as String) } } }
2
0
2.8k
Nov ’21
Retrieve specific data from specific document from Firestore without using a List in SwiftUI
I connected my SwiftUI app to Firebase Auth and Firestore, and the data is stored in a collection. My question is, how can I read specific data from the signed In user and display his data without a List? An example, the navigation title will be like this: Text(Hello (The signed In user's name)) and so on. Any helpful sites or videos?
0
0
283
May ’22
How to change List's cell background color alternately in SwiftUI?
Hi,I want to create diffrent cell with seperate color in a section. Reagards,Ranjeetstruct AlternateListCellView: View { var body: some View { List { Section(header: Text(Show alternate cell)) { ForEach(1...5) { row in Text(Row Index = (row)) } // row variable is out of scope, so its throw compile time error. Is any other way to create section and cell? // Kindly correct me if Any mistake. // .listRowBackground(row % 2 == 0 ? Color.orange : Color.yellow) } } .background(Color.purple) } }
1
0
1.8k
Aug ’19
iOS 16 SwiftUI TextField in section header (List)
If run this code on iOS16 keyboard gets dismissed randomly when character is typed (please see gif), while on iOS15 everything is fine. struct ContentView: View { let names = [Holly, Josh, Rhonda, Ted] @State var text = var body: some View { List { Section { ForEach(searchResults, id: .self) { name in Text(name) } } header: { TextField(Search for name, text: $text) } } } var searchResults: [String] { if text.isEmpty { return names } else { return names.filter { $0.contains(text) } } } } It happens when content is in a section with a header. Is it bug from apple introduced in iOS16 or am I doing something wrong? Has anyone had the same issue?
2
0
935
Dec ’22
Unable to set initial selection state of SwiftUI `List` in iOS 14
I'm using a NavigationView to display split view style sidebar and secondary views similar to the Fruta sample app. My sidebar has a List of NavigationLink's, and my secondary view displays that linked content. However, I'm not able to set an initial default selection (i.e. blue background selected row style) for the List in my sidebar. When the app first launches, there's no selection state in the List for the secondary view that is displayed until the user taps a row of the List. I have a @State var called selection that's passed into my Sidebar, which references it as a @Binding. selection has a value, which is why it's unexpected that the resulting List doesn't show it as selected when first displayed. EXPECTED RESULTS When the app launches, I would expect the List selects the initial row matching the @Binding that's passed in. ACTUAL RESULTS When the app launches, The List has no initial selected row until the user taps a row. I'd like for th
4
0
3.3k
Aug ’20
SwiftUI - List inside horizontal ScrollView on MacOS, unable to scroll horizontally
I'm trying to create a horizontal ScrollView, inside which there are many Lists that can scroll vertically. like MacOS Finder app The problem is, horizontal scroll is not happening if mouse scroll is triggered inside List. My guess is that scroll event is captured by List, ScrollView has no chance to handle. ScrollView(.horizontal) { List List List ... } Does any has any workaround?
3
0
2.1k
Oct ’20
SwiftUI: .textSelection(.enabled) not working in List on iOS 18
In iOS 18, textSelection(_:) not working in List. So, I can't copy text. Works on iOS 17 and earlier. Is this a bug and is there any solution? // Not Work: iOS 18 struct ContentView: View { var body: some View { List { Text(Hello World) .textSelection(.enabled) } } } // Work: iOS 18 and earlier struct ContentView: View { var body: some View { Text(Hello World) .textSelection(.enabled) } }
4
0
932
Sep ’24