Skip to content

Instantly share code, notes, and snippets.

@christianselig
Created November 18, 2022 16:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save christianselig/5959a807b4d1979ca6e65c9889a5aa2f to your computer and use it in GitHub Desktop.
Save christianselig/5959a807b4d1979ca6e65c9889a5aa2f to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State var show: Bool = false
var body: some View {
ZStack {
Button {
show.toggle()
} label: {
Text("Show")
}
ZStack(alignment: .bottom) {
if show {
Color.clear
Text("Hello once upon a time there was a duck named Ducky who went on to drink lots of juice boxes and live happily ever after")
.padding()
.frame(maxWidth: .infinity, alignment: .center)
.background(
Color.green
.cornerRadius(20.0)
.ignoresSafeArea()
)
.transition(.move(edge: .bottom))
.zIndex(1)
}
}
.animation(.linear(duration: 1.0), value: show)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
@bhimsenp
Copy link

bhimsenp commented Nov 18, 2022

struct ContentView: View {
    @State var show: Bool = false
    
    var body: some View {
        ZStack {
            Button {
                show.toggle()
            } label: {
                Text("Show")
            }
            GeometryReader { reader in
                ZStack(alignment: .bottom) {
                    if show {
                        Color.clear
                        Text("Hello once upon a time there was a duck named Ducky who went on to drink lots of juice boxes and live happily ever after")
                            .padding()
                            .frame(maxWidth: .infinity, alignment: .center)
                            .padding(.bottom, reader.safeAreaInsets.bottom)
                            .background(
                                Color.green
                                    .cornerRadius(20.0)
                            )
                            .transition(.move(edge: .bottom))
                            .zIndex(1)
                    }
                }
                .ignoresSafeArea()
            }
            .animation(.linear(duration: 1.0), value: show)
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment