'Composable as method parameter
I have a Scaffold composable which is used as the basis of all screens :
@Composable
fun ScreenScaffold(
navController: NavController? = null,
modifier: Modifier = Modifier,
topBar: @Composable () -> Unit = {},
hasBottomNavBar : Boolean = false,
hasGradient : Boolean = true,
stickyContainerContent: @Composable () -> Unit = {},
showStickyContainer: Boolean = false,
surfaceMode: SurfaceMode = SurfaceMode.OnBackground,
stickyContainerSurfaceMode: SurfaceMode = surfaceMode,
onBackButtonPressed: (() -> Boolean)? = null ,
content: @Composable () -> Unit) {
And TopBar parameter is a composable like this:
@Composable
fun TopBar(
title: String? = null,
titleAlign: TextAlign = TextAlign.Start,
hasLargeTitle: Boolean = false,
largeTitleTextStyle: TopBarLargeTitleTextStyle = TopBarLargeTitleTextStyle.LARGE,
hasBackButton: Boolean = false,
backButtonTint: Long = OneAppTheme.colors.topNavIconColor,
backButtonOnClick: () -> Unit = {},
rightButtonImageToken: String? = null,
rightButtonTint: Long = OneAppTheme.colors.topNavIconColor,
rightButtonOnClick: () -> Unit = {},
surfaceMode: SurfaceMode = SurfaceMode.OnBackground,
scrollBehavior: TopBarScrollBehavior? = null,
) {
Right now if I wanna pass a callback for back button handling, I have to pass it twice for both ScreenScaffold and TopBar (onBackButtonPressed and backButtonOnClick respectively). How can I pass that callback just once to ScreenScaffold and then somehow pass it to TopBar?
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
