Hi guys, is Navigation from one composable screen to another composable screen is possible without using Navigation libraries??
Let me explain what i want.
this is my MainActivity from where the main composable screen is shown. on a button click i am trying to navigate to some other screens from the main screen. However it errored while calling Navigate* composables : @Composable invocations can only happen from the context of a @Composable function
Copy code
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val viewModel by viewModels<AdsViewModel>()
setContent {
AdsTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
// Greeting("Android")
AdsScreen(viewModel,{
NavigateShowAll(viewModel = viewModel)
} ,{
NavigateClickBuy(it)
})
}
}
}
}
}
@Composable
private fun NavigateShowAll(viewModel: AdsViewModel) {
AdsViewAllScreen(viewModel)
}
@Composable
private fun NavigateClickBuy(url: String) {
}
j
jw
04/01/2023, 2:31 PM
Sure. At its simplest navigation is a boolean and an if statement selecting one of two screens
a
Anshulupadhyay03
04/01/2023, 3:07 PM
Thanks for the reply, @jw. But I did not get what you meant. I have updated the question with more information making it clear.
s
Scott Kruse
04/01/2023, 3:54 PM
Navigation is just a state change
a
Anshulupadhyay03
04/01/2023, 3:58 PM
@Scott Kruse and @jw thanks guys , i got what you guys saying and achieved it.
a
andylamax
04/03/2023, 9:56 AM
Next time please do ask android specific question in #compose-android not #compose