SM Arif Ahmed
SM Arif Ahmed

Reputation: 63

DatePicker height blinks when presented in .fullScreenCover(_ :) - SwiftUI

Click to view the issue

I'm trying to present a view with the DatePicker in it. When the view is presented suddenly the DatePicker height increases with a blink.

Working on min iOS version 14

Here is the code,

struct ContentView: View {
    
    @State private var showDatePicker : Bool = false
    @State private var pickedDate : Date = Date()
    
    var body: some View {
        VStack{
            Spacer()
            
            Button {
                showDatePicker.toggle()
            } label: {
                Text("Show Date Picker")
            }

            
            Spacer()
        }
        .fullScreenCover(isPresented: $showDatePicker) {
            DatePicker("Date Picker",
                       selection: $pickedDate,
                       displayedComponents: [.date])
            .datePickerStyle(.graphical)
            .padding(.horizontal)
        }
    }
}

When normally doing hide/show in a view by a flag it works fine. The blink appears when presenting with .fullScreenCover(_:)

Upvotes: 0

Views: 273

Answers (1)

VINA GAJERA
VINA GAJERA

Reputation: 74

Try this one is Working.

Xcode: 14.3 iOS Target: 16.2

@State private var showDatePicker : Bool = false
@State private var pickedDate = Date()
    
var body: some View {
    VStack{
        Spacer()
        Button {
            showDatePicker.toggle()
        } label: {
            Text("Show Date Picker")
        }
        Spacer()
    }
    .fullScreenCover(isPresented: $showDatePicker) {
        DatePicker("Date Picker",
                   selection: $pickedDate,
                   displayedComponents: [.date])
        .datePickerStyle(.graphical)
        .padding(.horizontal)
        .onAppear{
            self.pickedDate = Date()
        }
    }
}

Upvotes: 1

Related Questions