-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing “Root” #1
Comments
Hello @Reak45, Main app entry point @main
struct MainApp: App {
var body: some Scene {
WindowGroup {
RootView()
}
}
} Root View struct RootView: View {
@StateObject private var viewModel: RootViewModel
var body: some View {
if viewModel.userIsConnected {
Text("GO to maintabbar")
} else {
Text("login flow")
}
}
} Root ViewModel final class RootViewModel: ObservableObject {
@Published private(set) var userIsConnected: Bool = false
private var authenticationRepository: AuthenticationProceedings
private var cancellables = Set<AnyCancellable>()
init() {
setUp()
}
}
extension RootViewModel {
private func setUp() {
authenticationRepository.isAuthenticated
.receive(on: DispatchQueue.main)
.assignNoRetain(to: \. userIsConnected, on: self)
.store(in: &cancellables)
}
} Hope this helps. |
Thank you for your response! In the end I implemented a similar logic in my app :) |
Hello! Thank you so much for the article and the repository! They are both very helpful!
However, I have encountered an issue in my personal project that I cannot resolve on my own.
When the User first launches the app, I want him/her to complete a registration flow (a couple of views which can be navigated back). After that I’d like to set Main view as the root from which the user would be able to navigate to various subsections of the app and navigate back to the Main. How can I do that?
Thank you,
Aro
The text was updated successfully, but these errors were encountered: