Skip to content

[layer][shape] fix stale shape on resize, harden external mask handling#8

Open
honghaoz wants to merge 1 commit into
masterfrom
layer-shape-mask-fixes
Open

[layer][shape] fix stale shape on resize, harden external mask handling#8
honghaoz wants to merge 1 commit into
masterfrom
layer-shape-mask-fixes

Conversation

@honghaoz

@honghaoz honghaoz commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix mask reverting to a stale shape: the live-frame block captured the shape at setup; it now reads the layer's current shape, so shape updates and animateShape survive later resizes.
  • Harden external mask manipulation: shape = nil no longer destroys a mask the shape API didn't install; setting/animating a shape reinstalls the shape-managed mask if the mask was removed or replaced externally; the previously installed mask layer is untracked to avoid a permanent leak.
  • Document the shape↔mask contract and all edge cases on shape; disable implicit animations for in-place mask path updates.

Test plan

  • swift test --filter CALayer_ShapeTests` (25 tests; 6 new regression tests, all verified to fail against the old implementation)

Summary by CodeRabbit

  • Bug Fixes

    • Improved shape masking when masks are removed or replaced externally.
    • Preserved user-installed masks when shapes are cleared or animated.
    • Ensured shape masks recalculate correctly after layer bounds changes.
    • Prevented incorrect mask animations and restored the correct shape mask when needed.
  • Tests

    • Added coverage for mask replacement, removal, bounds changes, and shape animation behavior.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

CALayer shape masking now tracks its managed mask layer, preserves externally installed masks, reinstalls managed masks when replaced, and updates paths using current shapes and bounds. Animation falls back to direct application when the installed mask is not shape-managed, with expanded regression tests.

Changes

Shape-managed mask tracking

Layer / File(s) Summary
Mask tracking and shape updates
ChouTiUI/Sources/ChouTiUI/Universal/CoreAnimation/CALayer+Shape.swift
Adds weak associated storage for the shape-managed mask and updates shape changes based on whether the current mask matches the tracked layer.
Mask setup and animation handling
ChouTiUI/Sources/ChouTiUI/Universal/CoreAnimation/CALayer+Shape.swift
Replaces stale tracked masks, recalculates paths during frame changes, and skips animation when an external mask is installed.
Shape mask behavior tests
ChouTiUI/Tests/ChouTiUITests/Universal/CoreAnimation/CALayer+ShapeTests.swift
Tests bounds changes, external mask preservation and replacement, stale-mask untracking, and direct shape application without path animation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CALayer
  participant ShapeManagedMask
  participant ExternalMask
  CALayer->>ExternalMask: External mask replacement
  CALayer->>ShapeManagedMask: Reinstall managed mask on shape update
  CALayer->>ShapeManagedMask: Apply target path directly when masks differ
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main changes: fixing stale shape behavior on resize and improving external mask handling.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch layer-shape-mask-fixes

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.87%. Comparing base (ddfb474) to head (fd1fdad).

Files with missing lines Patch % Lines
...ouTiUI/Universal/CoreAnimation/CALayer+Shape.swift 97.36% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #8      +/-   ##
==========================================
+ Coverage   95.79%   95.87%   +0.08%     
==========================================
  Files         120      120              
  Lines        4873     4900      +27     
==========================================
+ Hits         4668     4698      +30     
+ Misses        205      202       -3     
Flag Coverage Δ
ChouTiUI 95.87% <97.36%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ouTiUI/Universal/CoreAnimation/CALayer+Shape.swift 96.93% <97.36%> (-0.25%) ⬇️

... and 1 file with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant