0

Given code is for custom bottom tab-bar with plus button in center by using we need to hide and show one detail view and from last tab we are just opens menu from bottom sheet.

Problem :- When we are hide and show a detail view using center button that refresh the ui and redirect us on root from any subview. while we are using bottom sheet that works fine for us. When we are open bottom sheet in subview that is start view from top of tabbar.

Problem Video

import SwiftUI

struct DashboardTBV: View {
    @StateObject var manager = CalendarManager()
    @StateObject var viewRouter: ViewRouter = ViewRouter()
    @State var showTimerDetail : Bool = false
    @State var showToast : Bool = false
    @State var toastMsg : String = ""
    let layout = [
        GridItem(.flexible())
    ]
    
    @State var showWorkOrderList : Bool = false
    @State var month : String = ""
    @State var year : String = ""
    @State var filterDate : String = ""
    
    @State var spacing: CGFloat = 20
    @State var headspace: CGFloat = 15
    @State var sidesScaling: CGFloat = 0.8
    @State var isWrap: Bool = false
    @State var autoScroll: Bool = false
    @State var time: TimeInterval = 1
    @State var currentIndex: Int = 0
    @State var isLoading : Bool = true
    @State var popToRoot : Bool = false
    @State var showSheet : Bool = false
    @State var showProfile : Bool = false
    
    var body: some View {
        GeometryReader { geometry in
            VStack(spacing: 0) {
                Spacer()
                ZStack(alignment: .bottom) {
                    VStack {
                        
                    }
                    .frame(width: geometry.size.width, height: geometry.size.height)
                    .background(Constant.AppColors.dark_background.opacity((showTimerDetail) ? 0.3 : 0))
                    .zIndex(5)
                    .onTapGesture {
                        withAnimation {
                            self.showTimerDetail = false
                        }
                    }
                    VStack(spacing:0) {
                        switch viewRouter.currentPage {
                        case .home:
                            VStack {
                                Spacer()
                                Text("Home")
                                Spacer()
                            }
                        case .setting:
                            VStack {
                                Spacer()
                                Text("Liked")
                                Spacer()
                            }
                        case .notification:
                            VStack {
                                Spacer()
                                Text("Records")
                                Spacer()
                            }
                        case .profile:
                            Text("")
                            Spacer()
                        }
                        HStack {
                            DashboardTabBarIcon(viewRouter: viewRouter, assignedPage: .home, width: geometry.size.width/5, height: geometry.size.height/28, systemIconName: "home", tabName: "")
                            DashboardTabBarIcon(viewRouter: viewRouter, assignedPage: .setting, width: geometry.size.width/5, height: geometry.size.height/28, systemIconName: "Time-Circle", tabName: "")
                            ZStack {
                                
                            }
                            .frame(width: geometry.size.width/8, height: geometry.size.width/8)
                            .clipShape(Circle())
                            .offset(y: -55)
                            .onTapGesture {
                                withAnimation {
                                    showTimerDetail.toggle()
                                }
                            }
                            DashboardTabBarIcon(viewRouter: viewRouter, assignedPage: .notification, width: geometry.size.width/5, height: geometry.size.height/28, systemIconName: "Chat", tabName: "")
                            DashboardTabBarIcon(viewRouter: viewRouter, assignedPage: .profile, width: geometry.size.width/5, height: geometry.size.height/28, systemIconName: "Category", tabName: "xyz") {
                                self.showSheet = true
                            }
                        }
                        .frame(width: geometry.size.width, height: 110)
                        .riseShadow()
                        .zIndex(10)
                    }
                    
                    if showTimerDetail {
                        VStack {
                            HStack {
                                Spacer()
                                Text("Time Clock")
                                    .foregroundColor(Constant.AppColors.iPoint_orange)
                                    .font(.custom(Constant.Font.Biotif_Medium, size: 20))
                                Spacer()
                            }.padding()
                            Divider()
                                .background(Constant.AppColors.white)
                                .frame(height: 0.6)
                            HStack {
                                Spacer()
                                Text("Clocked In at: 8/25/2022 9:41:52 AM")
                                    .foregroundColor(Constant.AppColors.white)
                                    .font(.custom(Constant.Font.Biotif_Regular, size: 16))
                                Spacer()
                            }.padding()
                            
                            Button {
                                withAnimation {
                                    
                                }
                            } label: {
                                HStack {
                                    Text("Clock Out")
                                        .font(.custom(Constant.Font.Biotif_SemiBold, size: 16))
                                        .foregroundColor(Constant.AppColors.dark_background)
                                }
                                .frame(maxWidth: .infinity)
                                .frame(height: 50)
                            }
                            .frame(maxWidth: .infinity)
                            .background(Constant.AppColors.white)
                            .cornerRadius(20)
                            .padding()
                        }
                        .padding(.bottom, 30)
                        .background(Constant.AppColors.dark_background)
                        .cornerRadius(12)
                        .padding([.leading, .trailing])
                        .padding(.bottom, 110)
                        .transition(AnyTransition.opacity.animation(.easeInOut(duration: 0.3)))
                        .zIndex(6)
                        
                    }
                    ZStack {
                        Image(systemName: "plus")
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: geometry.size.width/15, height: geometry.size.width/15)
                            .foregroundColor( self.showTimerDetail ? Constant.AppColors.iPoint_orange : Constant.AppColors.white)
                            .rotationEffect(.degrees(self.showTimerDetail ? 180.0 : 0.0))
                    }
                    .frame(width: geometry.size.width/8, height: geometry.size.width/8)
                    .background(Constant.AppColors.dark_background)
                    .clipShape(Circle())
                    .offset(y: -85)
                    .onTapGesture {
                        withAnimation {
                            showTimerDetail.toggle()
                        }
                    }
                    .zIndex(100)
                }
                PushView(destination: ProfileView().edgesIgnoringSafeArea(.all), destinationId: "ProfileView", isActive: $showProfile) {
                    Text("")
                        .frame(width: 0, height: 0)
                }
            }
            .modifier(MenuBottomSheet(showClose: false , isVisible: $showSheet))
        }
    }
}


struct DashboardTabBarIcon: View {
    
    @StateObject var viewRouter: ViewRouter
    let assignedPage: Page
    let width, height: CGFloat
    let systemIconName, tabName: String
    var tapAction : (()->())?
    
    var body: some View {
        VStack {
            Image(systemIconName)
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: width, height: height)
                .padding(.top, 30)
            Spacer()
        }
        .padding(.horizontal, -4)
        .onTapGesture {
            if tabName == "" {
                viewRouter.currentPage = assignedPage
            } else {
                tapAction?()
            }
        }
        .foregroundColor(viewRouter.currentPage == assignedPage ? .selectedTabBarIconColor : .unSelectedTabBarIconColor)
    }
}

  • You put tapgesture showDetails twice ? Also , in your case tap’ame parameter is not very use full : testing if tapAction is nil or not will do the job. – Ptit Xav Oct 18 '22 at 07:53
  • I removed that unused tap action from tabbar but nothing changed in behaviour. @PtitXav – Sarvesh Yadav Oct 18 '22 at 08:20

0 Answers0