iOS/Sources/App/ClientEvents/LocationHistoryEntryListItemView.swift
Fábio Oliveira d7924bcf81
Snapshot preview reuse (#3484)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
SnapshottablePreviews applied in the LocationHistoryListView and
Widgets.

In LocationHistoryListView, due to how Realm is used and how previews
are implemented under the hood, the injected data is written both on
`init` and `onAppear`.

For Widgets, not all the previews are visible. This is a limitation of
the previews UI.

I also ended up removing the duplicate snapshots that would assert the
behavior when more than the allowed tiles were passed. This can be
restored if preferred.

---------

Co-authored-by: Bruno Pantaleão Gonçalves <5808343+bgoncal@users.noreply.github.com>
2025-03-24 11:14:54 +01:00

67 lines
1.9 KiB
Swift

import Shared
import SwiftUI
struct LocationHistoryEntryListItemView: View {
private let entry: LocationHistoryEntry
private let dateFormatter: DateFormatter
init(
entry: LocationHistoryEntry,
dateFormatter: DateFormatter
) {
self.entry = entry
self.dateFormatter = dateFormatter
}
var body: some View {
NavigationLink {
LocationHistoryDetailViewControllerWrapper(
currentEntry: entry
)
.edgesIgnoringSafeArea([.top, .bottom])
} label: {
VStack(alignment: .leading) {
Text(dateFormatter.string(from: entry.CreatedAt))
.foregroundStyle(.primary)
if let trigger = entry.Trigger {
Text(trigger)
.foregroundStyle(.secondary)
}
}
}
}
}
struct LocationHistoryEntryListItemView_Previews: PreviewProvider {
static var previews: some View {
configuration.previews()
}
static var configuration: SnapshottablePreviewConfigurations<LocationHistoryEntry> = .init(
configurations: [
.init(
item: LocationHistoryEntry(
updateType: .Manual,
location: .init(latitude: 41.1234, longitude: 52.2),
zone: .defaultSettingValue,
accuracyAuthorization: .fullAccuracy,
payload: "payload"
),
name: "LocationHistoryEntryListItemView"
),
]
) { item in
List {
Section {
LocationHistoryEntryListItemView(
entry: item,
dateFormatter: with(DateFormatter()) {
$0.dateStyle = .short
$0.timeStyle = .medium
}
)
}
}
}
}