Lift pinned timelines modifiers up to CustomizeTimelinesList

.sheet on a Section with a header does not work, and produces warnings
about trying to present on a VC that already has a presentation. It
seems like the .sheet modifier is being applied to both the Section
content and header?

Fixes #514
This commit is contained in:
Shadowfacts 2024-07-21 12:02:14 -07:00
parent d4057adf4d
commit ca65f84137
2 changed files with 66 additions and 44 deletions

View File

@ -13,7 +13,7 @@ struct CustomizeTimelinesView: View {
let mastodonController: MastodonController
var body: some View {
CustomizeTimelinesList()
CustomizeTimelinesList(pinnedTimelines: mastodonController.accountPreferences.pinnedTimelines)
.environmentObject(mastodonController)
.environment(\.managedObjectContext, mastodonController.persistentContainer.viewContext)
}
@ -26,6 +26,14 @@ struct CustomizeTimelinesList: View {
@FetchRequest(sortDescriptors: []) private var filters: FetchedResults<FilterMO>
@Environment(\.dismiss) private var dismiss
@State private var deletionError: (any Error)?
// store this separately from AccountPreferences in the view, b/c the @LazilyDecoding wrapper breaks animations
@State private var pinnedTimelines: [PinnedTimeline]
@State private var isShowingAddHashtagSheet = false
@State private var isShowingAddInstanceSheet = false
init(pinnedTimelines: [PinnedTimeline]) {
self.pinnedTimelines = pinnedTimelines
}
var body: some View {
if #available(iOS 16.0, *) {
@ -50,7 +58,11 @@ struct CustomizeTimelinesList: View {
private var navigationBody: some View {
List {
PinnedTimelinesView(accountPreferences: mastodonController.accountPreferences)
PinnedTimelinesView(
pinnedTimelines: $pinnedTimelines,
isShowingAddHashtagSheet: $isShowingAddHashtagSheet,
isShowingAddInstanceSheet: $isShowingAddInstanceSheet
)
.appGroupedListRowBackground()
Section {
@ -99,6 +111,12 @@ struct CustomizeTimelinesList: View {
}
}
}
.modifier(PinnedTimelinesModifier(
accountPreferences: mastodonController.accountPreferences,
pinnedTimelines: $pinnedTimelines,
isShowingAddHashtagSheet: $isShowingAddHashtagSheet,
isShowingAddInstanceSheet: $isShowingAddInstanceSheet
))
.alertWithData("Error Deleting Filter", data: $deletionError, actions: { _ in
Button("OK") {
self.deletionError = nil

View File

@ -11,17 +11,10 @@ import Pachyderm
struct PinnedTimelinesView: View {
@EnvironmentObject private var mastodonController: MastodonController
@ObservedObject private var accountPreferences: AccountPreferences
@State private var isShowingAddHashtagSheet = false
@State private var isShowingAddInstanceSheet = false
// store this separately from AccountPreferences in the view, b/c the @LazilyDecoding wrapper breaks animations
@State private var pinnedTimelines: [PinnedTimeline]
init(accountPreferences: AccountPreferences) {
self.accountPreferences = accountPreferences
self.pinnedTimelines = accountPreferences.pinnedTimelines
}
@Binding var pinnedTimelines: [PinnedTimeline]
@Binding var isShowingAddHashtagSheet: Bool
@Binding var isShowingAddInstanceSheet: Bool
var body: some View {
Section {
@ -110,6 +103,17 @@ struct PinnedTimelinesView: View {
} header: {
Text("Pinned Timelines")
}
}
}
struct PinnedTimelinesModifier: ViewModifier {
let accountPreferences: AccountPreferences
@Binding var pinnedTimelines: [PinnedTimeline]
@Binding var isShowingAddHashtagSheet: Bool
@Binding var isShowingAddInstanceSheet: Bool
func body(content: Content) -> some View {
content
.sheet(isPresented: $isShowingAddHashtagSheet, content: {
#if os(visionOS)
AddHashtagPinnedTimelineView(pinnedTimelines: $pinnedTimelines)