mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
update split view controller behavior for ipad
This commit is contained in:
parent
2f0158de8d
commit
8003e0af23
3 changed files with 50 additions and 42 deletions
|
|
@ -289,7 +289,8 @@ import Views
|
|||
|
||||
@ObservedObject var viewModel: HomeFeedViewModel
|
||||
|
||||
private let columns = Array(repeating: GridItem(.flexible(), spacing: 20), count: 2)
|
||||
private let twoColumns = Array(repeating: GridItem(.flexible(), spacing: 20), count: 2)
|
||||
private let oneColumn = [GridItem(.flexible(), spacing: 20)]
|
||||
|
||||
func contextMenuActionHandler(item: FeedItem, action: GridCardAction) {
|
||||
switch action {
|
||||
|
|
@ -303,51 +304,53 @@ import Views
|
|||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
LazyVGrid(columns: columns, spacing: 20) {
|
||||
ForEach(viewModel.items, id: \.renderID) { item in
|
||||
let link = GridCardNavigationLink(
|
||||
item: item,
|
||||
searchQuery: searchQuery,
|
||||
actionHandler: { contextMenuActionHandler(item: item, action: $0) },
|
||||
selectedLinkItem: $selectedLinkItem,
|
||||
isContextMenuOpen: $isContextMenuOpen,
|
||||
viewModel: viewModel
|
||||
)
|
||||
if #available(iOS 15.0, *) {
|
||||
link
|
||||
.alert("Are you sure?", isPresented: $confirmationShown) {
|
||||
Button("Remove Link", role: .destructive) {
|
||||
if let itemToRemove = itemToRemove {
|
||||
withAnimation {
|
||||
viewModel.removeLink(dataService: dataService, linkId: itemToRemove.id)
|
||||
GeometryReader { geo in
|
||||
LazyVGrid(columns: geo.size.width < 500 ? oneColumn : twoColumns, spacing: 20) {
|
||||
ForEach(viewModel.items, id: \.renderID) { item in
|
||||
let link = GridCardNavigationLink(
|
||||
item: item,
|
||||
searchQuery: searchQuery,
|
||||
actionHandler: { contextMenuActionHandler(item: item, action: $0) },
|
||||
selectedLinkItem: $selectedLinkItem,
|
||||
isContextMenuOpen: $isContextMenuOpen,
|
||||
viewModel: viewModel
|
||||
)
|
||||
if #available(iOS 15.0, *) {
|
||||
link
|
||||
.alert("Are you sure?", isPresented: $confirmationShown) {
|
||||
Button("Remove Link", role: .destructive) {
|
||||
if let itemToRemove = itemToRemove {
|
||||
withAnimation {
|
||||
viewModel.removeLink(dataService: dataService, linkId: itemToRemove.id)
|
||||
}
|
||||
}
|
||||
self.itemToRemove = nil
|
||||
}
|
||||
self.itemToRemove = nil
|
||||
Button("Cancel", role: .cancel) { self.itemToRemove = nil }
|
||||
}
|
||||
Button("Cancel", role: .cancel) { self.itemToRemove = nil }
|
||||
}
|
||||
} else {
|
||||
link
|
||||
} else {
|
||||
link
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.background(
|
||||
GeometryReader {
|
||||
Color(.systemGroupedBackground).preference(
|
||||
key: ScrollViewOffsetPreferenceKey.self,
|
||||
value: $0.frame(in: .global).origin.y
|
||||
)
|
||||
.padding()
|
||||
.background(
|
||||
GeometryReader {
|
||||
Color(.systemGroupedBackground).preference(
|
||||
key: ScrollViewOffsetPreferenceKey.self,
|
||||
value: $0.frame(in: .global).origin.y
|
||||
)
|
||||
}
|
||||
)
|
||||
.onPreferenceChange(ScrollViewOffsetPreferenceKey.self) { offset in
|
||||
if !viewModel.isLoading, offset > 240 {
|
||||
viewModel.loadItems(dataService: dataService, searchQuery: searchQuery, isRefresh: true)
|
||||
}
|
||||
}
|
||||
)
|
||||
.onPreferenceChange(ScrollViewOffsetPreferenceKey.self) { offset in
|
||||
if !viewModel.isLoading, offset > 240 {
|
||||
viewModel.loadItems(dataService: dataService, searchQuery: searchQuery, isRefresh: true)
|
||||
}
|
||||
}
|
||||
|
||||
if viewModel.items.isEmpty, viewModel.isLoading {
|
||||
LoadingSection()
|
||||
if viewModel.items.isEmpty, viewModel.isLoading {
|
||||
LoadingSection()
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ struct HomeView: View {
|
|||
}
|
||||
.accentColor(.appGrayTextContrast)
|
||||
} else {
|
||||
GeometryReader { geo in
|
||||
HomeFeedContainerView(isCompact: geo.size.width < 500, viewModel: viewModel)
|
||||
GeometryReader { _ in
|
||||
HomeFeedContainerView(isCompact: UIDevice.isIPhone, viewModel: viewModel)
|
||||
}
|
||||
}
|
||||
#elseif os(macOS)
|
||||
|
|
|
|||
|
|
@ -43,12 +43,17 @@ public struct PrimaryContentView: View {
|
|||
NavigationView {
|
||||
// The first column is the sidebar.
|
||||
PrimaryContentSidebar(categories: categories)
|
||||
.navigationTitle("Categories")
|
||||
.navigationTitle("")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
|
||||
// Second column is the Primary Nav Stack
|
||||
PrimaryContentCategory.feed.destinationView
|
||||
}
|
||||
.accentColor(.appGrayTextContrast)
|
||||
.introspectSplitViewController {
|
||||
$0.preferredSplitBehavior = .tile
|
||||
$0.preferredPrimaryColumnWidth = 200
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue