Learn Courses My Dashboard

Background stays white

Hey gang,

I just can’t figure out how to change the background of that view. It’s white, but I’d like to change it to some other color.

Here’s the code from the view :

import SwiftUI


struct SearchView: View {
    
    @ObservedObject var vm = SerieSearchVM()
    @EnvironmentObject var config:ConfigVM
    @State var searchText:String = ""
    let layout = [
        GridItem(.adaptive(minimum: 110, maximum: 110))
    ]

    
    var body: some View {
        
        ZStack {
            VStack {
                Color.darkRed.ignoresSafeArea()
            }
            NavigationStack {
                ScrollView {
                    LazyVGrid(columns: layout) {
                        ForEach (vm.results, id:\.self) {result in
                            NavigationLink {
                                SerieView(serieId: result.id ?? 0)
                            } label: {
                                ContentMiniCard(imageURL: config.getImagePath(result.poster_path ?? "", "poster", "w342"),
                                                title: result.name ?? "",
                                                year: config.getYearFromDate(result.first_air_date ?? ""))

                            }
                        }
                    }
                    .navigationTitle("Recherche")
                    .searchable(text: $searchText)
                    .onChange(of: searchText) { value in
                        vm.searchText = searchText
                        if (!value.isEmpty && value.count > 2) {
                            Task {
                                await vm.searchSeries()
                            }
                        }
                        else {
                            vm.results = [SerieSearchResult]()
                        }
                    }
                } // ScrollView
            } // NavigationStack

        } // ZStack
        
        
    }
}

I have other views where it works just fine :

For this one, I had to use .scrollContentBackground(.hidden) but it doesn’t have the same effect in my problematic view.

import SwiftUI

struct BonjourView: View {
    var body: some View {
        ZStack {
            Color.darkRed
            List {
                Section {
                    Text("Item 1")
                }
                Section {
                    Text("Item 2")
                    Text("Item 3")
                    Text("Item 4")
                }
                Section {
                    Text("Item 5")
                    Text("Item 6")
                    Text("Item 7")
                }
            } // List
            .scrollContentBackground(.hidden)

        } // ZStack
    }
}

This one worked just fine.

import SwiftUI

struct ColorView: View {
    
    var body: some View {
        ZStack {
            HStack(spacing: 0) {
                Color.spotifyBlack
                Color.darkRed
                Color.neutralRed
                Color.darkBlue
                Color.flashyRed
                Color.purpleGray
                Color.roseVale
                Color.greenSheen
            }
            Text("Couleurs du thème")
                .font(.system(size: 80, weight: .black, design: .serif))
                .foregroundColor(.white)
                .multilineTextAlignment(.center)

        }
    }
}

Here’s the TabBarView code if that helps :

struct TabBarView: View {
    
    var body: some View {
        
        TabView {
            BonjourView()
                .tabItem {
                    Label("Home", systemImage: "house")
                }
                .badge(4)
            ColorView()
                .tabItem {
                    Label("Calendar", systemImage: "calendar.badge.clock")
                }
                .badge(4)
            SearchView()
                .tabItem {
                    Label("Search", systemImage: "magnifyingglass")
                }
                .badge(4)
            SerieView(serieId: 90669)
                .tabItem {
                    Label("Settings", systemImage: "gear")
                }
                .badge("NEW")
        } // TabView
        
    } // body
    
}

Thanks for your time!