/ChannelsView.swift Secret
Last active
February 23, 2021 14:28
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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