Comments (3)
@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 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.
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)
- Backpress in Screen HOT 1
- How to use BackHandler in a Screen with TabNavigator?
- Add windowInsets to BottomSheet HOT 1
- Working with lifecycle events in common HOT 5
- Crash due to Parcelable encountered IOException writing serializable HOT 6
- Navigator inside Dialog doesn't push screen properly
- iOS build error HOT 4
- iOS-like swipe back navigation HOT 3
- Deeplinks and Voyager HOT 1
- Voyager hilt support broken with Dagger 2.51 HOT 1
- UI Testing HOT 1
- Choose Different Animation Transitions Based on Different Screens HOT 2
- navigator scoped for viewmodel (moko-mvvm) HOT 1
- [Question] How to navigate from ScreenModel/ViewModel? HOT 1
- Window inset imePadding stopped working in 1.1.0-alpha03 HOT 2
- Voyager Screen with a `ViewModel` does not have its `SavedStateHandle` saved on process death HOT 1
- Custom back handling depending on the currentScreen HOT 2
- Integration with KMMViewModel
- Nesting Navigators prevents WindowInsets from being updated upon device rotation on iOS
- Parcelable encountered IOException writing serializable object HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from voyager.