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

拖拽替换回调问题 #447

Closed
chenzz66 opened this issue Jun 17, 2024 · 5 comments
Closed

拖拽替换回调问题 #447

chenzz66 opened this issue Jun 17, 2024 · 5 comments
Labels
提议 New feature or request

Comments

@chenzz66
Copy link

问题描述

拖拽回调事件
DefaultItemTouchCallback中onDrag第一次交换后松手没问题
如果第二次只是长按立马松开还是会触发onDrag事件,两个item还是上次交换的item
这个时候是否可以在onDrag后把sourceViewHolder, targetViewHolder置为null呢

期望结果

在不进行交换的时候不触发onDrag事件

如何复现

第二次只是长按立马松开

希望快速解决请Fork仓库复现问题并附上链接, 否则只能等有空才能排查
凭空猜测只会让问题晦涩难懂, 浪费本项目可持续维护时间

截图

异常堆栈信息或者手机截图/视频(拖拽到输入框即可上传)

版本

  • BRV:1.5.8
  • Android:11
  • Gradle: 8.6
  • Android Studio:Android Studio Jellyfish | 2023.3.1 RC 2
@liangjingkanji
Copy link
Owner

感觉你说的解决方案可以, 如果你有空或者希望成为brv贡献者可以提一个pr

如果没想法我有空会发布该版本

@liangjingkanji liangjingkanji added the Bug Something isn't working label Jun 19, 2024
@liangjingkanji
Copy link
Owner

liangjingkanji commented Jul 15, 2024

无法复现你描述的问题, 你录屏看下吧

    /**
     * 拖拽移动超过其他item时, 其返回值表示是否已经拖拽替换(会触发函数onMoved)
     * @return 返回false 禁止被拖拽交换移动
     */
    override fun onMove(
        recyclerView: RecyclerView,
        source: RecyclerView.ViewHolder,
        target: RecyclerView.ViewHolder,
    ): Boolean

理论上你没有超过其他item不会回调onMove

@liangjingkanji liangjingkanji added 无法复现 This doesn't seem right and removed Bug Something isn't working labels Jul 15, 2024
@chenzz66
Copy link
Author

无法复现你描述的问题, 你录屏看下吧

    /**
     * 拖拽移动超过其他item时, 其返回值表示是否已经拖拽替换(会触发函数onMoved)
     * @return 返回false 禁止被拖拽交换移动
     */
    override fun onMove(
        recyclerView: RecyclerView,
        source: RecyclerView.ViewHolder,
        target: RecyclerView.ViewHolder,
    ): Boolean

理论上你没有超过其他item不会回调onMove

20240716_102457.mp4

没有拖拽交换移动也触发了onDrag事件

@liangjingkanji
Copy link
Owner

原来是错误触发onDrag, 我理解有误了

@liangjingkanji
Copy link
Owner

liangjingkanji commented Jul 16, 2024

已经修复发布了

通过记录拖拽起始位置, 实现拖拽起始位置等于目标位置则属于无效移动, 不回调onDrag方法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
提议 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants