@@ -47,8 +47,13 @@ public class GMImagePickerController: UIViewController
4747 public static readonly CGSize PopoverContentSize = new CGSize ( 480 , 720 ) ;
4848
4949 internal UINavigationController _navigationController ;
50- private GMAlbumsViewController _albumsViewController ;
51-
50+ private GMAlbumsViewController _albumsViewController ;
51+
52+ /// <summary>
53+ /// Inhibits raising of the Canceled event on ViewDidDisappear
54+ /// </summary>
55+ private bool _finishedPickingAssets ;
56+
5257 /// <summary>
5358 /// Contains the selected 'PHAsset' objects. The order of the objects is the selection order.
5459 /// You can add assets before presenting the picker to show the user some preselected assets.
@@ -355,14 +360,14 @@ public void Dismiss (object sender, EventArgs args)
355360 // Explicitly unregister observers because we cannot predict when the GC cleans up
356361 Unregister ( ) ;
357362
358- Canceled ? . Invoke ( this , EventArgs . Empty ) ;
359-
360363 PresentingViewController ? . DismissViewController ( true , null ) ;
361364 }
362365
363366 public void FinishPickingAssets ( object sender , EventArgs args )
364367 {
365- // Explicitly unregister observers because we cannot predict when the GC cleans up
368+ _finishedPickingAssets = true ;
369+
370+ // Explicitly unregister observers because we cannot predict when the GC cleans up
366371 Unregister ( ) ;
367372
368373 FinishedPickingAssets ? . Invoke ( this , new MultiAssetEventArgs ( _selectedAssets . ToArray ( ) ) ) ;
@@ -688,7 +693,9 @@ public sealed override async void ViewWillAppear (bool animated)
688693 await _viewDidLoadAsyncTask ;
689694 base . ViewWillAppear ( animated ) ;
690695
691- // Ensure nav and toolbar customisations are set. Defaults are in place, but the user may have changed them
696+ _finishedPickingAssets = false ;
697+
698+ // Ensure nav and toolbar customisations are set. Defaults are in place, but the user may have changed them
692699 View . BackgroundColor = PickerBackgroundColor ;
693700
694701 _navigationController . Toolbar . Translucent = true ;
@@ -720,7 +727,15 @@ public sealed override async void ViewWillAppear (bool animated)
720727 //Handle
721728 }
722729 }
723-
730+
731+ public override void ViewDidDisappear ( bool animated )
732+ {
733+ base . ViewDidDisappear ( animated ) ;
734+
735+ if ( ( IsBeingDismissed || IsMovingFromParentViewController ) && ! _finishedPickingAssets )
736+ Canceled ? . Invoke ( this , EventArgs . Empty ) ;
737+ }
738+
724739 /// <summary>
725740 /// Checks if access to the Camera is granted, and if not (Denied), shows an error message.
726741 /// </summary>
0 commit comments