简体   繁体   English

Jetpack Compose:底页未按预期显示

[英]Jetpack Compose: Bottom Sheet not showing up as expected

I have a scaffold that has a BottomNavigationView and the content.我有一个具有BottomNavigationView和内容的脚手架。 On one of my screens, I have a filter button that navigates me to the FilterScreen .在我的一个屏幕上,我有一个过滤器按钮,可以将我导航到FilterScreen FilterScreen is a bottomSheet composable. FilterScreen是一个bottomSheet可组合的。 When I navigate to FilterScreen the result is :当我导航到FilterScreen时,结果是:

So as you can see when I click the filter button, the BottomNavigationView is hiding but the FilterScreen is not showing.因此,当我单击过滤器按钮时,您可以看到, BottomNavigationView正在隐藏,但FilterScreen未显示。 Here is the code :这是代码:

   val navController = rememberAnimatedNavController()
   val bottomSheetNavigator = rememberBottomSheetNavigator()
   val scaffoldState = rememberScaffoldState()

   navController.navigatorProvider += bottomSheetNavigator

   Scaffold(
            bottomBar = {
                if (isNavBarVisible) {
                    RubiBrandsBottomNavigationView(
                        onNavigateToTopLevelDestination = rubiBrandsTopLevelNavigation::navigateTo,
                        currentDestination = currentDestination,
                        topLevelDestinations = topLevelDestinations
                    )
                }
            },
            scaffoldState = scaffoldState
        ) {
            //navigation graph
            Box(
                modifier = Modifier
                    .padding(it)
            ) {
                NavGraph(
                    navController = navController,
                    bottomSheetNavigator = bottomSheetNavigator,
                    startDestination = startDestination,
                )
            }
        }


//Nav-Graph

@Composable
fun NavGraph(
    navController: NavHostController,
    bottomSheetNavigator: BottomSheetNavigator,
    modifier: Modifier = Modifier,
    startDestination: String
) {
    ModalBottomSheetLayout(
        sheetBackgroundColor = Color.White,
        bottomSheetNavigator = bottomSheetNavigator,
        sheetElevation = dimensionResource(id = R.dimen.dimen_4),
        sheetShape = RoundedCornerShape(dimensionResource(id = R.dimen.dimen_16))
    ) {
        AnimatedNavHost(
            navController = navController,
            startDestination = startDestination,
            route = ROOT_GRAPH
        ) {
            //auth graph
            authNavGraph(navController = navController, modifier = modifier)

            //main graph
            mainNavGraph(navController = navController)

        }
    }
}

//Filter Screen

fun NavGraphBuilder.addFilterScreen(
    navController: NavController
) {
    bottomSheet(
        route = Destination.FilterDestination.route
    ) {
        FilterScreen()
    }
}

I have tried to remove :我试图删除:

Scaffold(){padding->
   Box(
                modifier = Modifier
                    .padding(padding)
            ) {//content}
}

within my root Scaffold but in this case, the content of the screen is not fitting but the bottomSheet works as expected.在我的根Scaffold中,但在这种情况下,屏幕的内容不合适,但bottomSheet可以按预期工作。 Result is :结果是:

The bottomSheet come from accompanist material . bottomSheet来自伴奏材料

Accompanist Version:0.24.7-alpha伴奏版本:0.24.7-alpha

Compose Version: 1.2.0-rc02编写版本:1.2.0-rc02

I just move the ModalBottomSheetLayout out of the root Scaffold and wrap the Scaffold as its content and it worked.我只是将ModalBottomSheetLayout移出根Scaffold并将Scaffold包装为其内容并且它起作用了。 I'm not sure if this is correct or not but still works.我不确定这是否正确,但仍然有效。 Here is the code :这是代码:

  ModalBottomSheetLayout(
            bottomSheetNavigator = bottomSheetNavigator,
            sheetElevation = dimensionResource(id = R.dimen.dimen_4),
            sheetShape = RoundedCornerShape(dimensionResource(id = R.dimen.dimen_16))
        ) {
            Scaffold(
                bottomBar = {
                    if (isNavBarVisible) {
                        RubiBrandsBottomNavigationView(
                            onNavigateToTopLevelDestination = rubiBrandsTopLevelNavigation::navigateTo,
                            currentDestination = currentDestination,
                            topLevelDestinations = topLevelDestinations
                        )
                    }
                },
                scaffoldState = scaffoldState
            ) {
                //navigation graph
                Box(
                    modifier = Modifier
                        .padding(it)
                ) {
                    NavGraph(
                        navController = navController,
                        startDestination = startDestination,
                    )
                }
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM