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.
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
}
}