12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- //
- // ViewRouter.swift
- // fiveConstant
- //
- // Created by 李建 on 2023/1/29.
- //
- import Foundation
- import SwiftUI
- enum Page {
- case home
- case room
- case found
- case my
- }
- class ViewRouter: ObservableObject {
- @Published var currentPage: Page = .home
- }
- struct TabBarIcon: View {
-
- @StateObject var viewRouter: ViewRouter
-
- let assignedPage: Page
-
- let width, height: CGFloat
-
- let systemIconName, tabName: String
-
- var body: some View {
- VStack {
- Image(systemName: systemIconName)
- .resizable()
- .aspectRatio(contentMode: .fit)
- .frame(width: width, height: height)
- .padding(.top, 6)
- Text(tabName)
- .font(.footnote)
- .font(.system(size: 16))
- Spacer()
- }
- .padding(.horizontal, -2)
- .onTapGesture {
- viewRouter.currentPage = assignedPage
- }
- .foregroundColor(viewRouter.currentPage == assignedPage ? Color("SecondColor") : .gray)
- }
- }
|