有没有办法从传入的修饰符中检索值? [英] Is there a way to retrieve values from the passed-in Modifier?

查看:35
本文介绍了有没有办法从传入的修饰符中检索值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个以修饰符作为参数的组合.虽然我不认为这是可能的,但是有没有一种方法可以检索传递给这个修饰符的值?

I create a composable with a Modifier as a parameter. Although I do not think that this would be possible, but is there anyway a method by which I can retrieve the values passed in to this modifier?

{
 mComp(Modifier.height(100.dp).width(100.dp))
}

@Composable
fun mComp(modifier: Modifier){ // Yeah I know Composable names should start with a Cap Letter
 //Retrieve the height and width here. How?
}

推荐答案

这是不可能的,这是故意的.例如,在协程 flow 中,您无法在收集器中查询是否应用了 filter,它是不透明的,同样适用于修饰符.如果您想从修饰符中检索一些参数,您可以创建自定义的参数,这篇文章 展示了如何做到这一点

This is not possible and it is intentional. For instance, in a coroutine flow you can't query in the collector whether a filter was applied or not, it's opaque, and the same applies to modifiers. If you want to retrieve some argument from a modifier you can create your custom one, this article shows how to do so

这篇关于有没有办法从传入的修饰符中检索值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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