【问题标题】:Change the size of ModalDrawer when expanded, Jetpack Compose展开时更改 ModalDrawer 的大小,Jetpack Compose
【发布时间】:2021-10-14 23:48:45
【问题描述】:

我正在尝试在我的应用程序中实现一个抽屉,但它目前太大了。我会澄清我的意思,我知道其他问题,但他们似乎没有得到正确的答案,我的用例似乎有点不同。

这是帮助我实现这一目标的代码

@Composable
fun MainContent(component: Main) {

    val drawerState = rememberDrawerState(DrawerValue.Closed)
    val scope = rememberCoroutineScope()

    val openDrawer = {
        scope.launch {
            drawerState.open()
        }
    }

    Children(routerState = component.routerState, animation = crossfadeScale()) {
        when (val child = it.instance) {
            is Main.Child.Dashboard -> {
               HomeView() { ModalDrawer(drawerState) { DashboardContent(child.component) { openDrawer() } } }
            }
        }
    }
}

@Composable  // This is a wrapper around current screen
fun HomeView( content: @Composable () -> Unit) {
    Scaffold(modifier = Modifier.fillMaxSize()) {
        content()
    }
}

@Composable // Here is the actual drawer
fun ModalDrawer(drawerState: DrawerState, content: @Composable () -> Unit) {
    ModalDrawer(
        drawerState = drawerState,
        drawerContent = {
            Text("1234")
            Text("12345")
        },
        content = {
            content()
        },
        gesturesEnabled = drawerState.isOpen
    )
}

您可以忽略的子部分,它基本上只是检查当前处于活动状态的屏幕(现在它是唯一的仪表板,但是当我将屏幕添加到混合物中时,它还将具有其他屏幕,并且可以与我的抽屉正常工作走这条路。)

这是一个多平台的应用程序,所有的撰写代码都在 CommonMain 模块中。

【问题讨论】:

    标签: android material-design navigation-drawer android-jetpack-compose kotlin-multiplatform


    【解决方案1】:

    不,这是使用材料指南构建的,此尺寸无法更改

    但是你可以获取这个可组合的源代码并创建你自己的模态抽屉。

    这需要您一些时间,尝试从容器文件中复制所有代码,您将需要处理少量内部问题

    【讨论】:

    • 啊该死的,这有点糟糕。也许他们会在未来添加对调整大小的支持
    • @Nikola-Milovic 我对此表示怀疑,但您可以尝试在issue tracker 上创建问题,以便他们看到有需要
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 2022-07-26
    • 1970-01-01
    • 2021-07-18
    • 2022-11-06
    相关资源
    最近更新 更多