简体   繁体   English

Jetpack compose 多屏幕中的底部表单

[英]Jetpack compose Bottom sheet in multi screens

What is the best way to implement bottom sheet for multiple screens in jetpack compose?在 Jetpack Compose 中为多个屏幕实现底页的最佳方法是什么? Do we have to define Bottom sheet layout in each screen?我们是否必须在每个屏幕中定义 Bottom sheet 布局? Then what to do if we wanted our bottom sheet to overlap on bottom nav bar?那么如果我们希望我们的底部工作表重叠在底部导航栏上怎么办?

You can create a custom layout like您可以创建自定义布局,例如

MyAppCustomLayout(
  showBottomBar: Boolean = false, 
  state: ModalBottomSheetState = ModalBottomSheetState(initialValue = 
  ModalBottomSheetValue.Hidden),
  sheetContent: @Composable () -> Unit = {},
  content: @Composable () -> Unit)
{
  ModalBottomSheetLayout(
    sheetState = state,
    sheetContent = { sheetContent() })
  {
    Scaffold(
      bottomBar = if(showBottomBar)
      {{
        YourBottomNavigationView()
      }}
      else {{}})
    { content() }
  }
}

And use it anywhere in your app like below.并在您的应用程序中的任何位置使用它,如下所示。

val state = rememberModalBottomSheetState()

MyAppCustomLayout(
  state = state,
  sheetcontent = { 
    Column {
      Text("Some bottomSheet content")
    }
  })
{ 
  Column {
    Text("Some content")
  }
}

If you are using Jetpack Navigation Compose in your project, you might consider using Jetpack Navigation Compose Material to implement it.如果您在项目中使用Jetpack Navigation Compose ,您可以考虑使用Jetpack Navigation Compose Material来实现它。

For more detail, refer to the samples有关更多详细信息,请参阅示例

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

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