Making the search bar using .searchable permanently visible

I recently tried out the new .searchable modifier with SwiftUI to add searchable bars to my Core Data application and found an elegant solution (I think!), described it in my blog (too long to post here): https://backtosoftwaredevelopment.blogspot.com/2021/07/using-searchable-views-with-core-data.html

I was wondering how to make sure the search bar is always visible, instead of being visible when we drag the NavigationView down. The placement: parameter seems to be it, but I wasn't sure how to make it permanently visible.

Answered by LaithB in 708504022

set: .navigationBarDrawer(displayMode: .always).

.searchable(text: $searchStr, placement: .navigationBarDrawer(displayMode: .always))

Hi,

For now try what is suggested in https://stackoverflow.com/a/68154005/1356575 . It's an hack but it works.

Best regards.

Accepted Answer

set: .navigationBarDrawer(displayMode: .always).

.searchable(text: $searchStr, placement: .navigationBarDrawer(displayMode: .always))

Hi There,

One idea I've just discovered is using a textfield in place of the searchable modifier.

I used a published property wrapper in a class to handle the back and forth of the text entry.

Let me know if you need further clarification.

Cheers.

Making the search bar using .searchable permanently visible
 
 
Q