I think it’s pretty clear from the code what I’m t...
# compose
o
I think it’s pretty clear from the code what I’m trying to do, is this the most ideal way to do it?
Copy code
@AndroidEntryPoint
class MainActivity : ComponentActivity() {

    @Inject
    lateinit var prefs: SharedPreferences

    private val viewModel: MainViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        lifecycleScope.launch {
            viewModel.state.collect { uiState ->
                when (uiState) {
                    is MainViewModel.MainState.Loading -> {
                        Log.d("MainState", "Loading...")
                    }
                    is MainViewModel.MainState.Success -> {
                        setContent {
                            uiState.user?.let { Home(user = it) }
                        }
                    }
                    is MainViewModel.MainState.Error -> {
                        setContent {
                            Authentication()
                        }
                    }
                }
            }
        }
    }
}
🧵 2
I want to make a NavHost instead but the issue is that the routes are not available at the time of setting the NavHost destination, it’s bound to the state and depending on the state the routes are created
s
Making separate
setContent
calls looks very odd to me, I don’t think this is what you want to do. One
setContent
, with this switch inside of it. This is an image I saw recently which shows how much
setContent
is doing. I could be wrong of course but I don’t think you want to do this conditionally instead of just once.
o
Yes that was the first smell I got, but I think the rest makes sense
Thanks