mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 08:32:53 +02:00
#1098 - Switched to dynamically calculated row heights.
This commit is contained in:
@@ -21,9 +21,10 @@ import SwiftUI
|
||||
@available(iOS 14.0, *)
|
||||
struct UserSuggestionList: View {
|
||||
private struct Constants {
|
||||
static let rowHeight: CGFloat = 60.0
|
||||
static let maxHeight: CGFloat = 300.0
|
||||
static let listItemPadding: CGFloat = 4.0
|
||||
static let lineSpacing: CGFloat = 10.0
|
||||
static let maxHeight: CGFloat = 300.0
|
||||
static let maxVisibleRows = 4
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
@@ -31,31 +32,48 @@ struct UserSuggestionList: View {
|
||||
// MARK: Private
|
||||
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
@State private var prototypeListItemFrame: CGRect = .zero
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@ObservedObject var viewModel: UserSuggestionViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
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([.top, .bottom], Constants.listItemPadding)
|
||||
if viewModel.viewState.items.isEmpty {
|
||||
EmptyView()
|
||||
} else {
|
||||
ZStack {
|
||||
UserSuggestionListItem(avatar: AvatarInput(mxContentUri: "", matrixItemId: "", displayName: "Prototype"),
|
||||
displayName: "Prototype",
|
||||
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([.top, .bottom], 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.
|
||||
}
|
||||
}
|
||||
.listStyle(PlainListStyle())
|
||||
.environment(\.defaultMinListRowHeight, Constants.rowHeight)
|
||||
.frame(height: min(Constants.maxHeight, Constants.rowHeight * CGFloat(viewModel.viewState.items.count)))
|
||||
.id(UUID()) // Rebuild the whole list on item changes. Fixes performance issues.
|
||||
}
|
||||
}
|
||||
|
||||
private func contentHeightForRowCount(_ count: Int) -> CGFloat {
|
||||
(prototypeListItemFrame.height + (Constants.listItemPadding * 2) + Constants.lineSpacing) * CGFloat(count)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
|
||||
Reference in New Issue
Block a user