Skip to content

Instantly share code, notes, and snippets.

@cardoso
Last active February 23, 2021 14:28
Show Gist options
  • Save cardoso/7f8f868d36c37a1ec139ab9954883301 to your computer and use it in GitHub Desktop.
Save cardoso/7f8f868d36c37a1ec139ab9954883301 to your computer and use it in GitHub Desktop.
import SwiftUI
import StreamChatClient
struct ChannelsView: View {
...
var searchView: some View {
if(createTrigger) {
return AnyView(EmptyView())
} else {
let binding = Binding<String>(get: {
self.searchTerm
}, set: {
self.searchTerm = $0
self.loadChannels()
})
return AnyView(HStack {
TextField("Search channels", text: binding)
if !searchTerm.isEmpty {
Button(action: clearPressed) {
Text("Clear")
}
}
}
.padding()
.onDisappear(perform: {
if !self.searchTerm.isEmpty {
self.clearPressed()
}
})
)
}
}
func clearPressed() {
self.searchTerm = ""
self.loadChannels()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment