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 ++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 42 deletions(-) (limited to 'JuickNext/View/ContentView.swift') 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 } } -- cgit v1.2.3