Skip to content

Instantly share code, notes, and snippets.

@lawreyios
Created May 16, 2020 15:12
Show Gist options
  • Save lawreyios/7a1e8a982281607c5825c0c8fc59bbc8 to your computer and use it in GitHub Desktop.
Save lawreyios/7a1e8a982281607c5825c0c8fc59bbc8 to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State private var shouldShowErrorLabel = false
init() {
UINavigationBar.appearance().backgroundColor = .blue
UINavigationBar.appearance().largeTitleTextAttributes = [
.foregroundColor : UIColor.white,
]
}
var errorLabel: some View {
HStack {
Spacer()
Text("Error!")
.fontWeight(.bold)
.foregroundColor(Color.white)
Spacer()
}
.frame(height: 44.0)
.background(Color.red)
}
var body: some View {
NavigationView {
VStack {
if shouldShowErrorLabel {
errorLabel.transition(.asymmetric(insertion: .fadeAndSlide, removal: .fadeAndSlide))
Spacer()
Spacer()
}
}
.navigationBarTitle("Home", displayMode: .large)
.onAppear {
self.animateAndDelayWithSeconds(1) { self.shouldShowErrorLabel = true }
self.animateAndDelayWithSeconds(3) { self.shouldShowErrorLabel = false }
}
}
}
func animateAndDelayWithSeconds(_ seconds: TimeInterval, action: @escaping () -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
withAnimation {
action()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment