Skip to content

Commit 6f3e6b3

Browse files
✨ Raise GMImagePickerController.Canceled when the view is closed by pulling it down on iOS 13 (#75)
* This will raise GMImagePickerController.Canceled when the view is closed by pulling it down on iOS 13. See #74 * Update nuget Co-authored-by: Roy Cornelissen <[email protected]>
1 parent dcacab0 commit 6f3e6b3

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/GMImagePicker/GMImagePickerController.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

src/GMPhotoPicker.Xamarin.UITests/GMPhotoPicker.Xamarin.UITests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
3636
</Reference>
3737
<Reference Include="Xamarin.UITest">
38-
<HintPath>..\packages\Xamarin.UITest.3.0.4\lib\net45\Xamarin.UITest.dll</HintPath>
38+
<HintPath>..\packages\Xamarin.UITest.3.0.7\lib\net45\Xamarin.UITest.dll</HintPath>
3939
</Reference>
4040
</ItemGroup>
4141
<ItemGroup>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="NUnit" version="3.12.0" targetFramework="net45" />
4-
<package id="Xamarin.UITest" version="3.0.4" targetFramework="net45" />
4+
<package id="Xamarin.UITest" version="3.0.7" targetFramework="net45" />
55
</packages>

0 commit comments

Comments
 (0)