Search results for

SwiftUI List performance

50,605 results found

Post

Replies

Boosts

Views

Activity

SwiftUI Buttons in a List do not highlight when tapped
SwiftUI Buttons in a List no longer highlight when tapped. Seems to have stopped highlighting after iOS 16.0 I've only tested on an iPhone/simulators so not sure if iPad has the same issue. The issue has been carried over to iOS 17 Beta 4. My app does not feel Apple like as there is no visual feedback for the user when a button in the list is pressed. Does anyone know why this is occurring? Is this a bug on Apple's end?
5
0
3.2k
Jul ’23
SwiftUI list overlap navigationBar
I run this code on simulator and device with iOS 15 but when I scroll the List items overlap navigation bar title. but I found that if I add a padding-top with 1 on the List then the view works correctly! struct ContentView: View { var body: some View { NavigationView{ VStack{ List { ForEach(1...100 , id:.self) { index in Text(Message (index)) .listRowBackground(Color.clear) } } .background( ZStack{ Image(chat_bg) .resizable() .opacity(0.25) LinearGradient(gradient: Gradient(colors: [Color.black.opacity(0.9), Color.blue.opacity(0.6)]), startPoint: .top, endPoint: .bottom) } ) .listStyle(PlainListStyle()) SendContainer(message: ) } .layoutPriority(1) .navigationBarTitle(Text(Chats), displayMode: .inline) } } } struct SendContainer:View{ @State var message: String var body: some View{ HStack{ Image(systemName: paperclip) .font(.system(size: 24)) .foregroundColor(Color.gray) TextField(Type Text Here .... ,text:$message) .cornerRadius(16) Image(systemName: mic) .font(.system(size: 24))
1
0
3.5k
Oct ’21
Programmatically expand a list in SwiftUI 2
Hi there, I have a question regarding the new expandable lists in SwiftUI 2. When I create a sidebar with an expandable list its collapsed by default. Is there any way to either programmatically expand certain items via a binding or to store the expansions so that the app will remember which items where expanded after the app is opened again? Here is my code: struct SidebarMenu2: Identifiable { let id: String let title: String let icon: String? let action: (() -> Void)? var menues: [SidebarMenu2]? init(title: String, icon: String? = nil, action: @escaping () -> Void) { self.id = title self.title = title self.icon = icon self.action = action self.menues = nil } init(title: String, icon: String? = nil, menues: [SidebarMenu2]?) { self.id = title self.title = title self.icon = icon self.action = nil self.menues = menues } } struct Sidebar2: View { var menu: [SidebarMenu2] { [ SidebarMenu2( title: My Library, menues: [ SidebarMenu2(title: Profiles, icon: person.fill) { print(Profil
0
0
1.7k
Jul ’20
Why list items not able to delete in SwiftUI?
I have a simple app in SwiftUI, and I try to delete list items in app , project is working, but still list items not able to delete, I do not know what I did not put in my codes, any idea will be appreciated. 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 selectedUsers.remove(atOffsets: indexSet) }}) })} private func delete(item data: MyModel) { if let index = datas.firstIndex(where: { $0.id == data.id }) { datas.remove(at: index) } }} model: struct MyModel: Identifiable, Hashable, Codable { var id = UUID().uuidString var name: String } var datas = [ MyModel(name: david), MyModel(name: marry), ]
3
0
2.1k
Feb ’22
SwiftUI is pressing both buttons in a List
I have a List which acts like a form where you can enter values. It uses a custom View struct SectionArea to separate the various sections and cut down on code duplication, like this: List { SectionArea(title: Section One, height: 176, horizontalPadding: 0, roundCorners: (0, 0, 0, 0)) { VStack { Button { print(Pressed Button One) fullScreenViewChoice = .optionOne showSubView.toggle() } label: { HStack { Text(Button One) Spacer() Image(systemName: chevron.right) } } .frame(height: 40) Divider() Button { print(Pressed Button Two) fullScreenViewChoice = .optionTwo showSubView.toggle() } label: { HStack { Text(Button Two) Spacer() Image(systemName: chevron.right) } } .frame(height: 40) Divider() } } } .listStyle(.plain) .listRowSpacing(0) It works fine, but regardless of which button I press it always acts as though both buttons have been pressed. Say I press Button One, the console will display: Pressed Button One Pressed Button Two Can someone tell me where I'm going wrong here, please? Thanks
2
0
4.0k
Feb ’24
How to get and set SwiftUI List scroll position?
Just getting started with SwiftUI. Exciting stuff.I understand that List would be one of the main building blocks that I can use in place of UI/NSTableView. One thing I haven’t seen yet: how to get and set the scroll position? Specifically, my list would consist of “read” and “unread” items. When the user first enters the list, everything is unread, so the list can start at the top. As new items scroll into view, they become “read”. When the user now leaves the list, and later returns, the list should scroll to the first “unread” item. So I am not so much interested in the pixel-level scroll offset, but rather, how do I scroll the viewport into the right location so that the user would see the desired info. The API could be something like “scroll the list such that model object X is visible in the middle” (with or without animation).The read/unread state is easily expressible as a model object property. I’m having trouble with how to bind
13
0
19k
Jun ’19
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 https://stackoverflow.com/a/77587703 However, this approach doesn't seem to work with Lists. Has anyone find any solutions for this?
0
0
170
Sep ’25
SwiftUI List to show header only on scroll
We have a requirement for SwiftUI List to show the header only when user scrolls to top. This behaviour should be similar to search control that hides by default and only when the user pulls down then it displays. We would like to show our customView similar to search. example : .searchable(text: $searchText, placement: .navigationBarDrawer(displayMode: .automatic)) We need to implement similar functionality ( such as hide list header by default and enable it on scroll ). Can anyone suggest me a way to achieve this functionality. Appreciate your response. Thanks, Janakiram
1
0
693
Mar ’23
SwiftUI bottom-first List (inverted)
How can I create a List that starts on the bottom? All Lists start on top, but in a chat, the desired content scroll direction is up (inverted). There are workarounds that rely on flipping the list with rotation effects, but these don’t work well, and make the logic very hard to understand. Scrolling to bottom after some delay on list appear has side effects (loads rows on top). Ideally there would be List { … }.scrollDirection(.inverted) api, that automatically loads the list from its last item, not first.
3
0
4.1k
Jun ’21
Focus on the specific item in the List on SwiftUI (tvOS)
I am having a hard time trying to figured out how to focus on a specific cell/row in the list in the SwiftUI 2.0 and tvOS 14. I need to be able to focus and select a specific record when I am navigated to a view. However when the focus is switched to the list, some random row is focused. I've tried ScrollView and List to create a list of items with Buttons as items and with appropriate prefersDefaultFocus. Nothing works. Here's some sample code: struct ChannelListView: View { @Namespace private var namespace @ObservedObject var viewModel : LiveViewModel @State var selection = Set() var body: some View { List(viewModel.channels, selection: $selection){ item in ScrollViewReader { proxy in Button(action: { }){ ChannelItemView(item: item, selectedItem: $viewModel.selectedChannel, onSelected: { id in }) .padding(.vertical, 2) } .buttonStyle(ChannelButtonStyle()) .prefersDefaultFocus(item == viewModel.selectedChannel, in: namespace) } } .focusScope(namespace) }
0
0
1.2k
Oct ’20
List of Items - Best way SwiftUI
Hi, I have a list of items on the iPhone that I want to share on the watch. The list would be too big to have the actual file on the watch, so, what's the best way to share the list from the iPhone, and could someone give me a step by step on what to do or point me to a good document? Thanks, Dan Uff
0
0
453
Jun ’21
Why do I get an error when deleting data from SwiftUI List and Realm?
Hi all,I know this is may not be the right forum to post questions about Realm but my issue has to do with the nature of how SwiftUI works.Has anyone been able to successfully integrate Realm with SwiftUI, especially deleting records/rows from a SwiftUI List? I have tried a few different things but no matter what I do I get the same error. After reading some related threads I found out that other people have the same issue but I refuse to think that there is no current solution to integrate Realm with SwiftUI.The following code successfully presents all of the items from Realm in a SwiftUI List, I can create new ones and they show up in the List as expected, my issues is when I try to delete records from the List by either manually pressing a button or by left-swiping to delete the selected row, I get an Index is out of bounds error.Here is my code.Realm Model:class Dog: Object { @objc dynamic var name = @objc dynamic var age = 0 @objc d
4
0
3.8k
Apr ’20
Implement .searchable into existing list in SwiftUI
Hi there, I would like to implement a search bar into my existing list, filled with NavigationLinks. Is there a possibility to mark all my existing NavigationLinks with variables that I can show them in my search list? I am still quite new to SwiftUI so I would love to hear from you. Here is my code: var body: some View { NavigationView { List { Group { NavigationLink(destination: MidazolamLink()){ Image(MidazolamMediLabel) .resizable() .frame(width:60, height: 30) Text(Midazolam) } NavigationLink(destination: NaloxonLink()){ Image(NaloxonMediLabel) .resizable() .frame(width:60, height: 30) Text(Naloxon) } NavigationLink(destination: ParacetamolLink()){ Image(ParacetamolMediLabel) .resizable() .frame(width:60, height: 30) Text(Paracetamol) } NavigationLink(destination: PrednisolonLink()){ Image(PrednisolonMediLabel) .resizable() .frame(width:60, height: 30) Text(Prednisolon) } NavigationLink(destination: SalbutamolLink()){ Image(SalbutamolMediLabel) .resizable() .frame(widt
2
0
845
Nov ’23