Comments (3)
You can use the following interface and function to be able to pass the PaddingValues:
@Composable
fun CurrentTabX(
innerPadding: PaddingValues, snackBarHostState: SnackbarHostState
) {
val tabNavigator = LocalTabNavigator.current
val currentTab = tabNavigator.current as TabX
tabNavigator.saveableState("currentTab") {
currentTab.Content(innerPadding, snackBarHostState)
}
}
interface TabX : Tab {
@Composable
fun Content(
innerPadding: PaddingValues,
snackBarHostState: SnackbarHostState,
)
@Composable
override fun Content() {
error("Called Content without arguments")
}
}
Simply inherit from TabX
instead of Tab
for your Tabs and replace CurrentTab()
with CurrentTabX()
from voyager.
If you also want to then add a fade transition between the Tabs you could use:
typealias TabTransitionContent = @Composable AnimatedVisibilityScope.(Tab) -> Unit
@Composable
fun TabTransition(
navigator: TabNavigator,
transition: AnimatedContentTransitionScope<Tab>.() -> ContentTransform,
modifier: Modifier = Modifier,
content: TabTransitionContent
) {
AnimatedContent(
targetState = navigator.current,
transitionSpec = transition,
modifier = modifier
) { tab ->
navigator.saveableState("transition", tab) {
content(tab)
}
}
}
@Composable
fun FadeTabTransition(
navigator: TabNavigator,
modifier: Modifier = Modifier,
animationSpec: FiniteAnimationSpec<Float> = spring(stiffness = Spring.StiffnessMediumLow),
content: TabTransitionContent
) {
TabTransition(
navigator = navigator,
modifier = modifier,
content = content,
transition = { fadeIn(animationSpec = animationSpec) togetherWith fadeOut(animationSpec = animationSpec) }
)
}
And then call the following for the content of your Scaffold instead of CurrentTabX
:
content = { innerPadding ->
FadeTabTransition(it) { tab ->
(tab as TabX).Content(innerPadding, snackBarHostState)
}
},
from voyager.
Sorry for the late reply @hristogochev... Looks like a nice solution, thank you!
from voyager.
Related Issues (20)
- [Desktop] Density is not updated on changing the window to a screen with different density
- [KMP ViewModels][Voyager][Koin] Crush if you try to navigate back
- Override the back press in each Screen in Compose Multiplatform HOT 3
- Snackbar overlapped by BottomSheet when using BottomSheetNavigator
- HorizontalPager HOT 1
- [WASM] [Font] tofu are displayed instead of the actual font HOT 1
- Android Activity Lifecycle events stop being forwarded by AndroidScreenLifecycleOwner after screen rotation
- BottomSheetNavigator - IOS Build error HOT 4
- Navigation testing
- Problem with @Transient during Screen serialization
- 最新版本打包ios 会报错
- Need a dialog box style screen navigator
- Pass data to previous composable screens
- Crash when take picture HOT 4
- Voyager-Worker HOT 1
- Wasm URL routing support HOT 1
- Lifecycle Events Not Triggered During Screen Navigation HOT 4
- ScreenModel function goes into infinite loop when calling from screen HOT 2
- Screen Overridable Content function call multipleTimes when pass data from one Screen to another in Android project.
- Crash on implementing ScreenLifecycleOwner HOT 2
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.