Created
April 25, 2020 14:51
-
-
Save zntfdr/54d21c3d0538b0b6130c1d9c1a109a5e 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 screenAState: Bool = false | |
@Published var screenBState: Bool = false | |
} | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
lazy var appState = AppState() | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
let contentView = NavigationView { | |
ScreenA() | |
} | |
.environmentObject(appState) | |
if let windowScene = scene as? UIWindowScene { | |
let window = UIWindow(windowScene: windowScene) | |
window.rootViewController = UIHostingController(rootView: contentView) | |
self.window = window | |
window.makeKeyAndVisible() | |
} | |
} | |
} | |
struct ScreenA: View { | |
@EnvironmentObject var appState: AppState | |
var body: some View { | |
NavigationLink(destination: ScreenB(), isActive: $appState.screenAState) { | |
Text("Go to B") | |
}.isDetailLink(false) | |
} | |
} | |
struct ScreenB: View { | |
@EnvironmentObject var appState: AppState | |
var body: some View { | |
NavigationLink(destination: ScreenB(), isActive: $appState.screenBState) { | |
Text("Go to A") | |
}.isDetailLink(false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment