Skip to content

Conversation

@wyu71
Copy link
Contributor

@wyu71 wyu71 commented Jan 5, 2026

Added retry timer mechanism to reliably set focus after expand/collapse operations.

Log: improve focus handling after expand/collapse in NotifyView
pms: BUG-339891

Summary by Sourcery

Bug Fixes:

  • Ensure focus is reliably moved to the intended notification item after group expand or collapse using a retry-based focus mechanism.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 5, 2026

Reviewer's Guide

Implements a more reliable focus restoration mechanism in NotifyView after expand/collapse by introducing a retry-based timer that attempts to focus the intended list item once it becomes available, and wiring delegate expand/collapse handlers to use this new helper instead of manually tweaking nextIndex.

Sequence diagram for focus handling after expand in NotifyView

sequenceDiagram
    actor User
    participant NotifyViewDelegate
    participant NotifyModel
    participant View as NotifyViewListView
    participant Timer as ExpandFocusTimer
    participant Item as ListItem

    User->>NotifyViewDelegate: activate expand on notification
    NotifyViewDelegate->>NotifyModel: expandApp(expandIndex)
    NotifyViewDelegate->>View: requestFocusOnExpand(expandIndex_plus_1)

    Note over View: requestFocusOnExpand
    View->>View: pendingFocusIndex = idx
    View->>View: currentIndex = idx
    View->>View: positionViewAtIndex(idx, Contain)
    View->>Timer: set retries = 15
    View->>Timer: start()

    loop until focus set or retries exhausted
        Timer->>View: onTriggered
        View->>View: item = itemAtIndex(pendingFocusIndex)
        alt item exists and enabled
            View->>Item: forceActiveFocus()
            View->>View: pendingFocusIndex = -1
            Timer->>Timer: stop()
        else retries <= 0
            View->>View: pendingFocusIndex = -1
            Timer->>Timer: stop()
        else
            Timer->>Timer: retries--
        end
    end
Loading

Sequence diagram for focus handling after collapse in NotifyView

sequenceDiagram
    actor User
    participant NotifyViewDelegate
    participant NotifyModel
    participant View as NotifyViewListView
    participant Timer as ExpandFocusTimer
    participant Item as ListItem

    User->>NotifyViewDelegate: activate collapse on grouped notification
    NotifyViewDelegate->>NotifyViewDelegate: collapseIndex = index
    NotifyViewDelegate->>NotifyModel: collapseApp(index)
    NotifyViewDelegate->>View: requestFocusOnExpand(collapseIndex)

    Note over View: requestFocusOnExpand
    View->>View: pendingFocusIndex = idx
    View->>View: currentIndex = idx
    View->>View: positionViewAtIndex(idx, Contain)
    View->>Timer: set retries = 15
    View->>Timer: start()

    loop until focus set or retries exhausted
        Timer->>View: onTriggered
        View->>View: item = itemAtIndex(pendingFocusIndex)
        alt item exists and enabled
            View->>Item: forceActiveFocus()
            View->>View: pendingFocusIndex = -1
            Timer->>Timer: stop()
        else retries <= 0
            View->>View: pendingFocusIndex = -1
            Timer->>Timer: stop()
        else
            Timer->>Timer: retries--
        end
    end
Loading

Flow diagram for retry-based focus timer in NotifyView

flowchart TD
    A[start expand or collapse handler]
    A-->B["call requestFocusOnExpand(idx)"]
    B-->C[set pendingFocusIndex = idx]
    C-->D[set currentIndex = idx]
    D-->E["positionViewAtIndex(idx, Contain)"]
    E-->F[set expandFocusTimer.retries = 15]
    F-->G[start expandFocusTimer]

    subgraph TimerLoop[ExpandFocusTimer onTriggered]
        G-->H["retrieve item = view.itemAtIndex(pendingFocusIndex)"]
        H-->I{"item exists and item.enabled?"}
        I-- Yes -->J["call item.forceActiveFocus()"]
        J-->K[set pendingFocusIndex = -1]
        K-->L[stop timer]
        I-- No -->M{retries <= 0?}
        M-- Yes -->N[set pendingFocusIndex = -1]
        N-->L
        M-- No -->O[retries--]
        O-->H
    end
Loading

File-Level Changes

Change Details Files
Add a retry-based focus helper in the ListView to restore focus after expand/collapse operations.
  • Introduce pendingFocusIndex property on the ListView to track which index should receive focus after an expand/collapse operation.
  • Implement requestFocusOnExpand(idx) to set currentIndex, scroll the view, initialize retry count, and start a timer that will attempt to focus the target item.
  • Add expandFocusTimer Timer with configurable retry count and 50ms interval, which looks up the target item by pendingFocusIndex, forces active focus when the item is enabled, and clears state or gives up after retries are exhausted.
panels/notification/center/NotifyView.qml
Update expand/collapse delegate handlers to use the new focus helper instead of directly setting nextIndex.
  • In the collapse handler, capture the current delegate index before collapsing the app and call view.requestFocusOnExpand with that index to restore focus appropriately.
  • In the expand handler, replace direct assignment of nextIndex with a call to view.requestFocusOnExpand(expandIndex + 1) so focus moves to the first item after the expanded group.
panels/notification/center/NotifyViewDelegate.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 reviewed your changes and they look great!


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.

Added retry timer mechanism to reliably set focus after expand/collapse operations.

Log: improve focus handling after expand/collapse in NotifyView
pms: BUG-339891
@deepin-ci-robot
Copy link

deepin pr auto review

我来分析这段代码的修改:

  1. 功能改进:
  • 新增了在展开/折叠通知组后自动聚焦到相关项的功能
  • 使用定时器重试机制来确保焦点设置成功
  • 将原来的简单索引设置改为更可靠的聚焦请求机制
  1. 代码质量改进:
  • 引入了 pendingFocusIndex 属性来跟踪待聚焦的项
  • 使用 Timer 组件实现了重试机制
  • 代码结构更清晰,将聚焦逻辑封装在 requestFocusOnExpand 函数中
  1. 性能考虑:
  • 定时器间隔设置为 50ms,这是一个合理的值
  • 最多重试 15 次,可以避免无限重试
  • 一旦成功获取焦点就立即停止定时器
  1. 安全性改进:
  • 在尝试设置焦点前检查项是否存在且可用
  • 重试次数限制防止了潜在的无限循环
  • 重试失败后会清理状态

建议改进:

  1. 可以考虑将重试次数和间隔时间作为可配置参数
  2. 可以添加错误日志,帮助调试聚焦失败的情况
  3. 可以考虑添加一个超时机制,确保不会因为异常情况导致定时器一直运行

总体来说,这是一个很好的改进,提高了通知中心展开/折叠操作的可靠性和用户体验。代码结构清晰,考虑了各种边界情况,是一个可靠的实现。

@caixr23 caixr23 requested a review from 18202781743 January 6, 2026 02:24
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, wyu71

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

@wyu71
Copy link
Contributor Author

wyu71 commented Jan 6, 2026

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Jan 6, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 7b4ea55 into linuxdeepin:master Jan 6, 2026
10 of 11 checks passed
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