Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 by navGraphViewModels #12

Open
Key-CN opened this issue Feb 3, 2021 · 1 comment
Open

关于 by navGraphViewModels #12

Key-CN opened this issue Feb 3, 2021 · 1 comment

Comments

@Key-CN
Copy link

Key-CN commented Feb 3, 2021

导航图是动态生成,那么by navGraphViewModels(R.id.xxxx)这个图内作用域共享的ViewModel是不是就没办法使用了?

@vitaviva
Copy link
Owner

vitaviva commented Feb 4, 2021

by navGrpahViewModes(R.id.xxxx) 一般用来获取前面已经入栈的节点的ViewModel,对于已经入栈的节点Graph中已经可以找到了,所以可以使用。但是这里确实有一个小问题:Fragivity中通常并不关心id(实际id是class的hash),所以通过id获取vm不够友好。后期会添加一个不通过id获取vm的API供大家使用。当然非必要的情况,推荐直接使用by activityViewModels()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants