Hello! I'm creating an app using nav3. Right now I...
# compose
k
Hello! I'm creating an app using nav3. Right now I'm having the issue of performing an "up" navigation action. So basically there is no screen before, you open on some sort of detail page, but if you press the arrow button on the top left, it goes to the screen it would have before this screen. However, I'm having trouble showing the back animation. I've tried adding to the backstack and then removing the last item, but that only works if I set a delay of around 100 millis to give compose time to recognize the extra screen. Another thing I've tried was reverting the animation just for this time, this works, but the z-index is wrong (target screen is in front of initial). I've tried adjusting the z-index of the transition, but nav3 handles this themselves. Anybody has any luck with this?
👀 1
s
nav3 recipes show how to do that, which is what nav2 was doing internally. In that scenario, you are not in your own task, so doing this takes you back to your own task in a new activity. Recipe: https://github.com/android/nav3-recipes/tree/main/app/src/main/java/com/example/nav3recipes/deeplink/advanced
k
Thanks for the response! But this just creates a new task stack for Android, finishes the current activity and starts the new one(s). I'm building for Compose Multiplatform and using a single activity. So this is indeed what I am looking for, but I'd like it to be full nav3 code.
s
You should never find yourself in such a scenario where you only have a single destination in your backstack unless you were deep linked into the app. And I must admit I do not know much about iOS deep links to help you there.
k
Yes, of course, but it is a deeplink. Which I am handling with compose nav3. After the deeplink, I'd like the "up" to perform a backwards transition. It should be really easy. The backstack is just check if there is a single item, insert an item before and pop. But because nav3 exists in compose, you first have to wait until nav3 recognizes there is a screen added in the backstack. When that happens, I can pop and get the backwards transition. Otherwise it will be a forwards transition. The native code doesn't really matter here, since I want to handle it in the multiplatform nav3 compose code.
s
But that's what I am saying, if you do
The backstack is just check if there is a single item, insert an item before and pop
you will break the functionality on Android at least, you will stay on the task of the app that you were deep linked from instead of going back to your own task.
k
I think your architecture is a little different then. I have a single activity with launchmode singleTask. So there never will be multiple tasks for my app. And since I am programming in Compose Multiplatform I want as much as possible to be handled there instead of Android or iOS specific. Deeplinking is just navigating. I really appreciate you trying to help me! But I think we have different philosophies on how this should be handled. I really just want to force the back transition on nav3, if I manage to do that, my deeplinking and "up" navigation is working.
p
How are you handling deeplinks - your custom code or using the nav3 API? I am not sure about the new DeepLink API in 1.2 but if you are doing custom handling. Why not adding the 2 screens since the beginning? Like build a full stack with 2 navEntries since the beginning, instead of only the 1 product detail NavEntry
👆 1
👆🏻 1
s
Yeah I assumed you were not using
SingleTask
since it's not really the recommended option to use for Android apps. I'd do what Pablichenko says in your case.
k
I am using custom code which receives the deeplink information from both platforms and then fills the backstack with the information it needs. I could add the screen at the beginning in this backstack, but you would need to press back an extra time to get back to the previous app or website from which the deeplink came. This is why I wanted an "up" navigation. You press hardware back -> go back to previous app. You press back / up button -> you go to the screen before.
p
Oh I see, I get it better now, I mean it is a really unique design. It seems you will have to go with your previous workaround. I just wonder, if instead of waiting ~100ms as you said. If there is some callback from navdisplay so you don't have to guess this delay time
k
Haha it made sense to me to do it this way. I've tried, but haven't really gotten a successful way of doing it. I've tried the following: • delay -> is working if enough time • callback from NavDisplay sceneDecoratorStrategies (thought maybe after scene is decorated, navdisplay will know), but doesn't work • use my own rememberDecoratedNavEntries and use LaunchedEffect to see if entries have changed and callback from there, but doesn't work • I've tried using coroutineScope
withFrameNanos {  }
, but doesn't work (unless I have like 10 or something) So I'm really in the dark at what time the NavDisplay knows the new backstack so I can begin to pop.
p
Humm, if the decorator didn't work not sure what else. Perhaps opening a ticket in the nav3 recipes repo, either for a bug or a feature request. 100ms is too much imo
k
Yeah, I think that's best, but though maybe check here first if somebody managed to do this
Agreed, and prone to error
👍 1
v
Use the
metadata: (K) -> Map<String, Any>
entry overload and derive the correct
transitionSpec
transition from whether or not your key is deeplinked.
k
Thanks for the response, but as I said, the z-index is wrong if I just reverse the transitionSpec. Changing the z-index on the transitionSpec is also not working, nav3 does that internally.