Skip to content

fix: Make the photo library change observer more resilient#79

Merged
sigsbeym merged 1 commit intomasterfrom
batch-update-fix
Feb 23, 2026
Merged

fix: Make the photo library change observer more resilient#79
sigsbeym merged 1 commit intomasterfrom
batch-update-fix

Conversation

@iirovi-rs
Copy link
Collaborator

This changeset is pretty much fully AI generated, but it should address a (rare) crash we're seeing in Crashlytics, and it should be quite safe.

AI Summary:

This pull request improves the handling of incremental updates in the photo library gallery and enhances the robustness of the collection view updates. The main changes ensure that updates are only performed when the view is active, address potential data source mismatches, and correctly account for camera button offsets during batch updates.

Improvements to collection view update logic:

  • Added a check to ensure that incremental updates are only performed when the collection view is part of the window hierarchy, preventing unnecessary updates when the view is not visible.
  • Introduced validation to confirm the data source count matches the expected count from PHChange before applying incremental updates, with a fallback to full reload if mismatched.

Correct handling of camera button offset:

  • Modified batch update methods to correctly offset index paths when the gallery camera button is enabled, ensuring inserts, deletes, and reloads are accurately mapped. [1] [2]

Enhancement to index path calculation:

  • Updated the aapl_indexPathsFromIndexesWithSection extension in IndexSet+Extensions.swift to support an optional offset parameter, allowing flexible index path generation for collection view updates.

Copilot AI review requested due to automatic review settings February 13, 2026 21:45
@cursor
Copy link

cursor bot commented Feb 13, 2026

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on March 5.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link

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

This pull request enhances the photo library change observer to handle incremental updates more robustly, addressing rare crashes in the collection view update logic. The changes add defensive guards, data source validation, and correct camera button offset handling throughout the update flow.

Changes:

  • Added guard to prevent collection view updates when the view is not in the window hierarchy
  • Introduced data source count validation before performing incremental updates, with fallback to full reload on mismatch
  • Moved fetchResult update inside performBatchUpdates block to ensure collection view sees consistent state during batch operations
  • Applied camera button offset to all index path conversions (inserts, deletes, reloads) when gallery camera button is enabled
  • Removed unnecessary reloadData() call in completion block when no changes are detected
  • Updated aapl_indexPathsFromIndexesWithSection helper to accept an optional offset parameter

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Source/Pages/Gallery/YPLibrary+LibraryChange.swift Enhanced photo library change handling with view hierarchy checks, data validation, and correct camera button offset application
Source/Helpers/Extensions/IndexSet+Extensions.swift Added offset parameter to index path conversion helper method

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

@sigsbeym sigsbeym merged commit 577bc5b into master Feb 23, 2026
9 of 10 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.

4 participants