Jetpack Compose 脚手架 + 模态底片

时间:2021-05-28 19:13:01

标签: android android-jetpack-compose

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

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

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

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

------BottomAppBar-----

----ModalBottomSheet---

Compose 提供 3 个组件:

  1. 脚手架
  2. BottomSheetScaffold
  3. ModalBottomSheetLayout

脚手架没有底片属性

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() },
)

1 个答案:

答案 0 :(得分:4)

您可以使用以下内容:

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
        }
    )
}

enter image description here