mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
Allow displaying UserSuggestionList without shadow
This commit is contained in:
@@ -35,6 +35,7 @@ struct UserSuggestionList: View {
|
||||
// MARK: Public
|
||||
|
||||
@ObservedObject var viewModel: UserSuggestionViewModel.Context
|
||||
var showBackgroundShadow: Bool = true
|
||||
|
||||
var body: some View {
|
||||
if viewModel.viewState.items.isEmpty {
|
||||
@@ -46,25 +47,12 @@ struct UserSuggestionList: View {
|
||||
userId: "Prototype")
|
||||
.background(ViewFrameReader(frame: $prototypeListItemFrame))
|
||||
.hidden()
|
||||
BackgroundView {
|
||||
List(viewModel.viewState.items) { item in
|
||||
Button {
|
||||
viewModel.send(viewAction: .selectedItem(item))
|
||||
} label: {
|
||||
UserSuggestionListItem(
|
||||
avatar: item.avatar,
|
||||
displayName: item.displayName,
|
||||
userId: item.id
|
||||
)
|
||||
.padding(.bottom, Constants.listItemPadding)
|
||||
.padding(.top, viewModel.viewState.items.first?.id == item.id ? Constants.listItemPadding + Constants.topPadding : Constants.listItemPadding)
|
||||
}
|
||||
if showBackgroundShadow {
|
||||
BackgroundView {
|
||||
list()
|
||||
}
|
||||
.listStyle(PlainListStyle())
|
||||
.frame(height: min(Constants.maxHeight,
|
||||
min(contentHeightForRowCount(Constants.maxVisibleRows),
|
||||
contentHeightForRowCount(viewModel.viewState.items.count))))
|
||||
.id(UUID()) // Rebuild the whole list on item changes. Fixes performance issues.
|
||||
} else {
|
||||
list()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,6 +61,27 @@ struct UserSuggestionList: View {
|
||||
private func contentHeightForRowCount(_ count: Int) -> CGFloat {
|
||||
(prototypeListItemFrame.height + (Constants.listItemPadding * 2) + Constants.lineSpacing) * CGFloat(count) + Constants.topPadding
|
||||
}
|
||||
|
||||
private func list() -> some View {
|
||||
List(viewModel.viewState.items) { item in
|
||||
Button {
|
||||
viewModel.send(viewAction: .selectedItem(item))
|
||||
} label: {
|
||||
UserSuggestionListItem(
|
||||
avatar: item.avatar,
|
||||
displayName: item.displayName,
|
||||
userId: item.id
|
||||
)
|
||||
.padding(.bottom, Constants.listItemPadding)
|
||||
.padding(.top, viewModel.viewState.items.first?.id == item.id ? Constants.listItemPadding + Constants.topPadding : Constants.listItemPadding)
|
||||
}
|
||||
}
|
||||
.listStyle(PlainListStyle())
|
||||
.frame(height: min(Constants.maxHeight,
|
||||
min(contentHeightForRowCount(Constants.maxVisibleRows),
|
||||
contentHeightForRowCount(viewModel.viewState.items.count))))
|
||||
.id(UUID()) // Rebuild the whole list on item changes. Fixes performance issues.
|
||||
}
|
||||
}
|
||||
|
||||
private struct BackgroundView<Content: View>: View {
|
||||
|
||||
Reference in New Issue
Block a user