Add PollListItem

This commit is contained in:
Alfonso Grillo 2023-01-12 16:52:11 +01:00
parent 0cc54b6e24
commit cf6d64a974
2 changed files with 61 additions and 3 deletions

View file

@ -38,11 +38,12 @@ struct PollHistory: View {
)
Spacer()
}
.padding(.horizontal, 16)
ScrollView {
LazyVStack(spacing: 32) {
ForEach(0..<10) { index in
Text("Active poll number: \(index)")
PollListItem(data: .init(startDate: Date(), question: "Poll question number \(index)"))
}
.frame(maxWidth: .infinity, alignment: .leading)
@ -53,11 +54,11 @@ struct PollHistory: View {
}
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(.horizontal, 16)
.padding(.top, 32)
}
}
.padding(.horizontal, 16)
.padding(.vertical, 32)
.padding(.top, 32)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(theme.colors.background.ignoresSafeArea())
.accentColor(theme.colors.accent)
@ -68,6 +69,7 @@ struct PollHistory: View {
struct PollHistory_Previews: PreviewProvider {
static let stateRenderer = MockPollHistoryScreenState.stateRenderer
static var previews: some View {
stateRenderer.screenGroup()
}

View file

@ -0,0 +1,56 @@
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import SwiftUI
struct PollListData {
let startDate: Date
let question: String
}
struct PollListItem: View {
@Environment(\.theme) private var theme
private let data: PollListData
init(data: PollListData) {
self.data = data
}
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text(data.startDate.description)
.foregroundColor(theme.colors.tertiaryContent)
.font(theme.fonts.caption1)
HStack(spacing: 8) {
Image(uiImage: Asset.Images.pollHistory.image)
.resizable()
.frame(width: 16, height: 16)
Text(data.question)
.foregroundColor(theme.colors.primaryContent)
.font(theme.fonts.body)
}
}
}
}
struct PollListItem_Previews: PreviewProvider {
static var previews: some View {
PollListItem(data: .init(startDate: .init(), question: "Did you like this poll?"))
}
}