2

I have code like this:

            VStack{
                if (DeleteScreen.sharedInstance.postDelete){
                    VStack{
                        GeometryReader{_ in
                            DeletePostAlert()
                                .frame(maxWidth: .infinity, alignment: .center)
                                .frame(maxHeight: .infinity, alignment: .center)
                                .transition(AnyTransition.opacity.animation(.easeInOut(duration: 0.2)))
                            
                        }.background(Color.black.opacity(0.65))
                        
                        .onDisappear{

                        }
                        .onAppear{
                            
                            
                            
                        }
                    }
                }
            }

where the DeletePost alert is defined like this:

class DeleteScreen: ObservableObject {
    static let sharedInstance = DeleteScreen()
    @Published var postDelete: Bool = false
}

However, for some reason, the transition animations are not working. I'm trying to get the DeletePostAlert() to fade in or slide in or something but so far everything I've tried has not worked. I've also tried something like .animation(.spring()), but to no avail.

Any guidance as to what I'm doing wrong here would be appreciated.

Thanks

Evan
  • 1,892
  • 2
  • 19
  • 40

1 Answers1

4

I have exactly the same problem. Looks like a bug.

A possible solution that could be working for you is to set transition modifier on top of GeometryReader.

VStack {
    if(DeleteScreen.sharedInstance.postDelete) {
        VStack {
            GeometryReader { _ in
                DeletePostAlert()
                    .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
            }
            .transition(AnyTransition.opacity.animation(.easeInOut(duration: 0.2)))
            .background(Color.black.opacity(0.65))
            .onDisappear { ... }
            .onAppear { ... }
        }
    }
}

btw: I'm wondering why are you even using GeometryReader if you ignore its geometry value.

pleshis
  • 406
  • 5
  • 7