-
-
Save cardoso/7f8f868d36c37a1ec139ab9954883301 to your computer and use it in GitHub Desktop.
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