fix: improve hit testing logic for animated views in KRView#1050
fix: improve hit testing logic for animated views in KRView#1050wwwcg wants to merge 2 commits intoTencent-TDS:mainfrom
Conversation
There was a problem hiding this comment.
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
hitAnimatingdetection usingpresentationLayervsmodelLayergeometry. - 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.
| 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; | ||
| } |
There was a problem hiding this comment.
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.
|
resolve issue in #396 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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.
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>
No description provided.