leavesCZY / Matisse

A Image/Video Selector Implemented with Jetpack Compose(一个用 Jetpack Compose 实现的 Android 图片视频选择框架)
https://github.com/leavesCZY/Matisse/wiki
Apache License 2.0
768 stars 60 forks source link

compose 场景设置maxSelectable = 3 - state.imageList.size 时。具体操作详见desc #73

Closed ZHLhenry closed 1 week ago

ZHLhenry commented 2 weeks ago

设置maxSelectable = 3 - state.imageList.size时。 1:先选择2张照片确认,此时maxSelectable = 1
2:在此吊起图库,选择1张,点击确定,就崩溃了“maxSelectable must be greater than or equal to 1”

这个有啥解决思路么?

ZHLhenry commented 2 weeks ago

不太没明白,为啥点击图库里面确认按钮,会触发 init { if (maxSelectable < 1) { throw IllegalArgumentException("maxSelectable must be greater than or equal to 1") } if (maxSelectable > 1 && fastSelect) { throw IllegalArgumentException("fastSelect must be false") } }

leavesCZY commented 2 weeks ago

没看太懂你的描述,你要检查你的逻辑哪里导致了 maxSelectable 值会小于1

ZHLhenry commented 2 weeks ago

我知道原因了,是compose state刷新机制导致的。 state.imageList.size这个我是动态设置的。

ZHLhenry commented 2 weeks ago

所以,点击图库的确认后,state.imageList.size值改变了,引起了maxSelectable的改变。maxSelectable = if (3 - state.images.size == 0) 1 else 3 - state.images.size, 这样就可以了

ZHLhenry commented 2 weeks ago

提一个优化需求:用户选择了2个照片。下次拉起图库,可否默认就选中已经选择的照片啊

leavesCZY commented 2 weeks ago

这个目前就是已经支持的了,你看 wiki,里面写的 MediaFilter 就可以用于实现你要的效果

image

ZHLhenry commented 2 weeks ago

好滴好滴