From 7fe780a549f71bb95e4df0a52a1e701c5f8169dd Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 15 May 2024 11:52:54 +0300 Subject: Fix both layouts --- JuickNext/View/ContentView.swift | 69 ++++++++++++++++------------------------ JuickNext/View/FeedView.swift | 18 +++++++---- 2 files changed, 38 insertions(+), 49 deletions(-) (limited to 'JuickNext/View') diff --git a/JuickNext/View/ContentView.swift b/JuickNext/View/ContentView.swift index 3912c59..7f5db89 100644 --- a/JuickNext/View/ContentView.swift +++ b/JuickNext/View/ContentView.swift @@ -11,58 +11,43 @@ import SwiftUI struct ContentView: View { @Environment(\.horizontalSizeClass) private var size - let today = Feed(title: "Today", url: "https://api.juick.com/messages?popular=1") - let discussions = Feed(title: "Discussions", url: "https://api.juick.com/messages/discussions") - let discover = Feed(title: "Discover", url: "https://api.juick.com/messages") + let today = Feed(title: "Today", url: "https://api.juick.com/messages?popular=1", imageName: "ei-clock") + let discussions = Feed(title: "Discussions", url: "https://api.juick.com/messages/discussions", imageName: "ei-bell") + let discover = Feed(title: "Discover", url: "https://api.juick.com/messages", imageName: "Discover") @State private var showFeed : Bool = false @State private var selectedFeed: Feed? = nil + var body: some View { + let tabs = [today, discussions, discover] let view = (size == .compact) ? - AnyView(TabView { - FeedView(today).tabItem { - Image("ei-clock") - } - FeedView(discussions).tabItem { - Image("ei-bell") - } - FeedView(discover).tabItem { - Image("Discover") - } - }): AnyView(NavigationView { - let tabs = [today, discussions, discover] - VStack { - List { - ForEach(tabs, id: \.title) { - tab in - Button(action: { - selectedFeed = tab - showFeed.toggle() - }, label: { - Text(tab.title) - }) + AnyView( + TabView { + ForEach(tabs, id: \.title) { + tab in + FeedView(tab).tabItem { + Image(tab.imageName) } - }.background { - if let feed = selectedFeed { - NavigationLink( - destination: FeedView(feed), - isActive: $showFeed, - label: { - VStack { - Text(feed.title) - } + } + } + ): AnyView( + NavigationView { + VStack { + List { + ForEach(tabs, id: \.title) { + tab in + NavigationLink(destination: FeedView(tab), label: { + HStack { + Image(tab.imageName) + Text(tab.title) + }.padding() }) - } else { - EmptyView() + } } - } - }.toolbar { - ToolbarItem(placement: .principal) { - Text("Juick") - } + }.screenTitle(title: "Juick") } - }) + ) view } } diff --git a/JuickNext/View/FeedView.swift b/JuickNext/View/FeedView.swift index cd0569f..783d8c0 100644 --- a/JuickNext/View/FeedView.swift +++ b/JuickNext/View/FeedView.swift @@ -9,6 +9,7 @@ import SwiftUI struct FeedView: View { + @Environment(\.horizontalSizeClass) private var size @ObservedObject var messageFetcher : MessageFetcher let feed: Feed @@ -38,18 +39,21 @@ struct FeedView: View { } var body: some View { - VStack { + let content = VStack { stateContent - }.toolbar { - ToolbarItem(placement: .principal) { - Text(feed.title) - } - } + }.screenTitle(title: feed.title) + + let view = (size == .compact) ? + AnyView( + NavigationView { + content + }) : AnyView(content) + view } } struct FeedView_Previews: PreviewProvider { static var previews: some View { - FeedView(Feed(title:"Discover", url: "https://api.juick.com/messages")) + FeedView(Feed(title:"Discover", url: "https://api.juick.com/messages", imageName: "Discover")) } } -- cgit v1.2.3