mirror of
https://github.com/yattee/yattee.git
synced 2026-05-13 10:55:03 +00:00
Add resizable subscriptions sidebar on iPad
This commit is contained in:
@@ -37,6 +37,9 @@ struct SubscriptionsView: View {
|
|||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
@AppStorage("subscriptionsMacOSSidebarWidth") private var macOSSidebarWidth = 240.0
|
@AppStorage("subscriptionsMacOSSidebarWidth") private var macOSSidebarWidth = 240.0
|
||||||
@State private var macOSSidebarDragStartWidth: Double?
|
@State private var macOSSidebarDragStartWidth: Double?
|
||||||
|
#elseif os(iOS)
|
||||||
|
@AppStorage("subscriptionsIPadSidebarWidth") private var iPadSidebarWidth = 260.0
|
||||||
|
@State private var iPadSidebarDragStartWidth: Double?
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// List style from centralized settings.
|
/// List style from centralized settings.
|
||||||
@@ -255,9 +258,9 @@ struct SubscriptionsView: View {
|
|||||||
if isIPadRegular && showSidebar && subscriptionsLoaded && subscriptions.count > 1 {
|
if isIPadRegular && showSidebar && subscriptionsLoaded && subscriptions.count > 1 {
|
||||||
HStack(spacing: 0) {
|
HStack(spacing: 0) {
|
||||||
iOSChannelsSidebar
|
iOSChannelsSidebar
|
||||||
.frame(width: 260)
|
.frame(width: clampedIPadSidebarWidth)
|
||||||
|
|
||||||
Divider()
|
iPadSidebarResizeHandle
|
||||||
|
|
||||||
feedLayout
|
feedLayout
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
@@ -904,10 +907,17 @@ struct SubscriptionsView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
|
private static let iPadSidebarMinWidth = 220.0
|
||||||
|
private static let iPadSidebarMaxWidth = 420.0
|
||||||
|
|
||||||
private var isIPadRegular: Bool {
|
private var isIPadRegular: Bool {
|
||||||
UIDevice.current.userInterfaceIdiom == .pad && horizontalSizeClass == .regular
|
UIDevice.current.userInterfaceIdiom == .pad && horizontalSizeClass == .regular
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var clampedIPadSidebarWidth: CGFloat {
|
||||||
|
CGFloat(min(max(iPadSidebarWidth, Self.iPadSidebarMinWidth), Self.iPadSidebarMaxWidth))
|
||||||
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var feedLayout: some View {
|
private var feedLayout: some View {
|
||||||
Group {
|
Group {
|
||||||
@@ -979,6 +989,35 @@ struct SubscriptionsView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private var iPadSidebarResizeHandle: some View {
|
||||||
|
if isIPadRegular {
|
||||||
|
Rectangle()
|
||||||
|
.fill(.separator.opacity(0.7))
|
||||||
|
.frame(width: 1)
|
||||||
|
.frame(width: 14)
|
||||||
|
.frame(maxHeight: .infinity)
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.highPriorityGesture(iPadSidebarResizeGesture)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var iPadSidebarResizeGesture: some Gesture {
|
||||||
|
DragGesture(minimumDistance: 0, coordinateSpace: .global)
|
||||||
|
.onChanged { value in
|
||||||
|
if iPadSidebarDragStartWidth == nil {
|
||||||
|
iPadSidebarDragStartWidth = iPadSidebarWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
let baseWidth = iPadSidebarDragStartWidth ?? iPadSidebarWidth
|
||||||
|
let newWidth = baseWidth + value.translation.width
|
||||||
|
iPadSidebarWidth = min(max(newWidth, Self.iPadSidebarMinWidth), Self.iPadSidebarMaxWidth)
|
||||||
|
}
|
||||||
|
.onEnded { _ in
|
||||||
|
iPadSidebarDragStartWidth = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private func iOSSidebarRow(
|
private func iOSSidebarRow(
|
||||||
name: String,
|
name: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user