mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Refactor sidebar styling to remove duplicate code
This commit is contained in:
@@ -17,15 +17,10 @@ struct SceneNavigationView: View {
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
#if os(macOS)
|
||||
RegularSidebarContainerView()
|
||||
SidebarContainerView()
|
||||
.frame(minWidth: 100, idealWidth: 150, maxHeight: .infinity)
|
||||
#else
|
||||
if horizontalSizeClass == .compact {
|
||||
CompactSidebarContainerView()
|
||||
|
||||
} else {
|
||||
RegularSidebarContainerView()
|
||||
}
|
||||
SidebarContainerView()
|
||||
#endif
|
||||
|
||||
#if os(iOS)
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// CompactSidebarContainerView.swift
|
||||
// Multiplatform iOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 29/6/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CompactSidebarContainerView: View {
|
||||
|
||||
@EnvironmentObject private var sceneModel: SceneModel
|
||||
@StateObject private var sidebarModel = SidebarModel()
|
||||
@State private var showSettings: Bool = false
|
||||
|
||||
var body: some View {
|
||||
SidebarView()
|
||||
.modifier(SidebarToolbarModifier())
|
||||
.environmentObject(sidebarModel)
|
||||
.navigationBarTitle(Text("Feeds"))
|
||||
.listStyle(PlainListStyle())
|
||||
.onAppear {
|
||||
sceneModel.sidebarModel = sidebarModel
|
||||
sidebarModel.delegate = sceneModel
|
||||
sidebarModel.rebuildSidebarItems()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct CompactSidebarContainerView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
CompactSidebarContainerView()
|
||||
.environmentObject(SceneModel())
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// RegularSidebarContainerView.swift
|
||||
// SidebarContainerView.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 6/28/20.
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct RegularSidebarContainerView: View {
|
||||
struct SidebarContainerView: View {
|
||||
|
||||
@EnvironmentObject private var sceneModel: SceneModel
|
||||
@StateObject private var sidebarModel = SidebarModel()
|
||||
@@ -18,9 +18,9 @@ struct RegularSidebarContainerView: View {
|
||||
@ViewBuilder var body: some View {
|
||||
SidebarView()
|
||||
.modifier(SidebarToolbarModifier())
|
||||
.modifier(SidebarListStyleModifier())
|
||||
.environmentObject(sidebarModel)
|
||||
.navigationTitle(Text("Feeds"))
|
||||
.listStyle(SidebarListStyle())
|
||||
.onAppear {
|
||||
sceneModel.sidebarModel = sidebarModel
|
||||
sidebarModel.delegate = sceneModel
|
||||
@@ -30,9 +30,9 @@ struct RegularSidebarContainerView: View {
|
||||
|
||||
}
|
||||
|
||||
struct RegularSidebarContainerView_Previews: PreviewProvider {
|
||||
struct SidebarContainerView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
RegularSidebarContainerView()
|
||||
SidebarContainerView()
|
||||
.environmentObject(SceneModel())
|
||||
}
|
||||
}
|
||||
33
Multiplatform/Shared/Sidebar/SidebarListStyleModifier.swift
Normal file
33
Multiplatform/Shared/Sidebar/SidebarListStyleModifier.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// SidebarListStyleModifier.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 7/6/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct SidebarListStyleModifier: ViewModifier {
|
||||
|
||||
#if os(iOS)
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
#endif
|
||||
|
||||
@ViewBuilder func body(content: Content) -> some View {
|
||||
#if os(macOS)
|
||||
content
|
||||
.listStyle(SidebarListStyle())
|
||||
#else
|
||||
if horizontalSizeClass == .compact {
|
||||
content
|
||||
.listStyle(PlainListStyle())
|
||||
} else {
|
||||
content
|
||||
.listStyle(SidebarListStyle())
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
34
Multiplatform/Shared/Sidebar/SidebarStyleModifier.swift
Normal file
34
Multiplatform/Shared/Sidebar/SidebarStyleModifier.swift
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// SidebarStyleModifier.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 7/6/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct SidebarListStyleModifier: ViewModifier {
|
||||
|
||||
#if os(iOS)
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
#endif
|
||||
|
||||
@ViewBuilder func body(content: Content) -> some View {
|
||||
content
|
||||
#if os(macOS)
|
||||
content
|
||||
.listStyle(SidebarListStyle())
|
||||
#else
|
||||
if horizontalSizeClass == .compact {
|
||||
content
|
||||
.listStyle(PlainListStyle())
|
||||
} else {
|
||||
content
|
||||
.listStyle(SidebarListStyle())
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user