Search results for

SwiftUI List performance

50,605 results found

Post

Replies

Boosts

Views

Activity

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
How we can hide bottom tab bar when click the list items in SwiftUI?
I am new in SwiftUI and I try to build new project to learn quickly and I have a SwiftUI project, everything work very well, and when I click the any list items it is open other view, but bottom Tab bar still located in bottom. I want to hide bottom tab bar in there if I click any list items. Is it possible in SwiftUI? Dark_MenuApp: @main struct DarkMenuApp: App { @AppStorage(isDarkMode) private var isDarkMode = false var body: some Scene { WindowGroup { TabView { NavigationView { DarkMenuView() }.tabItem { Image(systemName: homekit) Text(home) } Text(Liked) .tabItem { Image(systemName: heart) Text(Liked) } Text(Reels) .tabItem { Image(systemName: video) Text(Reels) .environment(.colorScheme, isDarkMode ? .dark : .light) .preferredColorScheme(isDarkMode ? .dark : .light) } Text(Profile) .tabItem { Image(systemName: person) Text(Profile) } }.accentColor(.primary) } } } DarkMenuView: struct DarkMenuView: View { @AppStorage(isDarkMode) private var isDarkMode = false v
1
0
2.2k
Jul ’21
SwiftUI: Edit list row relement with swipe action and present modal sheet
Hi. I have a swiftui project with a list. I would now like to add 2 trailing swipe actions to this list, the .onDelete swipe action and a edit swipe action to the left of it. Like this: To achieve this in swiftui I added the following code to my list: List { ForEach(timers, id: .id) { timer in TimerRow(timer: timer) } .onDelete(perform: { IndexSet in deleteTimer(IndexSet) }) .swipeActions(edge: .trailing, allowsFullSwipe: false) { Button { // Open edit sheet isShowEditTimer.toggle() } label: { Image(systemName: pencil.circle) } } } But unfortunately only the edit function is displayed now: Do you know how I can solve my problem? But now to my real problem: I now want to open a modal sheet when the edit swipe action of a line is pressed. But how do I find out which line was swiped on? With the .onDelete function we get an IndexSet, but nothing here I would also like to give the struct that is called in my sheet this certain swiped element (CoreData
0
0
967
Jan ’22
SwiftUI List rows with multiple buttons trigger all buttons
I have a SwiftUI List with an HStack containing two Buttons. If I tap either button, or elsewhere in the cell, the entire cell highlights and actions for both Buttons are fired off. I can't find where this is documented, but have found that adding .buttonStyle(BorderlessButtonStyle()) to the List prevents this behavior - tapping individual buttons fire their individual actions as expected. Is this an expected behavior? Below is my example without the workaround applied: struct ContentView: View { var body: some View { List { HStack { Button(action: { print(button 1 tapped) }) { Text(One) } Button(action: { print(button 2 tapped) }) { Text(Two) } } } } } Thanks!
3
0
3.6k
Jun ’20
SwiftUI list does not scroll using 2-finger swipe on trackpad
I have been testing this simple SwiftUI code: It has a list in ContentView shown below. When a cell of the list is tapped, it pushes a SecondList into the navigation stack. When this SwiftUI code was run on a real iPad with a trackpad, I used 2-finger swipe to scroll the list up and down. In the Simulator, I enabled Capture Pointer to simulate a mouse. The list in the ContentView scrolls smoothly. However, for theSecondList, it freezes randomly and thereafter not responding. It also failed in a UIKit project, where I replaced a UINavigationView with this ContentView using UIHostingViewController. It was testing it with iPadOS 14.5 on both Simulator and iPad Pro hardware with Magic Keyboard. How do I fix this? Is this an OS bug? import SwiftUI struct ContentView: View { var body: some View { NavigationView { List { ForEach(0..30, id: .self) { index in NavigationLink( destination: SecondList(), label: { Text(String(index)) }) } } }.navigati
2
0
3.5k
May ’21
SwiftUI - Picker binding in segmented list
I have a problem with the binding of a picker. Here a short sample project. A simple data structure with two fields: a string (f1) and an enum (f2). struct D0: Identifiable,Equatable { var id: UUID var f1:String var f2:T0 } extension D0 { struct Data { var f1:String = String() var f2:T0 = .s1 } var data:Data {Data(f1: f1, f2: f2)} init(data:Data) { self.id = UUID() self.f1 = data.f1 self.f2 = data.f2 } mutating func update(from data:Data) { self.f1 = data.f1 self.f2 = data.f2 } static let sampleData : [D0] = [ D0(id: UUID(), f1: string1, f2: .s1), D0(id: UUID(), f1: string2, f2: .s2) ] enum T0: Int,CaseIterable,Identifiable { case s1=1 case s2 var id:Self {self} var name:String { switch rawValue { case 1: return one case 2: return two default: return undefined } } In the Editing View the string is bound to a textfield while the enum field is bound to the selection of a Picker. struct Editing: View { @Binding var data:D0.Data var body: some View { Form { VStack { TextField(F1, text: $data.f1) Picker(F2, select
1
0
749
Dec ’22
Fitting a UITextView within a cell for a List, SwiftUI
Hi All, I am having issues with a UITextView (I need this type of view so that it can detect links, email addresses, etc) that I created as a UIViewRepresentable. I am trying to fit this view inside a VStack that holds some other information that would be shown in a SwiftUI list view. It seems to fit fine vertically, but the width goes way out of frame. The text view's frame prints out as 3000 for the width. Any help is appreciated! struct MessageTextView: UIViewRepresentable { @State var text = func makeUIView(context: Context) -> UITextView { let view = UITextView(frame: .zero) view.isScrollEnabled = false view.isEditable = false view.dataDetectorTypes = .all view.automaticallyAdjustsScrollIndicatorInsets = false view.font = UIFont.systemFont(ofSize: 12) return view } func updateUIView(_ uiView: UITextView, context: Context) { uiView.text = text uiView.font = UIFont.systemFont(ofSize: 12) print(uiView.frame.width) } typealias UIViewType = UITextView } var body: some View { VStack(align
1
0
1.4k
Aug ’20
SwiftUI: unexpected behavior with two List side by side and a NavigationView
I have a screen with two List side by side, inside a NavigationView. The layout is rendered correctly, and I can independently scroll both lists. The problem is that, when I scroll the first list, it goes behind the navigation bar without triggering the effect of applying a background color to it. Here's a gif showing what's going on: And this is the code I'm using for this view: struct ContentView: View { var body: some View { NavigationView { HStack(spacing: 0) { List { Section(header: Text(Header left)) { ForEach(0..<600) { integer in Text((integer)) } } } .listStyle(InsetGroupedListStyle()) .frame(minWidth: 0, maxWidth: .infinity) List { Section(header: Text(Header right)) { ForEach(0..<400) { integer in Text((integer)) } } } .listStyle(InsetGroupedListStyle()) .frame(minWidth: 0, maxWidth: .infinity) } .navigationTitle(Example) } .navigationViewStyle(StackNavigationViewStyle()) } } Would this be a SwiftUI bug? If not, how can I make the first list
0
0
911
Aug ’21
How to transition views in a List View when it appears (SwiftUI)
There are views in a ListView. The views have the transition modifiers on them but no transition occurs. The List is made to appear first before its chid views are rendered. Here's some code to illustrate the problem: The StateObject: class TripsStore: ObservableObject { @Published private(set) var trips: [Trip] = [] @MainActor func getTrips() async throws { ... } } The View struct TripsStore: View { @StateObject private var tripsStore: TripsStore = TripsStore() @State private var progress: RequestStatus = .idle @State private var availableTrips: Set = [] var body: some View { NavigationStack { Group { if progress == .loading { ProgressView() } else { List(tripsStore.trips) { trip in if availableTrips.contains(trip.id) { TripCard(trip: trip) .transition(.asymmetric(insertion: .opacity, removal: .scale).animation(.easeInOut(duration: 3.5))) } } .onAppear { withAnimation { tripsStore.trips.forEach { trip in availableTrips.insert(trip.id) } } } } } .task { progress = .loading do { try await tri
0
0
356
May ’23
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
SwiftUI: List inside TabView inside NavigationView breaks animation
I want to have a TabView inside a NavigationView. The reason is that I am showing a List inside the TabView. When a user taps on an item in the list, the list uses a NavigationLink to show a detailed screen. The problem is that the navigationBarTitle is now broken. It does not animate when the user scrolls through the items (sometimes). I don't want to wrap my NavigationView inside the TabView, since that will always show the TabView. I don't want it. This is the reproduction code. If you run this in the simulator, the animation will break when switch a few times between the tabs and you scroll through the list. You will see that the navigation bar will remain where it is, without the animation. import SwiftUI struct ContentView: View { var body: some View { NavigationView { TabView { TestView() .tabItem { Image(systemName: person.3) } TestView() .tabItem { Image(systemName: person.2) } } .navigationTitle(Test) .navigationViewStyle(.stack) } } } struct TestView: Vi
2
0
3.4k
Feb ’22
Developing a custom swiftui profile images list
Hello Everyone, I'm developing an App and there is this specific behaviour that im struggling to implement. I want to display the profile images of the users participating in an event like below with the first 4 having their avatars appear and the surplus being counted and displayed in that counter circle. Not sure how to achieve this with swiftUI atm any guidance will be much appreciated
1
0
1.4k
Jan ’23
How we can use alert menu before delete list items in SwiftUI?
I have list items in SwiftUI, and when I delete list items I want to delete after alert menu, like do want to delete your list items, yes or no is it possible? struct MyView: View { @State private var selectedUsers: MyModel? var body: some View { ScrollView(.vertical, showsIndicators: false, content: { VStack(content: { ForEach(datas){ data in MyRowView(data: data) .contextMenu { Button(action: { self.delete(item: data) }) { Text(delete) } } .onTapGesture { selectedUsers = data } } .onDelete { (indexSet) in self.datas.remove(atOffsets: indexSet) }}) })} private func delete(item data: MyModel) { if let index = datas.firstIndex(where: { $0.id == data.id }) { datas.remove(at: index) } }}
2
0
2.5k
Feb ’22
SwiftUI Context Menu Popping Up Whole List
When I used Context Menu for each photo in three columns. So, the code is like below: List { LazyVGrid(columns: columns) { View() .contextMenu { Button() } } } This just pop up whole list not individual element when I long press the element to see context menu. The whole list is highlighted when context menu appears. How can I make this to highlight individual element not the whole list? If I remove any of List or LazyVGrid the problem fix. But the columns are not in the way I want. Also, I don't want to change List to VStack or ScrollView which don't have refreshControl. Thanks in advance.
3
0
1.9k
Aug ’21