extract MainTabView
Start to clean ContentView up a bit. We need it to be cleaner before we introduce the SetupView Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
81
damus/Views/MainTabView.swift
Normal file
81
damus/Views/MainTabView.swift
Normal file
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// MainTabView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2022-05-19.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MainTabView: View {
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
}
|
||||
|
||||
struct MainTabView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MainTabView()
|
||||
}
|
||||
}
|
||||
|
||||
struct NotificationsTab: View {
|
||||
@Binding var new_notifications: Bool
|
||||
@Binding var selected: Timeline?
|
||||
|
||||
let action: (Timeline) -> ()
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .center) {
|
||||
TabButton(timeline: .notifications, img: "bell", selected: $selected, action: action)
|
||||
|
||||
if new_notifications {
|
||||
Circle()
|
||||
.size(CGSize(width: 8, height: 8))
|
||||
.frame(width: 10, height: 10, alignment: .topTrailing)
|
||||
.alignmentGuide(VerticalAlignment.center) { a in a.height + 2.0 }
|
||||
.alignmentGuide(HorizontalAlignment.center) { a in a.width - 12.0 }
|
||||
.foregroundColor(.accentColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct TabButton: View {
|
||||
let timeline: Timeline
|
||||
let img: String
|
||||
|
||||
@Binding var selected: Timeline?
|
||||
|
||||
let action: (Timeline) -> ()
|
||||
|
||||
var body: some View {
|
||||
Button(action: {action(timeline)}) {
|
||||
Label("", systemImage: selected == timeline ? "\(img).fill" : img)
|
||||
.contentShape(Rectangle())
|
||||
.frame(maxWidth: .infinity, minHeight: 30.0)
|
||||
}
|
||||
.foregroundColor(selected != timeline ? .gray : .primary)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct TabBar: View {
|
||||
@Binding var new_notifications: Bool
|
||||
@Binding var selected: Timeline?
|
||||
|
||||
let action: (Timeline) -> ()
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Divider()
|
||||
HStack {
|
||||
TabButton(timeline: .home, img: "house", selected: $selected, action: action)
|
||||
NotificationsTab(new_notifications: $new_notifications, selected: $selected, action: action)
|
||||
TabButton(timeline: .global, img: "globe.americas", selected: $selected, action: action)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
damus/Views/SetupView.swift
Normal file
20
damus/Views/SetupView.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// SetupView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2022-05-18.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct SetupView: View {
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
}
|
||||
|
||||
struct SetupView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SetupView()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user