Move onReceive to container where it belongs

This commit is contained in:
Maurice Parker 2020-07-26 07:06:00 -05:00
parent 8f81b72fc9
commit a3459bc57a
2 changed files with 9 additions and 18 deletions

View File

@ -13,14 +13,21 @@ struct SidebarContainerView: View {
@Environment(\.undoManager) var undoManager
@EnvironmentObject private var sceneModel: SceneModel
@State var sidebarItems = [SidebarItem]()
@ViewBuilder var body: some View {
SidebarView()
SidebarView(sidebarItems: $sidebarItems)
.modifier(SidebarToolbarModifier())
.modifier(SidebarListStyleModifier())
.environmentObject(sceneModel.sidebarModel)
.onAppear {
sceneModel.sidebarModel.undoManager = undoManager
}
.onReceive(sceneModel.sidebarModel.sidebarItemsPublisher!) { newItems in
withAnimation {
sidebarItems = newItems
}
}
}
}

View File

@ -13,20 +13,18 @@ struct SidebarView: View {
// I had to comment out SceneStorage because it blows up if used on macOS
// @SceneStorage("expandedContainers") private var expandedContainerData = Data()
@Environment(\.undoManager) var undoManager
@StateObject private var expandedContainers = SidebarExpandedContainers()
@EnvironmentObject private var refreshProgress: RefreshProgressModel
@EnvironmentObject private var sceneModel: SceneModel
@EnvironmentObject private var sidebarModel: SidebarModel
@State var sidebarItems = [SidebarItem]()
@Binding var sidebarItems: [SidebarItem]
private let threshold: CGFloat = 80
@State private var previousScrollOffset: CGFloat = 0
@State private var scrollOffset: CGFloat = 0
@State var pulling: Bool = false
@State var refreshing: Bool = false
@ViewBuilder var body: some View {
#if os(macOS)
@ -64,12 +62,6 @@ struct SidebarView: View {
.transition(.move(edge: .bottom))
}
}
.onAppear {
sidebarModel.undoManager = undoManager
}
.onReceive(sidebarModel.sidebarItemsPublisher!) { newItems in
sidebarItems = newItems
}
#else
ZStack(alignment: .top) {
List {
@ -84,14 +76,6 @@ struct SidebarView: View {
ProgressView().offset(y: -40)
}
}
.onAppear {
sidebarModel.undoManager = undoManager
}
.onReceive(sidebarModel.sidebarItemsPublisher!) { newItems in
withAnimation {
sidebarItems = newItems
}
}
#endif
// .onAppear {