Craft search experiences in SwiftUI

RSS for tag

Discuss the WWDC21 session Craft search experiences in SwiftUI.

Posts under wwdc21-10176 tag

6 Posts

Post

Replies

Boosts

Views

Activity

SwiftUI isSearching environment value not updating properly
Hello - I am new to Swift so my apologies in advance if this is an easy fix. I am intrigued by the new .searchable modifier in SwiftUI as this seems like the most logical way to implement search in a SwiftUI-based app (instead of integrating with UIKit etc.) I tried running the following code import SwiftUI struct SearchableView: View {     @State var searchTerm: String = ""          @Environment(\.isSearching)     private var isSearching: Bool          var body: some View {         NavigationView {             Text("\(String(describing: isSearching))")         }.searchable(text: $searchTerm)     } } However, the value of isSearching doesn't seem to be changing when I click on the search bar and start typing. I tried adding @State to the isSearching variable but this resulted in an error. I would be very grateful for any suggestions! Thank you
2
0
3.3k
Apr ’22
How to make search bar in iOS 15 appear by default?
I started to develop an application using iOS15 and the new .searchable modifier. I have a simple layout with some placeholder results on the main page and a search field attached to the navigationBar. Currently, if the user loads the page and looks at the results (even scrolls a bit) will not be able find the search field as it's hidden by default. The user needs to scroll in reverse for the search bar to appear. How is this a good for UX? The only workaround is the drawer placement with .always, but that will make the navigation title inline. I really want to achieve the result from the Notes app, that has the search bar visible all the time. Any workaround? Was this feature really tested by anyone in a real app?
0
0
1.1k
Nov ’21
Picker under the search bar
Dear all, I want to add a Picker view under the search bar similarly as seen on the Files app: I would be happy with one of the two options - 1) to have a picker view to be visible under the search bar all the time (ie. even when the search bar is not activated), 2) to have the picker view to be visible when search bar is active. I tried to implement this by using the toolbar modifier but without luck. NavigationView {     List {         ...     }     .searchable(text: $searchText)     .toolbar {         ToolbarItem {             Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented)         }     } } I have also tried the workaround by adding the Picker view within the List/Form but in this case the Picker view disappears when the user scrolls the list down.     List {         Section {             Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented)         }         ...     }     .searchable(text: $searchText) } One last thing I tried was to put the picker view within the search bar’s suggestions parameter. This however, obscures the search results under the suggestions view.     List {         ...     }     .searchable(text: $searchText), suggestions: Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented) }) } Any ideas?
0
0
1.9k
Oct ’21
SwiftUI isSearching environment value not updating properly
Hello - I am new to Swift so my apologies in advance if this is an easy fix. I am intrigued by the new .searchable modifier in SwiftUI as this seems like the most logical way to implement search in a SwiftUI-based app (instead of integrating with UIKit etc.) I tried running the following code import SwiftUI struct SearchableView: View {     @State var searchTerm: String = ""          @Environment(\.isSearching)     private var isSearching: Bool          var body: some View {         NavigationView {             Text("\(String(describing: isSearching))")         }.searchable(text: $searchTerm)     } } However, the value of isSearching doesn't seem to be changing when I click on the search bar and start typing. I tried adding @State to the isSearching variable but this resulted in an error. I would be very grateful for any suggestions! Thank you
Replies
2
Boosts
0
Views
3.3k
Activity
Apr ’22
.searchable modifier with a keyboard shortcut
Hi, Does anyone knows if it is possible (or there are plans) to enable associating a .searchable modifier with a keyboard shortcut? It seems a no brainer and very useful for iPadOS or Catalyst. Thanks
Replies
4
Boosts
0
Views
3.6k
Activity
Apr ’22
How to make search bar in iOS 15 appear by default?
I started to develop an application using iOS15 and the new .searchable modifier. I have a simple layout with some placeholder results on the main page and a search field attached to the navigationBar. Currently, if the user loads the page and looks at the results (even scrolls a bit) will not be able find the search field as it's hidden by default. The user needs to scroll in reverse for the search bar to appear. How is this a good for UX? The only workaround is the drawer placement with .always, but that will make the navigation title inline. I really want to achieve the result from the Notes app, that has the search bar visible all the time. Any workaround? Was this feature really tested by anyone in a real app?
Replies
0
Boosts
0
Views
1.1k
Activity
Nov ’21
Picker under the search bar
Dear all, I want to add a Picker view under the search bar similarly as seen on the Files app: I would be happy with one of the two options - 1) to have a picker view to be visible under the search bar all the time (ie. even when the search bar is not activated), 2) to have the picker view to be visible when search bar is active. I tried to implement this by using the toolbar modifier but without luck. NavigationView {     List {         ...     }     .searchable(text: $searchText)     .toolbar {         ToolbarItem {             Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented)         }     } } I have also tried the workaround by adding the Picker view within the List/Form but in this case the Picker view disappears when the user scrolls the list down.     List {         Section {             Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented)         }         ...     }     .searchable(text: $searchText) } One last thing I tried was to put the picker view within the search bar’s suggestions parameter. This however, obscures the search results under the suggestions view.     List {         ...     }     .searchable(text: $searchText), suggestions: Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented) }) } Any ideas?
Replies
0
Boosts
0
Views
1.9k
Activity
Oct ’21
How to perform .onSumbit after selecting a search suggestion?
Currently in iOS 15 beta 2, you can the search suggestions to complete a search term, but is there a way that when the user select a suggestion, not only does it complete the term but also performs a .onSubmit? So that without having to hitting search on the keyboard, we can programmatically trigger a onSubmit?
Replies
0
Boosts
0
Views
752
Activity
Jul ’21
Binding -> Return from initializer without initializing all stored properties
When trying to add search to my app I get the warning "Return from initializer without initializing all stored properties" due to my Binding. But seems to me I'm doing exactly what the video is doing:     @Binding var searchableText: String Thoughts?
Replies
2
Boosts
0
Views
1.4k
Activity
Jul ’21