Skip to content
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

Navigation from ScreeModel #385

Open
GtechGovind opened this issue Apr 2, 2024 · 2 comments
Open

Navigation from ScreeModel #385

GtechGovind opened this issue Apr 2, 2024 · 2 comments

Comments

@GtechGovind
Copy link

In my current scenario, I'm seeking a solution to navigate from a ScreenModel to another screen. Regrettably, I haven't discovered a suitable method to accomplish this yet. Could you please provide guidance or suggestions on how to enable this navigation? Any assistance would be greatly appreciated. Thank you.

@akardas16
Copy link

you can achieve it with callbacks easily (kotlin callbacks)

assume below function is in your ScreenModel

 suspend fun loginUser(result:(data: UserResponse?, error: String?) -> Unit){ 
        repository.loginUser(model){response, error ->
            response?.let {
                  result(it, null)
            }
            error?.let {
                Log.i("error", "loginUser Error: $it")
               result(null, it)
            }
        }
    }

you can call it in your screen like below

  screenModel.loginUser{data, error ->
          response?.let{
               //navigate another screen in here
       }
 }

@nvkleban
Copy link
Contributor

nvkleban commented Apr 7, 2024

There are two main approaches that I know:

  1. With UiState - set some flag that indicates you need to navigate somewhere, then consume it by unsetting it screenmodel.navigetedToSomeScreen().
  2. With one time effects - use some kind of Channel that exposes events as Flow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants