Making a filter for AudioApp


What I attempt to obtain is that whenever you click on on some class instance on "Anxiousness reduction" I wish to present solely that songs/sounds which have style of "anxiousness" in Firebase, I attempted to make some @State variable and on tapgesture to vary that will depend on what’s clicked, however that merely does not work.

Right here is my code of SongsListView:

struct SongListView: View {
    @ObservedObject var soundVM = SoundViewModel()
    @State non-public var isFullScreen:Bool = false
    
    @EnvironmentObject var audioManager: AudioManager
    @Setting(.dismiss) var dismiss
    
    var audio: Sound
    
   
    // I added this to look at the style of SleepEasyView
    var genreBigCard = SleepEasyView().style
    
    var physique: some View {
        
        NavigationView{
            VStack{
                
                HStack{
                    Button{
                        audioManager.cease()
                        dismiss()
                    } label: {
                        Picture(systemName: "xmark.circle.fill")
                            .font(.system(measurement:36))
                            .foregroundColor(.white)
                    }
                    Spacer()
                    
                }.padding(20)
                ScrollView{
                    VStack(spacing:20){
                        ForEach(soundVM.sound) { sound in
                            // And add this to verify if the sounds style is equal
                            if genreBigCard == sound.style{
                          
                                NavigationLink{
                                    PlayerView(audio: sound).navigationBarBackButtonHidden(true)
                                } label: {
                                    VStack{
                                        HStack(){
                                            Picture("(sound.picture)")
                                                .resizable()
                                                .body(maxWidth:70, maxHeight:70)
                                            
                                            VStack(alignment:.main){
                                                Textual content(sound.title)
                                                    .fontWeight(.daring)
                                                Textual content(sound.creator)
                                                    .font(.system(measurement:9))
                                                    .fontWeight(.mild)
                                            }
                                            
                                            Spacer()
                                            
                                            Textual content("(sound.length)")
                                                .font(.system(measurement:12))
                                                .fontWeight(.mild)
                                                .padding(15)
                                        } .body(maxWidth:.infinity, alignment: .main)
                                            .onTapGesture(carry out: {
                                                isFullScreen.toggle()
                                            })
                                    }
                                    
                                    .body(maxWidth:340, maxHeight: 70)
                                    .background(.white)
                                    .cornerRadius(15)
                                    .shadow(coloration: Colour.black.opacity(0.33), radius: 5, x: 7, y: 7)
                                }.ignoresSafeArea()
                            }
                        }
                    }.body(maxWidth:.infinity, maxHeight:.infinity)
                }
                .foregroundColor(.black)
            }.onAppear {
                self.soundVM.fetchData()
            }
            .background(Colour("backgroundDark"))
            .navigationBarTitle("")
            .navigationBarHidden(true)
            .navigationBarBackButtonHidden(true)
        }
        
    }
}
struct SongListView_Previews: PreviewProvider {
    static var previews: some View {
        SongListView(audio: Sound.testData)
        
            .environmentObject(AudioManager())
        
    }
}

Code of SleepEasyView:

import SwiftUI


struct SleepEasyView: View {
    // Right here I add state var for style
    @State var style = "affirmations"

    @State var isCardActive = false
    var physique: some View {
        NavigationView{
            
            
            NavigationLink{ SongListView(audio: Sound.testData)
                            .navigationBarBackButtonHidden(true)
                            .navigationBarTitle("")
                .navigationBarHidden(true)
            
                
            } label:{
                
                
                BigCardView(title: "Anxiousness reduction", audioInfo: "7 audio recordsdata", picture: "evening", horizontalLines: 7, style:self.style) // Right here I cross state variable in parameter style
                    .onTapGesture {
                      //Within the line under I attempt to change the worth of style.
                        style = "anxiousness"
                        print(style)
                        
                        isCardActive.toggle()
                    }
                
            }
            
            
        }
        
    }
}

struct SleepEasyView_Previews: PreviewProvider {
    
    static var previews: some View {
        SleepEasyView()
    }
}

Right here is my BigCardView:

struct BigCardView: View {
    var title: String
    var audioInfo: String
    var picture: String
    var horizontalLines: Int
    var style: String
    
    var physique: some View {
        VStack{
            ZStack{
                VStack{
                    Picture(self.picture)
                        .resizable()
                        .scaledToFill()
                        .body(width: 340, top: 100)
                        .clipped()
                }
                
                .body(width: 340, top: 100)
                .cornerRadius(20)
                
                Rectangle()
                    .body(width: 340, top: 100)
                    .opacity(0.2)
                    .cornerRadius(20)
                
                VStack(alignment: .main, spacing: 5){
                    Textual content(self.title)
                        .font(.system(measurement:26))
                    Textual content(self.audioInfo)
                        .foregroundColor(.black)
                        .padding(.horizontal, 5)
                        .background(.white)
                        .cornerRadius(5)
                        .padding(.backside, 5)
                    
                    HStack(spacing:5){
                        ForEach(0..<self.horizontalLines){ _ in
                            Rectangle()
                                .body(width: 20, top: 3)
                                .background(.white)
                        }
                    }
                    
                }
                .foregroundColor(.white)
                .padding(.backside, 5)
                
                .padding(20)
                .body(maxWidth:340, alignment:.topLeading)
                
            }
            
        }
    }
}

struct BigCardView_Previews: PreviewProvider {
    static var previews: some View {
        BigCardView(title: "Anxiousness reduction", audioInfo: "7 audio recordsdata", picture: "evening", horizontalLines: 7, style:"affirmations")
    }
}

Leave a Reply