forked from shadowfacts/Tusker
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:
parent
d4057adf4d
commit
ca65f84137
|
@ -13,7 +13,7 @@ struct CustomizeTimelinesView: View {
|
||||||
let mastodonController: MastodonController
|
let mastodonController: MastodonController
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
CustomizeTimelinesList()
|
CustomizeTimelinesList(pinnedTimelines: mastodonController.accountPreferences.pinnedTimelines)
|
||||||
.environmentObject(mastodonController)
|
.environmentObject(mastodonController)
|
||||||
.environment(\.managedObjectContext, mastodonController.persistentContainer.viewContext)
|
.environment(\.managedObjectContext, mastodonController.persistentContainer.viewContext)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,15 @@ struct CustomizeTimelinesList: View {
|
||||||
@FetchRequest(sortDescriptors: []) private var filters: FetchedResults<FilterMO>
|
@FetchRequest(sortDescriptors: []) private var filters: FetchedResults<FilterMO>
|
||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
@State private var deletionError: (any Error)?
|
@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 {
|
var body: some View {
|
||||||
if #available(iOS 16.0, *) {
|
if #available(iOS 16.0, *) {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
|
@ -50,8 +58,12 @@ struct CustomizeTimelinesList: View {
|
||||||
|
|
||||||
private var navigationBody: some View {
|
private var navigationBody: some View {
|
||||||
List {
|
List {
|
||||||
PinnedTimelinesView(accountPreferences: mastodonController.accountPreferences)
|
PinnedTimelinesView(
|
||||||
.appGroupedListRowBackground()
|
pinnedTimelines: $pinnedTimelines,
|
||||||
|
isShowingAddHashtagSheet: $isShowingAddHashtagSheet,
|
||||||
|
isShowingAddInstanceSheet: $isShowingAddInstanceSheet
|
||||||
|
)
|
||||||
|
.appGroupedListRowBackground()
|
||||||
|
|
||||||
Section {
|
Section {
|
||||||
Toggle(isOn: $preferences.hideReblogsInTimelines) {
|
Toggle(isOn: $preferences.hideReblogsInTimelines) {
|
||||||
|
@ -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
|
.alertWithData("Error Deleting Filter", data: $deletionError, actions: { _ in
|
||||||
Button("OK") {
|
Button("OK") {
|
||||||
self.deletionError = nil
|
self.deletionError = nil
|
||||||
|
|
|
@ -11,17 +11,10 @@ import Pachyderm
|
||||||
|
|
||||||
struct PinnedTimelinesView: View {
|
struct PinnedTimelinesView: View {
|
||||||
@EnvironmentObject private var mastodonController: MastodonController
|
@EnvironmentObject private var mastodonController: MastodonController
|
||||||
@ObservedObject private var accountPreferences: AccountPreferences
|
|
||||||
|
|
||||||
@State private var isShowingAddHashtagSheet = false
|
@Binding var pinnedTimelines: [PinnedTimeline]
|
||||||
@State private var isShowingAddInstanceSheet = false
|
@Binding var isShowingAddHashtagSheet: Bool
|
||||||
// store this separately from AccountPreferences in the view, b/c the @LazilyDecoding wrapper breaks animations
|
@Binding var isShowingAddInstanceSheet: Bool
|
||||||
@State private var pinnedTimelines: [PinnedTimeline]
|
|
||||||
|
|
||||||
init(accountPreferences: AccountPreferences) {
|
|
||||||
self.accountPreferences = accountPreferences
|
|
||||||
self.pinnedTimelines = accountPreferences.pinnedTimelines
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Section {
|
Section {
|
||||||
|
@ -110,42 +103,53 @@ struct PinnedTimelinesView: View {
|
||||||
} header: {
|
} header: {
|
||||||
Text("Pinned Timelines")
|
Text("Pinned Timelines")
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $isShowingAddHashtagSheet, content: {
|
}
|
||||||
#if os(visionOS)
|
}
|
||||||
AddHashtagPinnedTimelineView(pinnedTimelines: $pinnedTimelines)
|
|
||||||
.edgesIgnoringSafeArea(.bottom)
|
struct PinnedTimelinesModifier: ViewModifier {
|
||||||
#else
|
let accountPreferences: AccountPreferences
|
||||||
if #available(iOS 16.0, *) {
|
@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)
|
AddHashtagPinnedTimelineView(pinnedTimelines: $pinnedTimelines)
|
||||||
.edgesIgnoringSafeArea(.bottom)
|
.edgesIgnoringSafeArea(.bottom)
|
||||||
} else {
|
#else
|
||||||
AddHashtagPinnedTimelineRepresentable(pinnedTimelines: $pinnedTimelines)
|
if #available(iOS 16.0, *) {
|
||||||
|
AddHashtagPinnedTimelineView(pinnedTimelines: $pinnedTimelines)
|
||||||
|
.edgesIgnoringSafeArea(.bottom)
|
||||||
|
} else {
|
||||||
|
AddHashtagPinnedTimelineRepresentable(pinnedTimelines: $pinnedTimelines)
|
||||||
|
.edgesIgnoringSafeArea(.bottom)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
})
|
||||||
|
.sheet(isPresented: $isShowingAddInstanceSheet, content: {
|
||||||
|
AddInstancePinnedTimelineView(pinnedTimelines: $pinnedTimelines)
|
||||||
.edgesIgnoringSafeArea(.bottom)
|
.edgesIgnoringSafeArea(.bottom)
|
||||||
|
})
|
||||||
|
.onReceive(accountPreferences.publisher(for: \.pinnedTimelinesData)) { _ in
|
||||||
|
if pinnedTimelines != accountPreferences.pinnedTimelines {
|
||||||
|
pinnedTimelines = accountPreferences.pinnedTimelines
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if os(visionOS)
|
||||||
|
.onChange(of: pinnedTimelines) {
|
||||||
|
if accountPreferences.pinnedTimelines != pinnedTimelines {
|
||||||
|
accountPreferences.pinnedTimelines = pinnedTimelines
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
.onChange(of: pinnedTimelines) { newValue in
|
||||||
|
if accountPreferences.pinnedTimelines != newValue {
|
||||||
|
accountPreferences.pinnedTimelines = newValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
})
|
|
||||||
.sheet(isPresented: $isShowingAddInstanceSheet, content: {
|
|
||||||
AddInstancePinnedTimelineView(pinnedTimelines: $pinnedTimelines)
|
|
||||||
.edgesIgnoringSafeArea(.bottom)
|
|
||||||
})
|
|
||||||
.onReceive(accountPreferences.publisher(for: \.pinnedTimelinesData)) { _ in
|
|
||||||
if pinnedTimelines != accountPreferences.pinnedTimelines {
|
|
||||||
pinnedTimelines = accountPreferences.pinnedTimelines
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if os(visionOS)
|
|
||||||
.onChange(of: pinnedTimelines) {
|
|
||||||
if accountPreferences.pinnedTimelines != pinnedTimelines {
|
|
||||||
accountPreferences.pinnedTimelines = pinnedTimelines
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
.onChange(of: pinnedTimelines) { newValue in
|
|
||||||
if accountPreferences.pinnedTimelines != newValue {
|
|
||||||
accountPreferences.pinnedTimelines = newValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue