blob: 3912c59c73e0a037ad79ac3431df2514b357d3b7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
//
// ContentView.swift
// Juick
//
// Created by Vitaly Takmazov on 14.05.2023.
// Copyright © 2023 com.juick. All rights reserved.
//
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")
@State private var showFeed : Bool = false
@State private var selectedFeed: Feed? = nil
var body: some View {
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)
})
}
}.background {
if let feed = selectedFeed {
NavigationLink(
destination: FeedView(feed),
isActive: $showFeed,
label: {
VStack {
Text(feed.title)
}
})
} else {
EmptyView()
}
}
}.toolbar {
ToolbarItem(placement: .principal) {
Text("Juick")
}
}
})
view
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
ContentView()
}
}
}
|