Skip to content

Commit

Permalink
Remove external init for StatusRowView
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed Jul 18, 2024
1 parent 500c798 commit 814a0f7
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 31 deletions.
3 changes: 0 additions & 3 deletions IceCubesApp/App/Main/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ struct AppView: View {
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.30), for: .tabBar)
}
}
.introspect(.tabView, on: .iOS(.v17, .v18)) { (_: UITabBarController) in
UITabBar.setAnimationsEnabled(false)
}
.id(appAccountsManager.currentClient.id)
.withSheetDestinations(sheetDestinations: $appRouterPath.presentedSheet)
}
Expand Down
4 changes: 2 additions & 2 deletions IceCubesApp/App/Tabs/Settings/DisplaySettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct DisplaySettingsView: View {
ZStack(alignment: .top) {
Form {
#if !os(visionOS)
StatusRowView(viewModel: previewStatusViewModel)
StatusRowExternalView(viewModel: previewStatusViewModel)
.allowsHitTesting(false)
.opacity(0)
.hidden()
Expand Down Expand Up @@ -85,7 +85,7 @@ struct DisplaySettingsView: View {

private var examplePost: some View {
VStack(spacing: 0) {
StatusRowView(viewModel: previewStatusViewModel)
StatusRowExternalView(viewModel: previewStatusViewModel)
.allowsHitTesting(false)
.padding(.layoutPadding)
.background(theme.primaryBackgroundColor)
Expand Down
2 changes: 1 addition & 1 deletion Packages/Account/Sources/Account/AccountDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public struct AccountDetailView: View {
.listRowBackground(theme.primaryBackgroundColor)
#endif
ForEach(viewModel.pinned) { status in
StatusRowView(viewModel: .init(status: status, client: client, routerPath: routerPath))
StatusRowExternalView(viewModel: .init(status: status, client: client, routerPath: routerPath))
}
Rectangle()
#if os(visionOS)
Expand Down
6 changes: 3 additions & 3 deletions Packages/Explore/Sources/Explore/ExploreView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public struct ExploreView: View {

private var loadingView: some View {
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)
.redacted(reason: .placeholder)
.allowsHitTesting(false)
Expand Down Expand Up @@ -188,7 +188,7 @@ public struct ExploreView: View {
if !results.statuses.isEmpty, viewModel.searchScope == .all || viewModel.searchScope == .posts {
Section("explore.section.posts") {
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)
.listRowBackground(theme.primaryBackgroundColor)
#else
Expand Down Expand Up @@ -266,7 +266,7 @@ public struct ExploreView: View {
ForEach(viewModel.trendingStatuses
.prefix(upTo: viewModel.trendingStatuses.count > 3 ? 3 : viewModel.trendingStatuses.count))
{ status in
StatusRowView(viewModel: .init(status: status, client: client, routerPath: routerPath))
StatusRowExternalView(viewModel: .init(status: status, client: client, routerPath: routerPath))
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ struct NotificationRowView: View {
if let status = notification.status {
HStack {
if type == .mention {
StatusRowView(viewModel: .init(status: status,
client: client,
routerPath: routerPath,
showActions: true))
StatusRowExternalView(viewModel: .init(status: status,
client: client,
routerPath: routerPath,
showActions: true))
.environment(\.isMediaCompact, false)
} else {
StatusRowView(viewModel: .init(status: status,
client: client,
routerPath: routerPath,
showActions: false,
textDisabled: true))
StatusRowExternalView(viewModel: .init(status: status,
client: client,
routerPath: routerPath,
showActions: false,
textDisabled: true))
.lineLimit(4)
.environment(\.isMediaCompact, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public struct StatusDetailView: View {

private var loadingDetailView: some View {
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)
.allowsHitTesting(false)
}
Expand Down
3 changes: 2 additions & 1 deletion Packages/StatusKit/Sources/StatusKit/Editor/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ extension StatusEditor {
StatusRowView(viewModel: .init(status: status,
client: client,
routerPath: RouterPath(),
showActions: false))
showActions: false),
context: .timeline)
.accessibilityLabel(status.content.asRawText)
.environment(RouterPath())
.allowsHitTesting(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public struct StatusEmbeddedView: View {
StatusRowView(viewModel: .init(status: status,
client: client,
routerPath: routerPath,
showActions: false))
showActions: false),
context: .timeline)
.accessibilityLabel(status.content.asRawText)
.environment(\.isCompact, true)
.environment(\.isMediaCompact, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public struct StatusesListView<Fetcher>: View where Fetcher: StatusesFetcher {
switch fetcher.statusesState {
case .loading:
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)
.allowsHitTesting(false)
}
Expand All @@ -48,7 +49,8 @@ public struct StatusesListView<Fetcher>: View where Fetcher: StatusesFetcher {
StatusRowView(viewModel: StatusRowViewModel(status: status,
client: client,
routerPath: routerPath,
isRemote: isRemote))
isRemote: isRemote),
context: .timeline)
.onAppear {
fetcher.statusDidAppear(status: status)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
11 changes: 4 additions & 7 deletions Packages/StatusKit/Sources/StatusKit/Row/StatusRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ public struct StatusRowView: View {
@Environment(Theme.self) private var theme
@Environment(Client.self) private var client

@State private var viewModel: StatusRowViewModel
@State private var showSelectableText: Bool = false
@State private var isBlockConfirmationPresented = false

public enum Context { case timeline, detail }
private let context: Context

public init(viewModel: StatusRowViewModel, context: Context = .timeline) {
_viewModel = .init(initialValue: viewModel)
self.context = context
}

@State public var viewModel: StatusRowViewModel
public let context: Context

var contextMenu: some View {
StatusRowContextMenu(viewModel: viewModel,
Expand All @@ -42,6 +38,7 @@ public struct StatusRowView: View {
}

public var body: some View {
let _ = Self._printChanges()
HStack(spacing: 0) {
if !isCompact {
HStack(spacing: 3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct StatusRowContextMenu: View {

Button {
let view = HStack {
StatusRowView(viewModel: viewModel)
StatusRowView(viewModel: viewModel, context: .timeline)
.padding(16)
}
.environment(\.isInCaptureMode, true)
Expand Down

0 comments on commit 814a0f7

Please sign in to comment.