Remove external init for StatusRowView

This commit is contained in:
Thomas Ricouard 2024-07-18 20:59:13 +02:00
parent 3f2fbeeec4
commit 54768772b5
11 changed files with 44 additions and 28 deletions

View file

@ -37,7 +37,7 @@ struct DisplaySettingsView: View {
ZStack(alignment: .top) { ZStack(alignment: .top) {
Form { Form {
#if !os(visionOS) #if !os(visionOS)
StatusRowView(viewModel: previewStatusViewModel) StatusRowExternalView(viewModel: previewStatusViewModel)
.allowsHitTesting(false) .allowsHitTesting(false)
.opacity(0) .opacity(0)
.hidden() .hidden()
@ -85,7 +85,7 @@ struct DisplaySettingsView: View {
private var examplePost: some View { private var examplePost: some View {
VStack(spacing: 0) { VStack(spacing: 0) {
StatusRowView(viewModel: previewStatusViewModel) StatusRowExternalView(viewModel: previewStatusViewModel)
.allowsHitTesting(false) .allowsHitTesting(false)
.padding(.layoutPadding) .padding(.layoutPadding)
.background(theme.primaryBackgroundColor) .background(theme.primaryBackgroundColor)

View file

@ -242,7 +242,7 @@ public struct AccountDetailView: View {
.listRowBackground(theme.primaryBackgroundColor) .listRowBackground(theme.primaryBackgroundColor)
#endif #endif
ForEach(viewModel.pinned) { status in ForEach(viewModel.pinned) { status in
StatusRowView(viewModel: .init(status: status, client: client, routerPath: routerPath)) StatusRowExternalView(viewModel: .init(status: status, client: client, routerPath: routerPath))
} }
Rectangle() Rectangle()
#if os(visionOS) #if os(visionOS)

View file

@ -155,7 +155,7 @@ public struct ExploreView: View {
private var loadingView: some View { private var loadingView: some View {
ForEach(Status.placeholders()) { status in ForEach(Status.placeholders()) { status in
StatusRowView(viewModel: .init(status: status, client: client, routerPath: routerPath)) StatusRowExternalView(viewModel: .init(status: status, client: client, routerPath: routerPath))
.padding(.vertical, 8) .padding(.vertical, 8)
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
.allowsHitTesting(false) .allowsHitTesting(false)
@ -201,7 +201,7 @@ public struct ExploreView: View {
if !results.statuses.isEmpty, viewModel.searchScope == .all || viewModel.searchScope == .posts { if !results.statuses.isEmpty, viewModel.searchScope == .all || viewModel.searchScope == .posts {
Section("explore.section.posts") { Section("explore.section.posts") {
ForEach(results.statuses) { status in ForEach(results.statuses) { status in
StatusRowView(viewModel: .init(status: status, client: client, routerPath: routerPath)) StatusRowExternalView(viewModel: .init(status: status, client: client, routerPath: routerPath))
#if !os(visionOS) #if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor) .listRowBackground(theme.primaryBackgroundColor)
#else #else
@ -279,7 +279,7 @@ public struct ExploreView: View {
ForEach(viewModel.trendingStatuses ForEach(viewModel.trendingStatuses
.prefix(upTo: viewModel.trendingStatuses.count > 3 ? 3 : viewModel.trendingStatuses.count)) .prefix(upTo: viewModel.trendingStatuses.count > 3 ? 3 : viewModel.trendingStatuses.count))
{ status in { status in
StatusRowView(viewModel: .init(status: status, client: client, routerPath: routerPath)) StatusRowExternalView(viewModel: .init(status: status, client: client, routerPath: routerPath))
#if !os(visionOS) #if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor) .listRowBackground(theme.primaryBackgroundColor)
#else #else

View file

@ -156,13 +156,13 @@ struct NotificationRowView: View {
if let status = notification.status { if let status = notification.status {
HStack { HStack {
if type == .mention { if type == .mention {
StatusRowView(viewModel: .init(status: status, StatusRowExternalView(viewModel: .init(status: status,
client: client, client: client,
routerPath: routerPath, routerPath: routerPath,
showActions: true)) showActions: true))
.environment(\.isMediaCompact, false) .environment(\.isMediaCompact, false)
} else { } else {
StatusRowView(viewModel: .init(status: status, StatusRowExternalView(viewModel: .init(status: status,
client: client, client: client,
routerPath: routerPath, routerPath: routerPath,
showActions: false, showActions: false,

View file

@ -155,7 +155,7 @@ public struct StatusDetailView: View {
private var loadingDetailView: some View { private var loadingDetailView: some View {
ForEach(Status.placeholders()) { status in ForEach(Status.placeholders()) { status in
StatusRowView(viewModel: .init(status: status, client: client, routerPath: routerPath)) StatusRowView(viewModel: .init(status: status, client: client, routerPath: routerPath), context: .timeline)
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
.allowsHitTesting(false) .allowsHitTesting(false)
} }

View file

@ -129,7 +129,8 @@ extension StatusEditor {
StatusRowView(viewModel: .init(status: status, StatusRowView(viewModel: .init(status: status,
client: client, client: client,
routerPath: RouterPath(), routerPath: RouterPath(),
showActions: false)) showActions: false),
context: .timeline)
.accessibilityLabel(status.content.asRawText) .accessibilityLabel(status.content.asRawText)
.environment(RouterPath()) .environment(RouterPath())
.allowsHitTesting(false) .allowsHitTesting(false)

View file

@ -26,7 +26,8 @@ public struct StatusEmbeddedView: View {
StatusRowView(viewModel: .init(status: status, StatusRowView(viewModel: .init(status: status,
client: client, client: client,
routerPath: routerPath, routerPath: routerPath,
showActions: false)) showActions: false),
context: .timeline)
.accessibilityLabel(status.content.asRawText) .accessibilityLabel(status.content.asRawText)
.environment(\.isCompact, true) .environment(\.isCompact, true)
.environment(\.isMediaCompact, true) .environment(\.isMediaCompact, true)

View file

@ -29,7 +29,8 @@ public struct StatusesListView<Fetcher>: View where Fetcher: StatusesFetcher {
switch fetcher.statusesState { switch fetcher.statusesState {
case .loading: case .loading:
ForEach(Status.placeholders()) { status in ForEach(Status.placeholders()) { status in
StatusRowView(viewModel: .init(status: status, client: client, routerPath: routerPath)) StatusRowView(viewModel: .init(status: status, client: client, routerPath: routerPath),
context: .timeline)
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
.allowsHitTesting(false) .allowsHitTesting(false)
} }
@ -48,7 +49,8 @@ public struct StatusesListView<Fetcher>: View where Fetcher: StatusesFetcher {
StatusRowView(viewModel: StatusRowViewModel(status: status, StatusRowView(viewModel: StatusRowViewModel(status: status,
client: client, client: client,
routerPath: routerPath, routerPath: routerPath,
isRemote: isRemote)) isRemote: isRemote),
context: .timeline)
.onAppear { .onAppear {
fetcher.statusDidAppear(status: status) fetcher.statusDidAppear(status: status)
} }

View file

@ -0,0 +1,15 @@
import SwiftUI
public struct StatusRowExternalView: View {
@State private var viewModel: StatusRowViewModel
private let context: StatusRowView.Context
public init(viewModel: StatusRowViewModel, context: StatusRowView.Context = .timeline) {
_viewModel = .init(initialValue: viewModel)
self.context = context
}
public var body: some View {
StatusRowView(viewModel: viewModel, context: context)
}
}

View file

@ -23,17 +23,13 @@ public struct StatusRowView: View {
@Environment(Theme.self) private var theme @Environment(Theme.self) private var theme
@Environment(Client.self) private var client @Environment(Client.self) private var client
@State private var viewModel: StatusRowViewModel
@State private var showSelectableText: Bool = false @State private var showSelectableText: Bool = false
@State private var isBlockConfirmationPresented = false @State private var isBlockConfirmationPresented = false
public enum Context { case timeline, detail } public enum Context { case timeline, detail }
private let context: Context
public init(viewModel: StatusRowViewModel, context: Context = .timeline) { @State public var viewModel: StatusRowViewModel
_viewModel = .init(initialValue: viewModel) public let context: Context
self.context = context
}
var contextMenu: some View { var contextMenu: some View {
StatusRowContextMenu(viewModel: viewModel, StatusRowContextMenu(viewModel: viewModel,
@ -42,6 +38,7 @@ public struct StatusRowView: View {
} }
public var body: some View { public var body: some View {
let _ = Self._printChanges()
HStack(spacing: 0) { HStack(spacing: 0) {
if !isCompact { if !isCompact {
HStack(spacing: 3) { HStack(spacing: 3) {

View file

@ -104,7 +104,7 @@ struct StatusRowContextMenu: View {
Button { Button {
let view = HStack { let view = HStack {
StatusRowView(viewModel: viewModel) StatusRowView(viewModel: viewModel, context: .timeline)
.padding(16) .padding(16)
} }
.environment(\.isInCaptureMode, true) .environment(\.isInCaptureMode, true)