Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Revert VC changes, do modal popover fixes #130
Browse files Browse the repository at this point in the history
Need to make sure it is over current context
  • Loading branch information
jamesmontemagno committed Nov 23, 2016
1 parent 8b06e59 commit e9b7f6b
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions src/Media.Plugin.iOS/MediaImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,36 +267,25 @@ private static MediaPickerController SetupController(MediaPickerDelegate mpDeleg
return picker;
}

/// <summary>
/// Gets the visible view controller.
/// </summary>
/// <returns>The visible view controller.</returns>
UIViewController GetVisibleViewController()
private Task<MediaFile> GetMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null)
{
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;

if (rootController.PresentedViewController == null)
return rootController;
UIWindow window = UIApplication.SharedApplication.KeyWindow;
if (window == null)
throw new InvalidOperationException("There's no current active window");

if (rootController.PresentedViewController is UINavigationController)
{
return ((UINavigationController)rootController.PresentedViewController).VisibleViewController;
}
UIViewController viewController = window.RootViewController;

if (rootController.PresentedViewController is UITabBarController)
if (viewController == null)
{
return ((UITabBarController)rootController.PresentedViewController).SelectedViewController;
window = UIApplication.SharedApplication.Windows.OrderByDescending(w => w.WindowLevel).FirstOrDefault(w => w.RootViewController != null);
if (window == null)
throw new InvalidOperationException("Could not find current view controller");
else
viewController = window.RootViewController;
}

return rootController.PresentedViewController;
}

private Task<MediaFile> GetMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null)
{


var viewController = GetVisibleViewController();

while (viewController.PresentedViewController != null)
viewController = viewController.PresentedViewController;

MediaPickerDelegate ndelegate = new MediaPickerDelegate(viewController, sourceType, options);
var od = Interlocked.CompareExchange(ref pickerDelegate, ndelegate, null);
Expand All @@ -312,7 +301,13 @@ private Task<MediaFile> GetMediaAsync(UIImagePickerControllerSourceType sourceTy
ndelegate.DisplayPopover();
}
else
{
if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
{
picker.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
}
viewController.PresentViewController(picker, true, null);
}

return ndelegate.Task.ContinueWith(t =>
{
Expand Down

0 comments on commit e9b7f6b

Please sign in to comment.