Skip to content

fix: improve hit testing logic for animated views in KRView#1050

Open
wwwcg wants to merge 2 commits intoTencent-TDS:mainfrom
wwwcg:main
Open

fix: improve hit testing logic for animated views in KRView#1050
wwwcg wants to merge 2 commits intoTencent-TDS:mainfrom
wwwcg:main

Conversation

@wwwcg
Copy link
Copy Markdown
Collaborator

@wwwcg wwwcg commented Feb 12, 2026

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates KRView’s hitTest:withEvent: override to better account for views that are mid-animation by incorporating presentation-layer position checks, while keeping Kuikly’s “touch penetration unless listeners exist” behavior aligned with Android.

Changes:

  • Adds hitAnimating detection using presentationLayer vs modelLayer geometry.
  • Prioritizes returning a hit subview before applying KRView’s penetration rules.
  • Applies penetration rules consistently for both normal hits and animation-compensated hits.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core-render-ios/Extension/Components/KRView.m Outdated
Comment on lines 188 to 200
UIView *hitView = [super hitTest:point withEvent:event];
_hitTesting = NO;
if (hitView == self) {

// 子视图命中,优先返回
if (hitView && hitView != self) {
return hitView;
}
// 自身命中(正常 hitTest 或动画位置补偿),统一走穿透判断
if (hitView == self || hitAnimating) {
// 对齐安卓事件机制,无手势事件监听则将手势穿透
if (!(self.gestureRecognizers.count > 0 || _css_touchUp || _css_touchMove || _css_touchDown)) {
return nil;
}
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

When hitAnimating is true but [super hitTest:point withEvent:] returns nil (common if the touch is within the presentation-frame but outside the model-frame), this implementation falls back to returning self/nil and never attempts to hit-test subviews at the animated position. That can make interactive subviews untouchable during movement animations. Consider doing a second pass that re-computes a point in self’s coordinate space based on the presentation layer geometry and re-running hit-testing for subviews before falling back to the penetration logic.

Copilot uses AI. Check for mistakes.
@wwwcg
Copy link
Copy Markdown
Collaborator Author

wwwcg commented Feb 12, 2026

resolve issue in #396

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/sidebar/zh.ts Outdated
Copilot AI added a commit that referenced this pull request Mar 27, 2026
When parent views are animating (e.g. shaking in edit mode), the old
hitTest immediately returned self without checking child views. This
prevented transparent overlays (zIndex 99) with touch handlers from
being hit-tested, contributing to the long press gesture issue.

The fix:
1. Separates animation detection from child hit testing
2. Always calls [super hitTest:] to check child views first
3. Prioritizes child view hits over animation compensation
4. Adds presentationLayer nil check and proper coordinate conversion

Agent-Logs-Url: https://github.com/Tencent-TDS/KuiklyUI/sessions/ba411884-ea52-4d3c-b4cf-ecfcef71ba11

Co-authored-by: wwwcg <5202686+wwwcg@users.noreply.github.com>
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.

2 participants