Make secondary column available on any size + add a toggle + faster macOS window resize

This commit is contained in:
Thomas Ricouard 2023-02-21 13:37:31 +01:00
parent 5d3b378373
commit 7a997ebd8a
11 changed files with 80 additions and 23 deletions

View file

@ -133,8 +133,7 @@ struct IceCubesApp: App {
} }
} }
} }
if proxy.frame(in: .global).width > (.maxColumnWidth + .secondaryColumnWidth), if appAccountsManager.currentClient.isAuth,
appAccountsManager.currentClient.isAuth,
userPreferences.showiPadSecondaryColumn userPreferences.showiPadSecondaryColumn
{ {
Divider().edgesIgnoringSafeArea(.all) Divider().edgesIgnoringSafeArea(.all)

View file

@ -29,6 +29,9 @@ struct ExploreTab: View {
AppAccountsSelectorView(routerPath: routerPath) AppAccountsSelectorView(routerPath: routerPath)
} }
} }
if UIDevice.current.userInterfaceIdiom == .pad && !preferences.showiPadSecondaryColumn {
SecondaryColumnToolbarItem()
}
} }
} }
.withSafariRouter() .withSafariRouter()

View file

@ -38,6 +38,11 @@ struct NotificationsTab: View {
} }
} }
} }
if UIDevice.current.userInterfaceIdiom == .pad {
if (!isSecondaryColumn && !userPreferences.showiPadSecondaryColumn) || isSecondaryColumn {
SecondaryColumnToolbarItem()
}
}
} }
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar) .toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar)
.id(client.id) .id(client.id)

View file

@ -46,6 +46,9 @@ struct SettingsTabs: View {
} }
} }
} }
if UIDevice.current.userInterfaceIdiom == .pad && !preferences.showiPadSecondaryColumn {
SecondaryColumnToolbarItem()
}
} }
.withAppRouter() .withAppRouter()
.withSheetDestinations(sheetDestinations: $routerPath.presentedSheet) .withSheetDestinations(sheetDestinations: $routerPath.presentedSheet)

View file

@ -178,6 +178,9 @@ struct TimelineTab: View {
} }
statusEditorToolbarItem(routerPath: routerPath, statusEditorToolbarItem(routerPath: routerPath,
visibility: preferences.postVisibility) visibility: preferences.postVisibility)
if UIDevice.current.userInterfaceIdiom == .pad && !preferences.showiPadSecondaryColumn {
SecondaryColumnToolbarItem()
}
} else { } else {
ToolbarItem(placement: .navigationBarTrailing) { ToolbarItem(placement: .navigationBarTrailing) {
addAccountButton addAccountButton

View file

@ -124,22 +124,38 @@ struct ConversationMessageView: View {
} }
} }
private func makeImageRequest(for url: URL, size: CGSize) -> ImageRequest {
ImageRequest(url: url, processors: [.resize(size: size)])
}
private func mediaWidth(proxy: GeometryProxy) -> CGFloat {
var width = proxy.frame(in: .local).width
if UIDevice.current.userInterfaceIdiom == .pad {
width = width * 0.60
}
return width
}
private func makeMediaView(_ attachement: MediaAttachment) -> some View { private func makeMediaView(_ attachement: MediaAttachment) -> some View {
GeometryReader { proxy in GeometryReader { proxy in
LazyImage(url: attachement.url) { state in let width = mediaWidth(proxy: proxy)
if let image = state.image { if let url = attachement.url {
image LazyImage(request: makeImageRequest(for: url,
.resizable() size: .init(width: width, height: 200))) { state in
.aspectRatio(contentMode: .fill) if let image = state.image {
.frame(height: 200) image
.frame(maxWidth: proxy.frame(in: .local).width) .resizable()
.clipped() .aspectRatio(contentMode: .fill)
.cornerRadius(8) .frame(height: 200)
.padding(8) .frame(maxWidth: width)
} else if state.isLoading { .clipped()
RoundedRectangle(cornerRadius: 8) .cornerRadius(8)
.fill(Color.gray) .padding(8)
.frame(height: 200) } else if state.isLoading {
RoundedRectangle(cornerRadius: 8)
.fill(Color.gray)
.frame(height: 200)
}
} }
} }
} }

View file

@ -6,6 +6,7 @@ import Shimmer
import SwiftUI import SwiftUI
public struct ConversationsListView: View { public struct ConversationsListView: View {
@EnvironmentObject private var preferences: UserPreferences
@EnvironmentObject private var routerPath: RouterPath @EnvironmentObject private var routerPath: RouterPath
@EnvironmentObject private var watcher: StreamWatcher @EnvironmentObject private var watcher: StreamWatcher
@EnvironmentObject private var client: Client @EnvironmentObject private var client: Client
@ -76,6 +77,9 @@ public struct ConversationsListView: View {
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.toolbar { .toolbar {
StatusEditorToolbarItem(visibility: .direct) StatusEditorToolbarItem(visibility: .direct)
if UIDevice.current.userInterfaceIdiom == .pad && !preferences.showiPadSecondaryColumn {
SecondaryColumnToolbarItem()
}
} }
.onChange(of: watcher.latestEvent?.id) { _ in .onChange(of: watcher.latestEvent?.id) { _ in
if let latestEvent = watcher.latestEvent { if let latestEvent = watcher.latestEvent {

View file

@ -4,8 +4,7 @@ public extension CGFloat {
static var layoutPadding: CGFloat = 20 static var layoutPadding: CGFloat = 20
static let dividerPadding: CGFloat = 2 static let dividerPadding: CGFloat = 2
static let statusColumnsSpacing: CGFloat = 8 static let statusColumnsSpacing: CGFloat = 8
static let maxColumnWidth: CGFloat = 650 static let secondaryColumnWidth: CGFloat = 400
static let secondaryColumnWidth: CGFloat = 360
static let sidebarWidth: CGFloat = 80 static let sidebarWidth: CGFloat = 80
static let pollBarHeight: CGFloat = 30 static let pollBarHeight: CGFloat = 30
} }

View file

@ -36,3 +36,22 @@ public struct StatusEditorToolbarItem: ToolbarContent {
} }
} }
} }
public struct SecondaryColumnToolbarItem: ToolbarContent {
@Environment(\.isSecondaryColumn) private var isSecondaryColumn
@EnvironmentObject private var preferences: UserPreferences
public init() {}
public var body: some ToolbarContent {
ToolbarItem(placement: isSecondaryColumn ? .navigationBarLeading : .navigationBarTrailing) {
Button {
withAnimation {
preferences.showiPadSecondaryColumn.toggle()
}
} label: {
Image(systemName: "sidebar.right")
}
}
}
}

View file

@ -67,7 +67,6 @@ public struct StatusRowCardView: View {
RoundedRectangle(cornerRadius: 16) RoundedRectangle(cornerRadius: 16)
.stroke(.gray.opacity(0.35), lineWidth: 1) .stroke(.gray.opacity(0.35), lineWidth: 1)
) )
.frame(maxWidth: .maxColumnWidth)
.onTapGesture { .onTapGesture {
openURL(url) openURL(url)
} }

View file

@ -27,8 +27,9 @@ public struct StatusRowMediaPreviewView: View {
@State private var isHidingMedia: Bool = false @State private var isHidingMedia: Bool = false
var availableWidth: CGFloat { var availableWidth: CGFloat {
if sceneDelegate.windowWidth > .maxColumnWidth { if UIDevice.current.userInterfaceIdiom == .phone &&
return .maxColumnWidth (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) {
return sceneDelegate.windowWidth * 0.80
} }
return sceneDelegate.windowWidth return sceneDelegate.windowWidth
} }
@ -36,10 +37,16 @@ public struct StatusRowMediaPreviewView: View {
var appLayoutWidth: CGFloat { var appLayoutWidth: CGFloat {
let avatarColumnWidth = theme.avatarPosition == .leading ? AvatarView.Size.status.size.width + .statusColumnsSpacing : 0 let avatarColumnWidth = theme.avatarPosition == .leading ? AvatarView.Size.status.size.width + .statusColumnsSpacing : 0
var sidebarWidth: CGFloat = 0 var sidebarWidth: CGFloat = 0
if UIDevice.current.userInterfaceIdiom == .pad && sceneDelegate.windowWidth < (.maxColumnWidth + .sidebarWidth) { var secondaryColumnWidth: CGFloat = 0
var layoutPading: CGFloat = .layoutPadding * 2
if UIDevice.current.userInterfaceIdiom == .pad {
sidebarWidth = .sidebarWidth sidebarWidth = .sidebarWidth
if preferences.showiPadSecondaryColumn {
secondaryColumnWidth = .secondaryColumnWidth
layoutPading = 0
}
} }
return (.layoutPadding * 2) + avatarColumnWidth + sidebarWidth + extraLeadingInset return layoutPading + avatarColumnWidth + sidebarWidth + extraLeadingInset + secondaryColumnWidth
} }
private var imageMaxHeight: CGFloat { private var imageMaxHeight: CGFloat {