展开时更改 ModalDrawer 的大小,Jetpack Compose [英] Change the size of ModalDrawer when expanded, Jetpack Compose

本文介绍了展开时更改 ModalDrawer 的大小,Jetpack Compose的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to implement a drawer in my application but it's currently way to large. I'll clarify what I mean and I am aware of other questions but they don't seem to have gotten a proper answer and my usecase seems to differ a bit.

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

This is the code that has helped me achieve this

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

您可以忽略的子部分,它只是检查当前处于活动状态的屏幕(现在它是唯一的仪表板,但是当我向混合物添加屏幕时,它也会显示其他屏幕,并与我拥有的抽屉一起正常工作走这条路.)

the children part you can ignore, it just basically checks what screen is currently active (right now its only dashboard, but as I add screens to the mixture it will also feature other ones, and to work properly with the Drawer I had to go about this way.)

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

This is a multiplatform app, all of the compose code is in the CommonMain Module.

推荐答案

不,这是使用材料指南构建的,此大小不能更改

No, this was build using material guidelines and this size cannot be changed

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

But you can take source code of this composable and create your own modal drawer.

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

It'll take your some time, try copying all code from container file and you will be left to deal with a small number of internals

这篇关于展开时更改 ModalDrawer 的大小,Jetpack Compose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆