iPadOS uses a different selection color when an external keyboard is connected. But the problem is that it doesn't change the text color to white, making it difficult to read: A simple List with NavigationLink produces this behavior by default: var body: some View { List { ForEach(searchResults) { item in NavigationLink(destination: ContentDetailView(item: item)) { ListItemView(item: item) } } } } I tried to improve text legibility by changing all Text colors to white when the cell is selected. But this doesn't work because the text becomes even more unreadable when no external keyboard is connected. Is there a way to change the selection color when an external keyboard is connected? Or maybe detect when an external keyboard is connected to manually change the text color for this specific case?
Search results for
SwiftUI List performance
50,605 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Simple master screen with list, NavigationLink to editable detail view. I want edits on the detail screen to update to the master list cars variable and the list UI. On the detail view, if I edit one field and exit the field, the value reverts to the original value. Why? If I edit one field, don't change focus and hit the back button. The master list updates. This is what I want, but I can only update 1 field because of problem #1. Should be able to edit all the fields. If I implement the == func in the Car struct, then no updates get saved. Why? struct Car: Hashable, Equatable { var id: UUID = UUID() var make: String var model: String var year: Int // static func == (lhs: Car, rhs: Car) -> Bool { // return lhs.id == rhs.id // } } struct ContentView: View { @State private var cars: [Car] init() { cars = [ Car(make: Toyota, model: Camry, year: 2020), Car(make: Honda, model: Civic, year: 2021), Car(make: Ford, model: Mustang, year: 2022), Car(make: Chevrolet, model: Malibu
There seems to be a problem with placing multiple NavigationLinks on a List item row in SwiftUI. If I have two links on the same row and tap one of them, SwiftUI seems to create a path using both links. Irrespective of which of the two is tapped, the view specified by the first (left-hand) appears. Tapping Back reveals the view specified by the second (right-hand) link. Tapping again returns to the list. This problem has been mentioned before in relation to Buttons. The solution offered was to use button styles, and make sure the button areas do not overlap (how could they overlap?). This does not work ChatGPT gave me a clear example, which it claimed would work, but just demonstrates the problem import SwiftUI struct ContentView: View { var body: some View { NavigationView { List { ForEach(0..<10) { index in HStack { NavigationLink(destination: DestinationView1(item: index)) { Text(Navigate to View 1) .padding() .background(Color.blue) .foregroundColor
For the life of me, I cannot get List selection working in SwiftUI. From what I found, there are at least three different methods to handling this: Using tags, IDs, or NavigationLink Tag/Selection... though none of these are actively working as far as I can tell. Even in Apple's Fruta app: Selecting something from the List sidebar, hiding the sidebar, and then bringing it back will cause the selection to lose the highlight. What is worse is that under the hood the selection publisher is being fired in all kinds of random in the different scenarios. I made a sample project demoing the three different types of selection and they all fail in different ways: When using a List with both tags or an Identifiable object, the binding will only ever fire the first row's identifier (even when selecting other rows) and only a few times before only ever firing nil thereafter. When using NavigationLink(destination:tag:selection:), the proper selection is fired, but is always followed by
I'm trying to build a high-performance text editor similar to the one found in the Apple Notes app. To eliminate uncertainties, I've created a SwiftUI app from scratch and added only the TextEditor view, nothing else. struct ContentView: View { @State private var text = var body: some View { TextEditor(text: $text) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) } } I've inserted a string with 347,023 characters, and text editing is very sluggish, slow, and text selection is even slower. The same string in the Apple Notes app exhibits smooth text editing and selection. I've also tried using UIKit with UITextView, but I'm experiencing the same performance drop. How can I achieve the same level of smooth text editing and performance as the Apple Notes app? I noticed that the following example is very smooth but you can't edit the text: https://developer.apple.com/documentation/uikit/textkit/using_textkit_2_to_interact_with_text Could you provide
I am writing a document-based app using the new SwiftUI 'App' protocol. I have a '+' button that reveals a popover. Within the popover, I have a List of buttons. When rendering this, the simulator shows a very small rectangle and *none* of the buttons. If I change this to a VStack and ForEach, I get a set of buttons. Is there something I am doing wrong to render a List in the Popover? I want to use the List for the separators and the 'grouped' formatting of the List view for more polish finish. Any suggestions on how to get this to work? import SwiftUI enum DragAction: String { case addEntry = addEntry case addTask = addTask case addAttachment = addAttachment } struct MenuItem: Identifiable { var id = UUID() let name: String let iconName: String let dragAction: DragAction } struct PlusPopoverMenu: View { @Binding var isPresented: Bool let menuItems: [MenuItem] = [ MenuItem(name: Add Entry, iconName: pencil.and.outline, dragAction: .addEntry), MenuItem(name
Hi. I would like to code a multiple timer app for me and my family. And i would now like to show these multiple timers in a list. From the list the user can tap on a timer (list row) and than go to the selected timer. Like in this app: https://youtu.be/KAIOYlXi2KE So far I've already managed to generate the transition from my list to my timer view with a navigation link in my list: NavigationLink { TimerView(timerObject: timer) } label: { Text(timer.name) } } But if I now go back to my list, and then try to go to the same timer which I started earlier, a completely new instance of my timer view is created even though I am still getting the print commands (every second) in my console of my earlier started timer. So how can I code that each list row has only a single instance of a timer and then always goes back to just that one timer? I would be really happy about help. Thank you!
I Have this struct struct Friend: Identifiable { var name: String let bday: Date let id = UUID() } and this code: struct FriendView: View { @Binding var friends: [Friend] var dateFormatter: DateFormatter { ... } var body: some View { VStack { List { ForEach(friends) { friend in HStack { Text(friend.name) Spacer() Text(self.dateFormatter.string(from: friend.bday)) } } } } } How to sort birthdays in swiftUI so that next birthday from today is on top of the list? I have tried putting friends.sorted(by: {$0.bday < $1.bday}) in if statement but then i just get the oldest friend on top, and not the next one who has a birthday this year. I would appreciate any help very much. Thank you in advance!
Hi All! I've encountered a SwiftUI NavigationSplitView bug in my app that I'd appreciate help with, I've spent quite some time trying to work out a solution to this problem. I have a main list, which has either a Location or LocationGroup. When selecting a Location, the detail view is presented. When selecting a LocationGroup, a subsequent list of Locations are presented (from the group). When tapping on any of these Locations, the NavigationStack does not animate (push the view), and when tapping back from it, it jumps to the main selection. The overall goal is to be able to present within the detail: of a NavigationSplitView a NavigationStack, and to be able to push onto that stack from both the main NavigationSplitView's list, and from the detail. I created the following sample code that reproduces the issue: ContentView.swift public enum LocationSplitViewNavigationItem: Identifiable, Hashable { case location(Location) case locationGroup(LocationGroup) public var id: UUI
Why does this code cause a memory leak? struct ContentView: View { @State var itemsX = Array(0..500) var body: some View { List { ForEach(itemsX, id: .self) { index in Section(header: HStack { Text(String(index, radix: 16)) Spacer() Text(Other text) }) { Text(DataText) } } } } } If I cut down the items in the array to 250 it doesn't leak at the beginning but when I scroll up and down Instruments shows a number of leaks.
I tried removing several Text views in List as the mode transited to Edit but the List kept a row height before transition and the row height changed after scrolling. I would like to change the row height as the mode transited to Edit. How can I actualize it? The following code is to see the problem. Xcode 12.4 iOS 14.4 SwiftUI import SwiftUI struct ContentView: View { @Environment(.editMode) var editMode @State private var selections: SetInt = Set() var body: some View { VStack { EditButton() List(selection: self.$selections) { ForEach(0..100) { i in VStack { Text(First Text) if editMode?.wrappedValue != .active { Text(Second Text) Text(Third Text) Text(Forth Text) Text(Fifth Text) Text(Sixth Text) } } } } } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
Hello everyone. I just discovered one issue with List in iOS16. The sample Playground code is provided below. Steps to reproduce: Run the code. Scroll down the list to the bottom so first rows become hidden. Scroll up to first row. Tap on first row. Result: row is marked as selected but its size stays unchanged. Once you scroll the list up and down this row will resize itself. Expected result: row resize immediately after tap on it. Note that if you don't perform steps 2 and 3 (maybe cells are not being reused) it works as expected. Also on iOS 14, 15 it works as expected import PlaygroundSupport struct Item: Identifiable, Equatable { let id: String let name: String } struct App: View { @State var items: [Item] = [Item(id: 0, name: Apples), Item(id: 1, name: Oranges), Item(id: 2, name: Bananas), Item(id: 3, name: Pears), Item(id: 4, name: Mangos), Item(id: 5, name: Grapefruit), Item(id: 6, name: Peaches), Item(id: 7, name: Qiwies), Item(id: 8, name: Strawberries), Item(id:
I have exactly the same question, nobody has been able to solve it on Stack Overflow, so I'm going to try to get lucky here. Question Source, at: Stack Overflow - Question asked by Miosser When the ability to delete is disabled [.deleteDisabled(true)] on a list and the list's edit button [EditButton()] is pressed, the extra space to the left of each list item still appears as if it were still show the delete buttons (I don't want to do multi-selection of list rows either, just organize the list items individually), but I haven't found or been able to remove that space on the left, which belongs to the delete buttons and I want strip to make the text fill the entire line, because the stripping capability still leaves that space even if it's disabled. List { ForEach(projectListVM.projects .filter{filterFavorites ? $0.isFavorite == true : ($0.isFavorite || !$0.isFavorite)}, id: .id) { itemProject in ProjectListRowScreen(itemProject: itemProject, projectListVM
I'm implementing a 'ruler' view similar to what you would find in Sketch / Photoshop / etc. Basically a ruler at the top which shows you the current view size and updates as you zoom in/out. In my example, it draws about ~250 rectangles. I wanted to do it with SwiftUI but I'm getting into performance issues. When I update the view's scale with a slider, FPS drops noticeably. (Testing on macOS Catalina 10.15.7, Xcode 12.0.1, Macbook Air.) I wonder if I hit the limits of SwiftUI and should switch to Metal, or am I missing some optimization here? Note that I did add .drawingGroup() modifier but it doesn't seem to help in any way. Here's a sample app to download: Github - https://github.com/Moriquendi/swiftui-performance-tests Here's a code for the ruler view: struct Timeline: View { ttlet scale: Double ttprivate let minLongTickWidth = 30.0 ttlet LARGE_TICKS_COUNT = 50 ttvar SMALL_TICKS_COUNT = 5 ttvar body: some View { ttttHStack(alignment: .bottom, spacing: 0) { tttt
SwiftUI List EditModel multiple selection seems to have a bug staring on iOS 14.2 - 14.4 currently, to replicated the issue. Enter List edit mode Select items Scroll until selected items are not visible Scroll back to selected items. same issue that has screen recording - https://stackoverflow.com/questions/65781022/swiftui-list-cells-not-displaying-selection-state-correctly-after-scrolling