0

I am new to SwiftUI (and Swift for that matter) and this may be a simple question but I have not been able to find the solution. I have a list in a struct which is viewable underneath the TabView. How do I stop this. I imagine it's some setting on the underlying views being presented when tabitems are pressed, but I can't find what it is.

enter image description here

UPDATE

I put this in and it didn't seem to work. The code ran but the background is still transparent.

    if #available(iOS 15, *) {
        print("appearance navigation bar")
        let appearance = UINavigationBarAppearance()
        appearance.configureWithOpaqueBackground()
        UINavigationBar.appearance().standardAppearance = appearance
        UINavigationBar.appearance().scrollEdgeAppearance = appearance
    }

Here is the code for the list, I didn't include the API call but it returns an array of case:

struct CaseListView: View {

@State private var caseList: [Case] = []
@EnvironmentObject var sessionInfo: SessionInfo
@Environment(\.msalApplication) private var msalApplication
@State private var isFirst: Bool = true


var body: some View {
    
    NavigationView() {
        VStack {
            
            GroupBox(content: {
                Text("Something 1")
                Text("Something 2")
            }) {
                Text("Update")
            }

        
            List(caseList.indices, id: \.self) {index in
            
            VStack(alignment: .leading, spacing: 5) {
                
                Image(systemName: "ellipsis")
                    .frame(maxWidth: .infinity, alignment: .trailing)
                    .foregroundColor(.secondary)
                    .padding(10)
                    .onTapGesture {
                        self.toggleExpanded(caseList[index])
                    }
                NavigationLink(destination: CaseView(caseItem: caseList[index]), label: {

                    
                    CaseExpandableView(isExpanded: index == 0 ? true : false, caseItem: caseList[index])

                })
            
            }
            .listRowInsets(EdgeInsets(top: 8, leading: 0, bottom: 8, trailing: 0))
            .background(Color.white)
            .clipShape(RoundedRectangle(cornerRadius: 10))
            .listRowSeparatorTint(Color(UIColor.systemGray6), edges: .all)
            .listRowSeparator(.visible)
            .listRowBackground(Color(UIColor.systemGray6))
            .frame(
                maxWidth: .infinity,
                minHeight: 0,
                maxHeight: .infinity,
                alignment: .topLeading
            )
        } //list
        .listStyle(InsetGroupedListStyle())
            
            
        }   //first hstack
    }
    .onAppear() {
        loadCases()
    }
    .navigationTitle("Cases")
}

And here's the detail view:

import SwiftUI

struct CaseExpandableView: View {

let isExpanded: Bool
let caseItem: Case

var body: some View {
    
    HStack {
        
        Image(systemName: "folder.fill.badge.person.crop")
            .foregroundColor(.accentColor)
            .padding(5)
        
        VStack(alignment: .leading, spacing: 5) {
            
            Text(caseItem.alias)
            Text("# team members")
                .font(.subheadline)
                .foregroundColor(.secondary)
            
            
            
            if isExpanded {
                VStack(alignment: .leading) {
                    Text("Line1")
                    Text("Line2")
                    Text("Line3")
                    Text("Line4")
                }
            }
        }
        .padding(5)
        

        
        Spacer()

        let badgeCount = Int.random(in: 0..<5)
        if badgeCount>0 {

        ZStack {
            Circle()
                .foregroundColor(.red)
                .frame(width: 25, height: 25) // here!
                Text(String(badgeCount))
                    .foregroundColor(.white)
                    .font(Font.system(size: 12))
            }
        }

        
    } //hstack
}

}

lcj
  • 1,355
  • 16
  • 37
  • 1
    Could you possibly edit your question to include the code for your tab view (and, ideally, the list view as well)? That'd help diagnose your issue. Thanks – ScottM Jun 23 '22 at 12:46
  • Does this answer your question https://stackoverflow.com/questions/69563463/ios-15-navigation-bar-transparency-problem-with-tabview? – Timmy Jun 23 '22 at 12:47
  • Please include pieces of code so we can help you solve this issue – Dev Doshi Jun 24 '22 at 19:07
  • Seems to be working now. @NoeOnJupiter, if you want to put your response as an answer I will mark it as such. – lcj Jun 25 '22 at 14:21

0 Answers0