Skip to content

fix(ios): prevent duplicate cancel callbacks in image picker - #11

Closed
kosmydel wants to merge 1 commit into
4.7.1-discord-2from
kosmydel/fix-image-crash
Closed

fix(ios): prevent duplicate cancel callbacks in image picker#11
kosmydel wants to merge 1 commit into
4.7.1-discord-2from
kosmydel/fix-image-crash

Conversation

@kosmydel

@kosmydel kosmydel commented Jun 2, 2026

Copy link
Copy Markdown

I don't have a repro; this is a bit of a guess at a fix for the Sentry issue

AI-driven repro scenario when it could happen:

The race requires the async photo load to still be in-flight when the dismiss fires — it won't happen on fast local photos.

  1. Use an iCloud photo that is not downloaded locally (look for the cloud icon in Photos).
  2. Enable New Architecture (NOBRIDGE mode).
  3. Open the image picker, tap the iCloud photo to select it, then immediately swipe down before the download completes.
  4. Without the patch: the dispatch_group_notify block fires after presentationControllerDidDismiss: has already consumed the callback → crash.
  5. With the patch: presentationControllerDidDismiss: sets photoSelected = YES; the notify block early-returns → no crash.

@kosmydel kosmydel changed the title fix(ios): prevent double RCTResponseSenderBlock invocation in image p… fix(ios): prevent duplicate cancel callbacks in image picker Jun 2, 2026
@kosmydel
kosmydel requested review from SzymczakJ and Copilot June 2, 2026 14:23

Copilot AI 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.

Pull request overview

This PR updates the iOS implementation of react-native-image-picker to prevent duplicate “cancel” callbacks (and the resulting crash) when the picker is dismissed while async photo loading is still in-flight.

Changes:

  • Introduces a photoSelected flag to ensure the callback is only consumed once per picker session.
  • Adds early-return guards in imagePickerControllerDidCancel: and presentationControllerDidDismiss: to avoid duplicate cancel emissions.

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

Comment thread ios/ImagePickerManager.m
@kosmydel kosmydel closed this Jun 3, 2026
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