Giter Site home page Giter Site logo

Comments (3)

Mukuljangir372 avatar Mukuljangir372 commented on June 15, 2024

@iesedobleac I've gone through you code but I didn't find the screen code. Could you share the code for screens and tabs including navigation logic as well?

from voyager.

iesedobleac avatar iesedobleac commented on June 15, 2024

@iesedobleac I've gone through you code but I didn't find the screen code. Could you share the code for screens and tabs including navigation logic as well?

Yes, of course, here it is:

My main App Composable

@Composable
fun App() {

    val tabs = listOf(HomeTab, MapsTab)

    KoinContext {

        MaterialTheme {

            TabNavigator(
                tab = HomeTab,
                tabDisposable = {

                    TabDisposable(
                        navigator = it,
                        tabs = tabs
                    )
                }
            ) {
                Scaffold(topBar = {
                    TopAppBar(title = {
                        Text(text = it.current.options.title)
                    })
                }, bottomBar = {
                    BottomNavigation {

                        tabs.forEach { tab ->
                            TabNavigationItem(tab)
                        }
                    }
                }, content = {
                    CurrentTab()
                })
            }
        }
    }
}

My HomeTab

object HomeTab : Tab {

    override val options: TabOptions
        @Composable
        get() {
            val icon = rememberVectorPainter(Icons.Default.Home)

            return remember {
                TabOptions(
                    index = 0u,
                    title = "Home",
                    icon = icon
                )
            }
        }

    @Composable
    override fun Content() {
        Navigator(screen = HomeScreen()) { navigator ->
            SlideTransition(navigator = navigator)
        }
    }
}

My HomeScreen

class HomeScreen : Screen {


    @Composable
    override fun Content() {
        HomeScreenContent()
    }
}

@Composable
fun HomeScreenContent(viewModel: HomeViewModel = koinInject<HomeViewModel>()) {

    Column(
        modifier = Modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {

        Button(onClick = {
            navigator.push(DetailScreen())
        }) {
            Text("Go to detail")
        }
    }
}

And finally, this is my DetailScreen:

class DetailScreen : Screen {

    @Composable
    override fun Content() {

        val navigator = LocalNavigator.current

        Box(modifier = Modifier.fillMaxSize()) {

            IconButton(
                onClick = {
                    navigator?.pop()

                }, modifier = Modifier
                    .padding(start = 14.dp, top = 14.dp)
                    .clip(CircleShape)
                    .background(MaterialTheme.colors.primary)
            ) {
                Icon(
                    imageVector = Icons.Default.ArrowBack,
                    contentDescription = null,
                    tint = Color.White
                )
            }

            Column(
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally,
                modifier = Modifier.fillMaxSize(),
            ) {
                Text("Detail Screen")
            }
        }
    }
}

from voyager.

subtosharki avatar subtosharki commented on June 15, 2024

i am having the same problem trying to use a LocalNavigator.currentOrThrow.push(Screen) inside of a tab and it didnt work, instead it gave me this error

screens.vendor.VendorScreen cannot be cast to cafe.adriel.voyager.navigator.tab.Tab

did you ever find a fix to this?

from voyager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.