Hello, I'm what's the recommended method to naviga...
# compose-desktop
g
Hello, I'm what's the recommended method to navigate/route views in desktop? I've tried to import
androidx.navigation:navigation-compose
but getting aar gradle import issues. I've been told this is not available for desktop yet. All I want to do is have sidebar items and be able to change the view on the main right panel. Most of the examples are using some sort of state but for the same view only such as Issues or Code. Also If I have an
onClick
method it tells me this can't return a composable as I've tried to do it that way, passing in a composable or returning a composable upon clicking
p
What about just using a Stack<Screen>?
g
oh I didn't know about this? are there any guides?
p
Well it's desktop you don't have the save instance requirements
Just use a stack and render the top element
Manipulate the state of the top element in your onClick
Or add a new state on top of the stack and render it
a
But do you need a stack at all? According to your description, you just need to replace current view. So it is just something like State<@Composable () -> Unit>.
g
@Arkadii Ivanov oh so the main body is added ina state and can return a Composable?
and upon an click I can modify that state and hence the view would change?
a
Yep. You also need to render the view. Like state.value()
g
ok thanks for that, will give it ago.
p
To me it reads it's overcomplicating things
What is it exactly that's shown in onClick?
g
@Paul Woitaschek just doing simple routing, sidebar has various items on click each should display it's own view on the main body view, so window is one row with two columns
Navigation seems like what I want but unfortunately it's not supported on desktop
a
I doubt you need a navigation, since navigation normally means back stack, but looks like you don't need one. So simply have a state with currently active "view" and replace it when needed. A view can be represented as a descriptive sealed class with all possible variants, or as @Composable function. But in case you need navigation, here is an open issue to follow: https://github.com/JetBrains/compose-jb/issues/85
g
thanks @Arkadii Ivanov this might get me over the hurdle for the moment, but navigation would be nice especially param/route based which I'll need in the future, then again I'm not a mobile dev so playing around with desktop for now to get an idea what I can build/do with it
p
Its not jvm but I guess its portable quite easy
g
oh nice, what you mean by not jvm though?
looks like it's in kotlin so 'jvm' right?
a
It is an Android library which produces
aar
g
I see thanks
@Arkadii Ivanov do you have an example of a project using this
Copy code
State<@Composable () -> Unit>
a
No I don't. It's actually better to represent all screens as a sealed class, and use State<Screen>.
g
I see
this looks like the winner, I will try this later on today and report back to see how it went
hope viewModel is supported by desktop though