#1098 - Various changes following code review.

This commit is contained in:
Stefan Ceriu
2021-10-07 12:21:40 +03:00
parent 9470a9336f
commit 94459be545
8 changed files with 16 additions and 15 deletions
@@ -20,7 +20,7 @@ import Foundation
import Combine
@available(iOS 14.0, *)
struct UserSuggestionViewStateItem: BindableState, Identifiable {
struct UserSuggestionViewStateItem: Identifiable {
let id: String
let avatar: AvatarInputProtocol?
let displayName: String?
@@ -87,7 +87,7 @@ class UserSuggestionService: UserSuggestionServiceProtocol {
}
// Partial username should start with one and only one "@" character
guard lastComponent.prefix(while: { character in character == "@" }).count == 1 else {
guard lastComponent.prefix(while: { $0 == "@" }).count == 1 else {
return
}
@@ -97,8 +97,8 @@ class UserSuggestionService: UserSuggestionServiceProtocol {
partialName.removeFirst()
self.items.send(self.suggestionItems.filter({ userSuggestion in
let containedInUsername = userSuggestion.userId.lowercased().range(of: partialName.lowercased()) != .none
let containedInDisplayName = (userSuggestion.displayName ?? "").lowercased().range(of: partialName.lowercased()) != .none
let containedInUsername = userSuggestion.userId.lowercased().contains(partialName.lowercased())
let containedInDisplayName = (userSuggestion.displayName ?? "").lowercased().contains(partialName.lowercased())
return (containedInUsername || containedInDisplayName)
}))
@@ -77,6 +77,9 @@ class UserSuggestionServiceTests: XCTestCase {
service?.processTextMessage("@@")
assert(service?.items.value.count == 0)
service?.processTextMessage("alice@matrix.org")
assert(service?.items.value.count == 0)
}
func testStuff() {
@@ -51,6 +51,7 @@ struct UserSuggestionList: View {
.listStyle(PlainListStyle())
.environment(\.defaultMinListRowHeight, rowHeight)
.frame(height: min(maxHeight, rowHeight * CGFloat(viewModel.viewState.items.count)))
// .frame(maxHeight: maxHeight)
.id(UUID()) // Rebuild the whole list on item changes. Fixes performance issues.
}
}
@@ -69,7 +70,7 @@ private struct BackgroundView<Content: View>: View {
}
var body: some View {
VStack(content: content)
content()
.background(theme.colors.background)
.clipShape(RoundedCornerShape(radius: shadowRadius, corners: [.topLeft, .topRight]))
.shadow(color: .black.opacity(0.20), radius: 20.0, x: 0.0, y: 3.0)
@@ -36,7 +36,7 @@ struct UserSuggestionListItem: View {
if let avatar = avatar {
AvatarImage(avatarData: avatar, size: .medium)
}
VStack(alignment:.leading) {
VStack(alignment: .leading) {
Text(displayName ?? "")
.font(theme.fonts.body)
.foregroundColor(theme.colors.primaryContent)
@@ -33,20 +33,18 @@ struct UserSuggestionListWithInput: View {
var viewModel: UserSuggestionListWithInputViewModel
@State private var inputText: String = ""
var body: some View {
VStack(spacing: 0.0) {
UserSuggestionList(viewModel: viewModel.listViewModel.context)
TextField("Search for user", text: $inputText)
.background(Color.white)
.onChange(of: inputText, perform: { value in
viewModel.callback(value)
})
.border(Color.black)
.onChange(of: inputText, perform:viewModel.callback)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding([.leading, .trailing])
.onAppear(perform: {
.onAppear {
inputText = "@-" // Make the list show all available mock results
})
}
}
}
}