Search results for

SwiftUI List performance

50,605 results found

Post

Replies

Boosts

Views

Activity

SwiftUI List row expansion causes weird bounce effect
When using a List in SwiftUI, expanding row items using anything other than the default DisclosureGroupStyle seems to cause a bounce during expansion/collapse. What is the recommended way to avoid this bounce? Link to code: https://github.com/dannys42-bugs/BugListExpansion (includes a small video demonstrating the issue)
2
0
995
Aug ’24
Why list menu items not shown in SwiftUI project?
I have list item menu project in SwiftUI, my project work, but I have list icons, they are not shown in list view, even I was try to use system image, there is not any change on screen, any idea? struct MasterView: View { let view1 = Menu(name:Home, image:image_home, destination:.home) let view2 = Menu(name:View 1, image:image_view1, destination:.view1) let view3 = Menu(name:View 3, image:image_view2, destination:.view2) var body: some View { let menus: [Menu] = [view1, view2, view3] return List { ForEach(menus) { menu in self.destinationView(menu: menu) }}} func destinationView(menu: Menu) - some View { switch menu.destination { case .view1: return NavigationLink( destination: AnyView(View1(menu: menu)) ) { Text((menu.name)) } case .view2: return NavigationLink( destination: AnyView(View2(menu: menu)) ) { Text((menu.name)) } default: return NavigationLink( destination: AnyView(HomeView(menu: menu)) ) { Text((menu.name)) }}}} Model.swift: /// Main menu item for the
5
0
1.6k
Apr ’21
Dynamically change sort order a SwiftUI Sectioned List
I'm trying to dynamically change the sort order to sections SwiftUI list. The Core Data model consists of an Item Entity with a group and timestamp attribute. import SwiftUI import CoreData struct ContentView: View { @Environment(.managedObjectContext) private var viewContext @State var counter: UInt32 = 0 @State var order: SortOrder = .reverse @SectionedFetchRequest( sectionIdentifier: .group!, sortDescriptors: [SortDescriptor(.timestamp, order: .reverse)], predicate: nil, animation: .default ) private var items: SectionedFetchResults var body: some View { NavigationView { List { ForEach(items) { section in Section(header: Text((section.id))) { ForEach(section) { item in NavigationLink { VStack { Text(Item at (item.timestamp!, formatter: itemFormatter)) Text((item.group!)) } } label: { VStack { Text(item.timestamp!, formatter: itemFormatter) } } } } } } .navigationTitle(Sectioned List) .toolbar { ToolbarItem(placement: .primaryAction) { Button(action: addItem) { L
2
0
3.5k
Jan ’22
Trying to update a swiftUI list view when the sort order changes...
Hello, My app includes a list of items sorted by their last used date. I'm trying to implement the following behaviour: user sees a list of items (most recently used at the top) user navigates into detail view for item X in the list user performs an action to 'use' item X user navigates back to the list expected: user sees itemX at the top of the list actual: users sees itemX in its previous location (see sample code below) Note that when I uncomment line 27, after the user uses itemX they are immediately returned to the listView, and itemX is the first item. Is there a way I can get itemX showing at the top, but not getting immediately (jarringly) returned to the listView from the detail view? thanks! import SwiftUI struct ContentView: View { @ObservedObject var list = ModelList.shared var body: some View { NavigationView { List(list.sorted()) {object in NavigationLink(destination: DetailView(object: object)) { Text(object.title
1
0
2.2k
Aug ’20
How can I make an "inverted" list (bottom to top) with SwiftUI?
I'm trying to figure out how to make an inverted list in my watchOS app for a message view, so that messages appear from the bottom first, and go up. Everything I've tried so far has some sort of major drawback, and I'm wondering if there's some proper way to do it. My current implementation is flipping every message item upside-down, then flipping the whole list upside-down. This works in making the list go from bottom to top, but the digital crown scroll direction is also inverted. Simply inverting the array of messages doesn't work either, as the user has to scroll to the bottom of the list manually every time. Any tips/suggestions would be greatly appreciated.
1
0
473
Nov ’24
SwiftUI List with Section and ForEach loads all rows at once
Hello, coming from SO (https://stackoverflow.com/questions/71806868/swiftui-list-with-section-and-swipe-actions-loads-all-rows-at-once) I can't find any related post here. The issue: If you are using a ForEach inside a Section all rows are loaded at once. It seems like a bug or I misunderstood how to use them together. NOTE: I also posted a temporary workaround to mock a section in this SO thread. Here is the code snippet from SO: struct Item: Identifiable { var id = UUID() var name: String } struct Row: View { var item: Item static var counter = 0 init(item: Item) { self.item = item Row.counter += 1 print(Row.counter) } var body: some View { Text(item.name) } } struct ContentView: View { @State var items = (1...1000).map { Item(name: Item ($0)) } var body: some View { List { ForEach(items) { Row(item: $0) .swipeActions(edge: .leading) { Button(Action, action: {}) } } } } }
1
0
1.2k
Sep ’22
How do i use dynamic data for my SwiftUI ScrollView without destroying performance?
Currently i am trying really hard to create experience like the Apple fitness app. So the main view is a single day and the user can swipe between days. The week would be displayed in the toolbar and provide a shortcut to scroll to the right day. I had many attempts at solving this and it can work. You can create such an interface with SwiftUI. However, changing the data on every scroll makes limiting view updates hard and additionally the updates are not related to my code directly. Instruments show me long updates, but they belong to SwiftUI and all the advice i found does not apply or help. struct ContentView: View { @State var journey = JourneyPrototype(selection: 0) @State var position: Int? = 0 var body: some View { ScrollView(.horizontal) { LazyHStack(spacing: 0) { ForEach(journey.collection, id: .self) { index in Listing(index: index) .id(index) } } .scrollTargetLayout() } .scrollTargetBehavior(.paging) .scrollPosition(id: $position) .onChange(of: position) { oldValue, newVa
0
0
66
2w
Help Debugging Performance of Grid with Many Circles SwiftUI
Hello everyone, I've been trying to improve the performance of a grid view that I've made for an app. Basically, it's like one of those sensory boards and there are circles that, when dragged over, change color and play a little haptic feedback. However, I want the grid to span the entire screen and so by increasing the dimensions of the grid to say, 30x30, I am noticing significant performance decreases. CPU usage increases to 99% and the haptic feedback and animation slow down. I've narrowed down the problem to the drag gesture (not the haptics). Just the drag gesture makes the CPU usage approach 40%. The part where I verify if the drag location is within the bounds of any of the circles increase the CPU though. This is like O(n) but with like 900 grid points doesn't sound like it should be that bad? Is there any way that I can improve the code performance? I've tried putting each row of the grid into a Group and also tried switching to UIKit and using CAReplicatorLayers to constr
0
0
1.1k
Feb ’24
SwiftUI List on maCOS: highlighting content in the selected row?
Hello all, In a SwiftUI List, when a row is selected, a blue selection is drawn in the selection, and foreground Text with the default primary color is automatically made white. For other views with custom colors, I'd like to be able to make sure they become tinted white to match the system apps. For example, see the blue dot on the selected row: Example code: List(selection: $selection) { ForEach(0..<4) { index in HStack { Image(systemName: circle.fill) .foregroundColor(.blue) Text(Test) } .tag(index) } } With NSTableCellView, there is the backgroundStyle property. I've searched all of the available environment variables, and couldn't find anything appropriate. I have also tried manually including an isSelected binding on a view for each row, but the selection binding is not updated by List until mouse-up, while the highlight is updated on mouse-down and drag, so this results in a flickery appearance and is not right either. Any tips on how to achieve the correct result
5
0
5.1k
Nov ’22
SwiftUI TabView - duplicate entries List View while binded to a @FetchRequest
macOS app using a TabView, each tab's root view is using a @FetchRequest to populate a List view. while switching between tabs results in 1 ... (n * n) duplicate items on each tab switch. The behaviour is as if the internal update call in response to the SwiftUI view updating is not clearing the previous List view items but is appending to it. How do you clear or empty the List view on/or before every UI update call to the @FetchRequest property wrapper?
1
0
1.8k
Mar ’22
LazyVStack not refreshing offset of child list in SwiftUI
If initially content/list is large and scrolled to bottom, second time scroll bar offset remains at same place for small reloaded content making contents invisible(as small contents are at top of list). Only after scrolling list to the top small list contents becomes visible else its hidden. If I replace LazyVStack to VStack, issue goes aways but I won't be able to make sticky sections in it. To Reproduce this issue: Click Click me button to reload long list Scroll to bottom Click Click me button to reload small list Small list contents are invisible Now scroll to top and then it shows small list and adjusts list content size Output: // ContentView.swift // LazyVStackIssue // Created by Vishwanath Deshmukh on 12/24/21. import SwiftUI struct ContentView: View { @State var array = [Vish] @State var count = 1 var body: some View { ZStack(alignment: .top) { VStack(spacing: 0) { Button(action: refreshData) { Text(Click me) }
0
0
1.1k
Dec ’21
SpriteKit/RealityKit + SwiftUI Performance Regression on iOS 26
Hi, Toggling a SwiftUI menu in iOS 26 significantly reduces the framerate of an underlying SKView or ARView. Below are test cases for SpriteKit and RealityKit. I ran these tests on iOS 26.1 Beta using an iPhone 13 (A15 chip). Results were similar on iOS 26.0.1. Both scenes consist of circles and balls bouncing on the ground. The restitution of the physics bodies is set for near-perfect elasticity, so they keep bouncing indefinitely. In both SKView and ARView, the framerate drops significantly whenever the SwiftUI menu is toggled. The menu itself is simple and uses standard SwiftUI animations and styling. SpriteKit import SpriteKit import SwiftUI class SKRestitutionScene: SKScene { override func didMove(to view: SKView) { view.contentMode = .center size = view.bounds.size scaleMode = .resizeFill backgroundColor = .darkGray anchorPoint = CGPoint(x: 0.5, y: 0.5) let groundWidth: CGFloat = 300 let ground = SKSpriteNode(color: .gray, size: CGSize(width: groundWidth, height: 10))
2
0
245
Oct ’25
how to assign textField's default value in list (swiftUI)
I have a list with textField and a button. my goal is that I want to provide default value to textField when I toggle the button. I can do it with text, but I don't know how to do with textField struct ContentView: View { @State var isEnableBatch: Bool = false var body: some View { VStack { Button { isEnableBatch.toggle() } label: { Image(isEnableBatch == true ? EAIcon-Check_rectangle : EAIcon-Check_Box) } List { ForEach(0 ..< 10, id: .self) { index in let value = isEnableBatch ? batch Enable : (index) Text(value) // <-- I don't know how to do here if i change to textField } } .listStyle(.plain) } .padding() } } If I change to use textField as below it will show compile error No exact matches in reference to static method 'buildExpression' struct ContentView: View { @State var isEnableBatch: Bool = false @State var attValue: String = var body: some View { VStack { Button { isEnableBatch.toggle() } label: { Image(isEnableBatch == true ? EAIcon-Check_rectangle : EAIcon-Check_Box) } List
2
0
731
Aug ’23
Updates on SwiftUI list causes detail views to pop
I found this problem many times in the internet but not a solution for this. I have a SwiftUI list with data fetched from a server. The app uses a periodically background sync (into a core data background context). So the rows of this list can change. To make it simple to understand think of a message app like on the iPhone: struct MasterView: View { @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: Chat.name, ascending: true)], animation: .none) private var chats: FetchedResults var body: some View { List { ForEach(chats, id: .chatID) { chat in NavigationLink(destination: DetailView(chat: chat)) { Text(chat.name ?? ) } } } } } The detail view is not so important here but keeping with the example of a message app you would have something like the following code to display the messages of a selected chat: struct DetailView: View { let chat: Chat @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: Message.timestamp, ascending: true)], animation: .none) private
0
0
739
Oct ’21