Jetpack Compose 脚手架 + 模态底片

Arr*_*row 1 android android-jetpack-compose

我正在尝试使用 Compose 设计一个布局,其中包括:

  1. 顶部应用栏
  2. 正文(内容)
  3. 底部应用栏
  4. 单击时表示菜单的底部工作表(模态底部工作表)

-------TopAppBar-------

------主要内容------

------底部应用栏-----

----ModalBottomSheet---

Compose 提供了 3 个组件:

  1. 脚手架
  2. 底片脚手架
  3. 模态底部图纸布局

脚手架没有底片属性

BottomSheetScaffold没有 BottomAppBar 属性

ModalBottomSheetLayout只有 content 和 sheetContent

Which of these components should I combine and in what **structure** to achieve what I want?

Scaffold(
  topBar = { TopBar() },
  content = { innerPadding -> Body(innerPadding) },
  bottomAppbar = { BottomAppBar() }
)
ModalBottomSheetLayout(
  sheetState = rememberModalBottomSheetState(
    initialValue = ModalBottomSheetValue.Hidden
  ),
  sheetContent = { SheetContent() },
)
BottomSheetScaffold(
  scaffoldState = ...,
  sheetContent = { SheetContent() },
  content = { ScreenContent() },
)
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 7

您可以使用以下内容:

val bottomState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
ModalBottomSheetLayout(
    sheetState = bottomState,
    sheetContent = {
        //. sheetContent
    }
) {
    Scaffold(
        scaffoldState = scaffoldState,
        topBar = {
            TopAppBar(
                title = {
                    Text(text = "TopAppBar")
                }
            )
        },
        bottomBar = {
            BottomAppBar(modifier = Modifier) {
                IconButton(
                    onClick = {
                        coroutineScope.launch { bottomState.show() }  
                    }
                ) {
                    Icon(Icons.Filled.Menu, contentDescription = "Localized description")
                }
            }
        },

        content = { innerPadding ->
            //...main content
        }
    )
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明