Created
May 16, 2020 15:12
-
-
Save lawreyios/7a1e8a982281607c5825c0c8fc59bbc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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