Skip to content

feat: improve scrollbar animation and state management#536

Merged
18202781743 merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-325887
Oct 13, 2025
Merged

feat: improve scrollbar animation and state management#536
18202781743 merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-325887

Conversation

@wjyrich

@wjyrich wjyrich commented Oct 13, 2025

Copy link
Copy Markdown
Contributor
  1. Added hideWidthDuration property to control scrollbar width animation timing
  2. Implemented __calculateStateConditions function to centralize state logic
  3. Replaced complex when conditions with state-based approach using __currentState
  4. Added proper state change handlers for hovered, pressed, active and size properties
  5. Enhanced hide transition with width animation before opacity fade
  6. This improves scrollbar behavior consistency and reduces flickering during state changes

feat: 改进滚动条动画和状态管理

  1. 添加 hideWidthDuration 属性控制滚动条宽度动画时间
  2. 实现 __calculateStateConditions 函数集中处理状态逻辑
  3. 使用 __currentState 替换复杂的 when 条件,采用基于状态的方法
  4. 为 hovered、pressed、active 和 size 属性添加适当的状态变化处理程序
  5. 在隐藏过渡中添加宽度动画,在透明度淡出之前执行
  6. 这提高了滚动条行为的一致性,减少了状态变化期间的闪烁问题

PMS: BUG-283687 BUG-325887

1. Added hideWidthDuration property to control scrollbar width animation
timing
2. Implemented __calculateStateConditions function to centralize state
logic
3. Replaced complex when conditions with state-based approach using
__currentState
4. Added proper state change handlers for hovered, pressed, active and
size properties
5. Enhanced hide transition with width animation before opacity fade
6. This improves scrollbar behavior consistency and reduces flickering
during state changes

feat: 改进滚动条动画和状态管理

1. 添加 hideWidthDuration 属性控制滚动条宽度动画时间
2. 实现 __calculateStateConditions 函数集中处理状态逻辑
3. 使用 __currentState 替换复杂的 when 条件,采用基于状态的方法
4. 为 hovered、pressed、active 和 size 属性添加适当的状态变化处理程序
5. 在隐藏过渡中添加宽度动画,在透明度淡出之前执行
6. 这提高了滚动条行为的一致性,减少了状态变化期间的闪烁问题

PMS: BUG-283687 BUG-325887

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @wjyrich, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

deepin-ci-robot added a commit to linuxdeepin/dtk6declarative that referenced this pull request Oct 13, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#536
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

我对这段代码审查如下:

  1. 语法逻辑:
  • 新增的 __currentState 属性和 __calculateStateConditions() 函数将原本分散在各个状态中的条件判断集中管理,提高了代码的可维护性。
  • 使用数字状态码(0-3)替代了原本的布尔表达式,使状态判断更加清晰直观。
  • 使用 Qt.callLater() 确保状态更新在下一个事件循环中执行,避免了潜在的状态竞争问题。
  1. 代码质量:
  • 改进后的代码结构更清晰,将复杂的条件判断逻辑封装在单独的函数中,提高了代码的可读性。
  • 状态定义更加统一,都使用 __currentState 进行判断,保持了代码风格的一致性。
  • 将状态计算逻辑与UI渲染逻辑分离,遵循了单一职责原则。
  1. 代码性能:
  • 使用 Qt.callLater() 可能会带来轻微的性能开销,但这是为了确保状态更新的正确性,是可以接受的。
  • 状态集中管理后,减少了重复的条件判断,可能会带来轻微的性能提升。
  • 建议考虑对频繁触发的事件(如hovered)进行防抖处理,以避免过多的状态计算。
  1. 代码安全:
  • 代码中使用了明确的类型定义(property int),避免了潜在的类型安全问题。
  • 状态判断逻辑更加严谨,通过 __calculateStateConditions() 函数确保所有状态条件都被正确处理。
  • 使用 Qt.callLater() 确保状态更新的顺序性,避免了潜在的竞态条件。

改进建议:

  1. 考虑将 __calculateStateConditions() 函数中的条件判断提取为单独的函数或常量,以提高代码的可读性。
  2. 可以考虑添加注释,说明 __currentState 的各个数值对应的具体状态。
  3. 对于 hide 状态的 transition,建议明确指定 to 属性的值,例如 to: 0,以保持一致性。
  4. 考虑添加边界检查,确保 __currentState 的值始终在有效范围内(0-3)。
  5. 可以考虑将状态相关的常量定义提取为枚举或常量,例如:
readonly property int STATE_HIDE: 0
readonly property int STATE_NORMAL: 1
readonly property int STATE_HOVER: 2
readonly property int STATE_ACTIVE: 3

总体而言,这次改进提高了代码的可维护性和可读性,同时保持了原有的功能不变。通过集中管理状态逻辑,使得代码更加健壮和易于理解。

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@18202781743 18202781743 merged commit 0d09e8a into linuxdeepin:master Oct 13, 2025
17 of 20 checks passed
18202781743 pushed a commit to linuxdeepin/dtk6declarative that referenced this pull request Oct 13, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#536
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