Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to remove background of a view with different Transition?

$
0
0

I'll provide a simplified example. Let's say when I toggle I want to instantly remove the background of the text without any transition or animation, but have the text itself fade out with opacity. How can I achieve this? Please, do not suggest using a ZStack instead of .background; I am looking for a solution in this specific scenario. If it's not possible, please let me know.

struct BackgroundTransition: View {    @State var show = true    var body: some View {        VStack {            Group {                if show {                    Text("Some Text")                        .background(                            Color.blue                                .transition(.identity)                                .animation(.none, value: show)                        )                } else {                    Spacer()                        .frame(maxHeight: .infinity)                }            }            .frame(height: 50)            Button("Toggle") {                withAnimation {                    show.toggle()                }            }        }    }}

I tried applying .identity transition to the background view and .none animation, but it didn't work.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>