Skip to content

Commit

Permalink
✨ Raise GMImagePickerController.Canceled when the view is closed by p…
Browse files Browse the repository at this point in the history
…ulling 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]>
  • Loading branch information
ThomasHilbertAtCervis and roycornelissen authored Jul 17, 2020
1 parent dcacab0 commit 6f3e6b3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
29 changes: 22 additions & 7 deletions src/GMImagePicker/GMImagePickerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ public class GMImagePickerController: UIViewController
public static readonly CGSize PopoverContentSize = new CGSize(480, 720);

internal UINavigationController _navigationController;
private GMAlbumsViewController _albumsViewController;

private GMAlbumsViewController _albumsViewController;

/// <summary>
/// Inhibits raising of the Canceled event on ViewDidDisappear
/// </summary>
private bool _finishedPickingAssets;

/// <summary>
/// Contains the selected 'PHAsset' objects. The order of the objects is the selection order.
/// You can add assets before presenting the picker to show the user some preselected assets.
Expand Down Expand Up @@ -355,14 +360,14 @@ public void Dismiss (object sender, EventArgs args)
// Explicitly unregister observers because we cannot predict when the GC cleans up
Unregister ();

Canceled?.Invoke(this, EventArgs.Empty);

PresentingViewController?.DismissViewController (true, null);
}

public void FinishPickingAssets (object sender, EventArgs args)
{
// Explicitly unregister observers because we cannot predict when the GC cleans up
_finishedPickingAssets = true;

// Explicitly unregister observers because we cannot predict when the GC cleans up
Unregister ();

FinishedPickingAssets?.Invoke(this, new MultiAssetEventArgs(_selectedAssets.ToArray()));
Expand Down Expand Up @@ -688,7 +693,9 @@ public sealed override async void ViewWillAppear (bool animated)
await _viewDidLoadAsyncTask;
base.ViewWillAppear (animated);

// Ensure nav and toolbar customisations are set. Defaults are in place, but the user may have changed them
_finishedPickingAssets = false;

// Ensure nav and toolbar customisations are set. Defaults are in place, but the user may have changed them
View.BackgroundColor = PickerBackgroundColor;

_navigationController.Toolbar.Translucent = true;
Expand Down Expand Up @@ -720,7 +727,15 @@ public sealed override async void ViewWillAppear (bool animated)
//Handle
}
}


public override void ViewDidDisappear(bool animated)
{
base.ViewDidDisappear(animated);

if ((IsBeingDismissed || IsMovingFromParentViewController) && !_finishedPickingAssets)
Canceled?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Checks if access to the Camera is granted, and if not (Denied), shows an error message.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Xamarin.UITest">
<HintPath>..\packages\Xamarin.UITest.3.0.4\lib\net45\Xamarin.UITest.dll</HintPath>
<HintPath>..\packages\Xamarin.UITest.3.0.7\lib\net45\Xamarin.UITest.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/GMPhotoPicker.Xamarin.UITests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.12.0" targetFramework="net45" />
<package id="Xamarin.UITest" version="3.0.4" targetFramework="net45" />
<package id="Xamarin.UITest" version="3.0.7" targetFramework="net45" />
</packages>

0 comments on commit 6f3e6b3

Please sign in to comment.