Hi everyone .. Im Using Voyager as my Navigation ....
# compose-ios
a
Hi everyone .. Im Using Voyager as my Navigation .. However i cant swipe to go back on ios target .. is there a way or sample repo to implement back gesture on iosApp ? thank you ..
k
cc @SrSouza
m
same here
a
im able to imitate back gesture manually with something like this
Copy code
abstract class BaseScreen : Screen, BaseScreenContent, ScreenLifecycleOwner {

    @Composable
    override fun Content() {
        val navigator = LocalNavigator.currentOrThrow
        var offsetState by remember { mutableFloatStateOf(0f) }
        Box(
            modifier = Modifier.background(Color.White)
        ) {
            ScreenContent()
            if (Platform.os == PlatformOS.iOS){
                Box(
                    modifier = Modifier
                        .fillMaxHeight()
                        .width(20.dp)
                        .pointerInput(Unit){
                            detectHorizontalDragGestures(
                                onDragEnd = {
                                    if (offsetState > 100) {
                                        if (navigator.items.size > 1) navigator.pop()
                                    }
                                    offsetState = 0f
                                }
                            ) { _, dragAmount ->
                                if (offsetState < 0) return@detectHorizontalDragGestures
                                offsetState += dragAmount
                            }
                        }
                )
            }
        }
    }
}

private interface BaseScreenContent {
    @Composable
    fun ScreenContent()
}
❤️ 1
m
@Angga Ardinata wow nice! I will try this. Did you only apply this to a BaseScreen and does that work for all? or you apply to each screen?
a
How do you create a new screen ? If just class HomeScreen : Screen {} Change the implementation of Screen with BaseScreen
To all of your screen
m
Right now I dont have a BaseScreen yet
but okay I will add that then
a
I will not work like ios back gesture where you can peek previous screen .. bit for me atleast user can goback with swipe 😁
Voyager still developing this feature
m
ahh yes that is all I need as well actually 😄
thank you very much @Angga Ardinata will try this on my end
a
https://github.com/adrielcafe/voyager/issues/144 .. here the issue for back gesture
1
m
hello @Angga Ardinata just want let you know I managed to implement the back gesture thanks to your help. Hopefully voyager adds the peek previous screen but your solution was a great alternative as well! 🙇
a
@mangubatrj Wow glad that im actually helping someone with my limited knowledge
🙌 1
s
I have not being able to contribute to Voyager lately, but PR are welcome always. Suggestion folks, instead of using
BaseScreen
you folks could just add this component to the main Navigation Content. Example:
Copy code
Navigator(...) { navigator ->
   Box(..) {
     CurrentScreen()
     if (Platform.os == PlatformOS.iOS){
        ...
     }
   }
}
About previous screen peek, I need to validate about recomposition of it, but, Voyager Stack is built with SnapshotStateList, so, in practice, something like this:
Copy code
val previousScreen = remember(navigator) {
  derivedStateOf {
    navigator.toList().getOrNull(navigator.size - 2)
  }
}
But if this does not work properly we could easily add
peekPreviousItem
on it.
👍 1
I did share a implementation from PreCompose that I manage to make it work on Voyager, check it out: https://github.com/adrielcafe/voyager/issues/144#issuecomment-1763186873
🔥 1
❤️ 1
m
Thank you @SrSouza will definitely check this out! ❤️
104 Views