Last active
November 8, 2021 03:35
-
-
Save svenoaks/4a37d348ee83ba77325c16938a997c6d to your computer and use it in GitHub Desktop.
This file contains 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
import SwiftUI | |
class AppState:ObservableObject { | |
@Published var showLoadingOverlay = false | |
func loadData() { | |
self.showLoadingOverlay = true | |
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { | |
self.showLoadingOverlay = false | |
} | |
} | |
} | |
struct ContentView: View { | |
@StateObject var state = AppState() | |
var body: some View { | |
VStack { | |
Text("HELLO") | |
Button { | |
state.loadData() | |
} label: { | |
Text("BUTTON") | |
} | |
} | |
.fullScreenCover(isPresented: $state.showLoadingOverlay) { | |
Text("LOADING") | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment