Slider does not seems slide on tabview in SwiftUI

Omid

How I can make sliders starts normally slide? Right now they locked down.

I think the problem is because of Binding of View which Slider are inside, however those Binding have nothing to do with Sliders and those Sliders have own value for work as State! But I do not know why it makes issue. I tried slider in a tabview without binding to view it work, but not with binding.

my code:

    import SwiftUI

struct ContentView: View {
    
    @State var currentPage: Int = 1
    @State var animationIsEnable    : Bool = true
    @State var shadowIsEnable       : Bool = true

    var body: some View {
        
        
        ZStack
        {

            Color.gray.ignoresSafeArea()
            
            
            TabView(selection: $currentPage)
            {
                Text("Hi").tag(0)
                SliderView(animationIsEnable: $animationIsEnable, shadowIsEnable: $shadowIsEnable).tag(1)
                
            }
            .indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .never))
            .tabViewStyle(PageTabViewStyle())
            
        }
  
        
    }
}


struct SliderView: View {

    
    @Binding var animationIsEnable  : Bool
    @Binding var shadowIsEnable     : Bool
    
    
    @State var volum1: Float = 50
    @State var volum2: Float = 50

    var body: some View {

        VStack {

            
            HStack { Text("03:58"); Slider(value: $volum1, in: 0...100, step: 1); Text("23:51") }.padding(.vertical)

            HStack {
                Button(action: {print("speaker.1")}) { Image(systemName: "speaker.1").font(Font.body.bold()) }
                Slider(value: $volum2, in: 0...100, step: 1)
                Button(action: {print("speaker.3")}) { Image(systemName: "speaker.3").font(Font.body.bold()) }
            }.padding(.vertical)
     
            
        }
        .padding(.horizontal)
        .foregroundColor(Color.black)
        .shadow(color: shadowIsEnable ? Color.black.opacity(0.7) : Color.clear, radius: 10, x: -8, y: 8)
        
    }
}


 
Asperi

Your problem is in .shadow.

The solution is to use compositing group. Tested with Xcode 12.1 / iOS 14.1

.foregroundColor(Color.black)
.compositingGroup()              // << here !!
.shadow(color: shadowIsEnable ? Color.black.opacity(0.7) : Color.clear, radius: 10, x: -8, y: 8)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related