Skip to content

Conversation

@pengfeixx
Copy link
Contributor

@pengfeixx pengfeixx commented Dec 30, 2025

Fix abnormal animation for two-finger swipe

Log: Fix abnormal animation for two-finger swipe
pms: BUG-343525

Summary by Sourcery

Bug Fixes:

  • Prevent abnormal flick animation when initiating a two-finger swipe without an active drag gesture.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 30, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds drag state tracking to the fullscreen list view to prevent unintended flick animations when a two-finger swipe begins, ensuring the content position stays in sync with the current index unless a real drag is in progress.

Sequence diagram for two-finger swipe handling and flick cancellation

sequenceDiagram
    actor User
    participant TouchSystem
    participant FullscreenFrame
    participant ListviewPage

    User->>TouchSystem: two_finger_swipe_start
    TouchSystem->>FullscreenFrame: touch_events
    FullscreenFrame->>ListviewPage: process_touch_events

    alt no_real_drag_in_progress
        ListviewPage->>ListviewPage: onFlickStarted
        ListviewPage->>ListviewPage: check isDragging == false
        ListviewPage->>ListviewPage: cancelFlick()
        ListviewPage->>ListviewPage: set contentX = currentIndex * width
    else real_drag_in_progress
        ListviewPage->>ListviewPage: onDragStarted
        ListviewPage->>ListviewPage: set isDragging = true
        ListviewPage->>ListviewPage: allow normal flick animation
    end

    User-->>TouchSystem: release_gesture
    TouchSystem-->>FullscreenFrame: drag_end_event
    FullscreenFrame->>ListviewPage: onDragEnded
    ListviewPage->>ListviewPage: set isDragging = false
Loading

Updated class diagram for FullscreenFrame list view drag state

classDiagram
    class FullscreenFrame {
    }

    class Indicator {
        int currentIndex
    }

    class ListviewPage {
        bool interactive
        int currentIndex
        bool isDragging
        int contentX
        int width
        void setCurrentIndex(index)
        void onFlickStarted()
        void onDragStarted()
        void onDragEnded()
    }

    FullscreenFrame --> ListviewPage : contains
    FullscreenFrame --> Indicator : contains
    Indicator --> ListviewPage : syncs_currentIndex
Loading

File-Level Changes

Change Details Files
Guard the list view flick behavior with an explicit drag state so that flicks are canceled when a swipe starts without an active drag, fixing abnormal two-finger swipe animations.
  • Introduce an isDragging boolean property on the list view to track whether a drag gesture is active.
  • On flick start, cancel the flick and reset contentX to the page corresponding to currentIndex when no drag is active to avoid desynchronized animations.
  • Set isDragging to true on drag start and false on drag end to correctly reflect the current gesture state.
qml/FullscreenFrame.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider using the built-in ListView drag/flick state properties (e.g., drag.active or flicking) instead of maintaining a separate isDragging flag to reduce the risk of state getting out of sync.
  • You may want to explicitly reset isDragging when the view becomes non-interactive or is reinitialized (e.g., on interactive changes or component destruction) to avoid a stale true state after lifecycle changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider using the built-in `ListView` drag/flick state properties (e.g., `drag.active` or `flicking`) instead of maintaining a separate `isDragging` flag to reduce the risk of state getting out of sync.
- You may want to explicitly reset `isDragging` when the view becomes non-interactive or is reinitialized (e.g., on `interactive` changes or component destruction) to avoid a stale `true` state after lifecycle changes.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Fix abnormal animation for two-finger swipe

Log: Fix abnormal animation for two-finger swipe
pms: BUG-343525
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码的修改进行审查:

  1. 语法逻辑:
  • 代码语法正确,QML的属性和信号处理器使用规范
  • 添加了isDragging状态变量来跟踪拖拽状态
  • 通过onFlickStarted、onDragStarted和onMovementEnded三个信号处理器来管理拖拽状态
  1. 代码质量:
  • 优点:
    • 使用了清晰的状态变量命名(isDragging)
    • 状态管理逻辑清晰
  • 可改进之处:
    • 缺少对isDragging变量的注释说明其用途
    • onFlickStarted中的逻辑可能需要更详细的注释说明为什么需要取消flick并重置contentX
  1. 代码性能:
  • 使用Qt.binding()来动态绑定currentIndex,这是正确的做法
  • 没有明显的性能问题,但建议检查频繁的contentX更新是否会影响性能
  1. 代码安全:
  • 代码本身没有明显的安全问题
  • 建议添加对contentX的边界检查,确保不会越界

改进建议:

property bool isDragging: false  // 标记当前是否处于拖拽状态

onFlickStarted: {
    // 如果不在拖拽状态,则取消快速滑动并重置到当前位置
    if (!isDragging) {
        cancelFlick()
        // 确保contentX在有效范围内
        contentX = Math.max(0, Math.min(currentIndex * width, contentWidth - width))
    }
}

onDragStarted: {
    isDragging = true
}

onMovementEnded: {
    isDragging = false
}

function setCurrentIndex(index) {
    // 确保索引在有效范围内
    index = Math.max(0, Math.min(index, count - 1))
    listviewPage.currentIndex = index
    // 使用绑定保持与indicator同步
    listviewPage.currentIndex = Qt.binding(function() { return indicator.currentIndex })
}

主要改进:

  1. 添加了注释说明代码逻辑
  2. 在设置contentX时添加了边界检查
  3. 在setCurrentIndex函数中添加了索引范围检查
  4. 保持了原有的功能不变,但增加了安全性检查

这些改进可以提高代码的可维护性和健壮性,同时保持原有功能不变。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@BLumia BLumia merged commit ac4d86c into linuxdeepin:master Dec 30, 2025
9 of 10 checks passed
@pengfeixx pengfeixx deleted the fix-343525 branch December 30, 2025 08:41
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

Successfully merging this pull request may close these issues.

3 participants