Repository navigation
Conversation
|
@Kashif-E HI, we will have a look on this soon (testing and trying on our samples), don't know if it will be for 1.0 that will be soon released. Btw thanks for the contribution! I will let you know soon! |
97053dc to
2792058
Compare
# Conflicts: # voyager-navigator/src/commonMain/kotlin/cafe/adriel/voyager/navigator/Navigator.kt
|
Hey guys, any updates on this? |
|
@DevSrSouza any update ? |
|
@DevSrSouza @adrielcafe this is something we really need can you please help here? |
|
@Kashif-E Have you given up on this? :( |
|
@jakoss i hate to admit this but yes, but, i am thinking about making my fork a separate library. |
More fragmentation for navigation libraries for compose, but i understand the reason. This thread is too ignored at this point |
|
@Kashif-E Can we get back here? Forgive us for inactivity, this feature is very important and we want it on Voyager Please let me know if you can continue here, I will take care of reviewing it and ensuring it is merged, if not possible I will continue it myself. Thank you in advance for your time and contribution!! 🙏🏽 |
|
I don't feel like this implementation is ideal for Voyager, I would prefer something like the one displayed here would be better. I feel it clutters the navigator when it could just be a module added on-top of it |
|
1 issue I find with this is that it uses String keys, I find that with Kotlin I would prefer to have a TypeSafe key to Value object that allows managing types inherently. Something like this interface TypedKey<T>
object DataId : TypedKey<Long>
private val typedKeyMap: Map<TypedKey<*>, Any>
fun <T> putInTypedKeyMap(typedKey: TypedKey<T>, value: T): T {
typedKeyMap[typedKey] = value
}
fun <T> getFromTypedKeyMap(typedKey: TypedKey<T>): T {
return typedKeyMap[typedKey] as T
}
fun inputMyData() {
putInTypedKeyMap(DataId, 100L)
}
fun getMyData() {
val myDataId: Long = getFromTypedKeyMap(DataId)
} |
|
@Syer10 Great! What we want here is the "possibility of passing results between screens" the way, api, imp in which this will be done has not yet been defined. Also agree that such a feature should be something "more" and not tied to the navigator. What you said will be considered, thanks! |
|
@Syer10 what you said is perfectly right. However, there are a few things that should be considered here
|
|
this looks great @DevSrSouza. ill test this in our app and will let you know how this works |
|
This could get into the documentation IMHO @DevSrSouza |
|
Is it possible to use this snippet with a BottomSheetNavigator? @DevSrSouza |
|
@DevSrSouza it works, 🎆🎆 @osrl both mine and what @DevSrSouza proposed can be used with bottomsheet navigator |
|
|
|
@osrl you can use these extensions, remove the actual keyword |
|
Hello, is it going to be supported by the library, or you prefer to keep it as extension function and everybody just copy paste it? |
|
@DevSrSouza This works, it's great, but it seems a little cumbersome to use, maybe I'm using it the wrong way? However, due to life cycle issues, the first page can only get the current value by directly using var lastItemKey: String? by rememberSaveable {
mutableStateOf(null)
}
Box(modifier = Modifier.clickable {
navigator.push(SecondPageScreen())
lastItemKey = navigator.lastItem.key
})
if (lastItemKey != null) {
val result by navigator.navigationResult
.getResult<String>(lastItemKey!!)
} |
|
@0xZhangKe it does not matter what you use as key for example you use "papi chulo" as key when passing back result and use it on first screen |
1 similar comment
|
@0xZhangKe it does not matter what you use as key for example you use "papi chulo" as key when passing back result and use it on first screen |
|
@Kashif-E This means that the first page must clearly know the Key of the second page. If the two Screens are in different modules and cannot reference each other, then this will become a bit troublesome. |
|
@0xZhangKe try this |
|
I think that there is a confusion here. Voyager is Screen based navigation and if you needs the result it should be handled by the previous screen and not returned to the navigation stack action call. interface PopResult<in T> {
fun onResult(result: T)
}
class MyScreen : Screen, PopResult<T> {
fun onResult(result: T) {
// handle the popped result
}
}
// Inside screen Content() that will be popped
val navigator = LocalNavigator.currentOrThrow
navigator.pop() // It is a sync call and will not trigger recomposition immediatelly
val nextScreen = navigator.lastItemOrNull as? PopResult<T>
nextScreen?.onResult(...) |
|
meanwhile there is no official support, I'm currently using this if anyone needs, it enforces some type safety by sending "request" to the next screen. It's almost the same as DevSrSouza proposal, but nav library agnostic. Ofc, if it's not implemented correctly an value can be held in memory until the app is closed by the user and even potentially exceed parcelable size limit // Root
ProvideNavResultStateHolder() {
Navigator(Screen1())
}
// Screen1
val contract = rememberNavResultContract<Int>(key)
val response = contract.response.value
val isCurrentScreen = navigator.isCurrentScreen(key)
LaunchedEffect(response, isCurrentScreen) {
if(!isCurrentScreen) return@LaunchedEffect
if(response !is NavResult.Value) return@LaunchedEffect
// Do something
contract.consume()
}
Button(
onClick = {
navigator.push(Screen2(contract.request))
}
) {
Text("Push")
}
// Screen2
val contract = rememberNavResultContract<Int>(request)
Button(
onClick = {
contract.send(0)
navigator.pop()
}
) {
Text("Pop")
}
|
|
We all are still waiting for this PR. |
|
Any updates? |
|
We all are still waiting |
Where is this |
It was renamed to |
thanks, did look into it but not quite sure |
|
Hey guys, VoyagerScreenDelegate.kt val Navigator.screenDelegates: VoyagerScreenDelegate
get() = NavigatorLifecycleStore.get(this) {
VoyagerScreenDelegate()
}
class VoyagerScreenDelegate() : NavigatorDisposable {
private val delegates = mutableStateMapOf<String, Any?>()
override fun onDispose(navigator: Navigator) {
clearDelegates()
}
fun setDelegate(delegateKey: String, delegate: Any?) {
delegates[delegateKey] = delegate
}
fun <T> getDelegate(delegateKey: String): T? {
return delegates[delegateKey] as? T
}
fun clearDelegate(delegateKey: String) {
delegates[delegateKey] = null
}
private fun clearDelegates() {
delegates.clear()
}
}Then we can create a delegate class with a delegation interface for SecondScreen (a screen that needs to pass back the results) data class SecondScreenDelegate(
val onItemClick: (Int) -> Unit,
val onDismiss: () -> Unit
)When we need to push SecondScreen into the stack we can create an instance of SecondScreenDelegate, save it to Navigator with delegateKey, and pass delegateKey to the SecondScreen. val delegateKey = this.hashCode().toString()
navigator.screenDelegates.setDelegate(
delegateKey = delegateKey,
delegate = SecondScreenDelegate(
onItemClick = {
selectedItemIndex = it
navigator.screenDelegates.clearDelegate(delegateKey)
navigator.pop()
},
onDismiss = {
navigator.screenDelegates.clearDelegate(delegateKey)
navigator.pop()
}
)
)
navigator.push(SecondScreen(delegateKey = delegateKey))With provided delegateKey in the SecondScreen we can get instance of delegate and fire callbacks in the place where SecondScreen logic is required when (action) {
is SecondScreenAction.OnItemClick -> {
_delegate?.onItemClick?.let { it(action.index) }
}
is SecondScreenAction.OnDismiss -> {
_delegate?.onDismiss?.let { it() }
}
}For more clarity I have created a sample project to investigate and try it out. |
|
Really terrible that this PR didn't get enough attention. 3 months without any changes, is this library still alive? |
|
Too bad this was not moved forward, would have been nice to have. Passing data is a very important part of navigation. |
|
DevSrSouza's solution is perfect and works as expected when working with a single navigator, but for me, I am using multiple navigators, for example, a tab navigator and then a screen inside the tab where it does not work. Then call it like from where you want to send result back extension if required Good work DevSrSouza appriciated. |

Closes #110
Adds support to pass results between screen for
NavigatorandBottomSheetNavigator.using Navigator.
Passing the result
Getting the result
destinationsNavigator .getResult<Boolean>(LocalNavigator.currentOrThrow.lastItem.key) .value ?.let { result -> onAddedToCart(result) }using BottomSheetNavigator:
Passing the result
Getting the result: