Skip to content
Permalink
Browse files
[iOS] Update the presentation style of the photo picker
https://bugs.webkit.org/show_bug.cgi?id=240926
rdar://89670039

Reviewed by Wenson Hsieh.

The photo picker should no longer be displayed as a popover. Instead, let UIKit
decide the modal presentation style.

* Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm:
(-[WKFileUploadPanel dealloc]):
(-[WKFileUploadPanel dismiss]):
(-[WKFileUploadPanel _dismissDisplayAnimated:]):
(-[WKFileUploadPanel _showPhotoPickerWithSourceType:]):

Set the presentationController's delegate so that we are informed when the picker
is dismissed by swiping down.

(-[WKFileUploadPanel _presentMenuOptionForCurrentInterfaceIdiom:]): Deleted.

This method was already unused.

(-[WKFileUploadPanel _presentPopoverWithContentViewController:animated:]): Deleted.
(-[WKFileUploadPanel popoverControllerDidDismissPopover:]): Deleted.

Canonical link: https://commits.webkit.org/251012@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294882 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
pxlcoder committed May 26, 2022
1 parent 663022c commit 923a7342448b708ec15f61f18c3f4d64c5ff1b25
Showing 1 changed file with 5 additions and 49 deletions.
@@ -332,7 +332,7 @@ - (NSString *)_temporaryDirectoryCreateIfNecessary

#pragma mark - WKFileUploadPanel

@interface WKFileUploadPanel () <UIPopoverControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIDocumentPickerDelegate, UIAdaptivePresentationControllerDelegate
@interface WKFileUploadPanel () <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIDocumentPickerDelegate, UIAdaptivePresentationControllerDelegate
#if USE(UICONTEXTMENU)
, UIContextMenuInteractionDelegate
#endif
@@ -351,9 +351,8 @@ @implementation WKFileUploadPanel {
RetainPtr<WKFileUploadMediaTranscoder> _mediaTranscoder;
#endif
RetainPtr<UIImagePickerController> _imagePicker;
RetainPtr<UIViewController> _presentationViewController; // iPhone always. iPad for Fullscreen Camera.
RetainPtr<UIViewController> _presentationViewController;
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
RetainPtr<UIPopoverController> _presentationPopover; // iPad for action sheet and Photo Library.
BOOL _isPresentingSubMenu;
ALLOW_DEPRECATED_DECLARATIONS_END
#if USE(UICONTEXTMENU)
@@ -374,7 +373,6 @@ - (instancetype)initWithView:(WKContentView *)view
- (void)dealloc
{
[_imagePicker setDelegate:nil];
[_presentationPopover setDelegate:nil];
[_documentPickerController setDelegate:nil];
#if USE(UICONTEXTMENU)
[self removeContextMenuInteraction];
@@ -503,22 +501,14 @@ - (void)dismiss

if (auto view = _view.get())
[[UIViewController _viewControllerForFullScreenPresentationFromView:view.get()] dismissViewControllerAnimated:NO completion:nil];

[_presentationPopover setDelegate:nil];
_presentationPopover = nil;

_presentationViewController = nil;

[self _cancel];
}

- (void)_dismissDisplayAnimated:(BOOL)animated
{
if (_presentationPopover) {
[_presentationPopover dismissPopoverAnimated:animated];
[_presentationPopover setDelegate:nil];
_presentationPopover = nil;
}

if (_presentationViewController) {
UIViewController *currentPresentedViewController = [_presentationViewController presentedViewController];
if (currentPresentedViewController == self || currentPresentedViewController == _imagePicker.get()) {
@@ -781,45 +771,20 @@ - (void)_showPhotoPickerWithSourceType:(UIImagePickerControllerSourceType)source
[_imagePicker setSourceType:sourceType];
[_imagePicker setMediaTypes:[self _mediaTypesForPickerSourceType:sourceType]];
[_imagePicker setDelegate:self];
[_imagePicker presentationController].delegate = self;
[_imagePicker setAllowsEditing:NO];
[_imagePicker setModalPresentationStyle:UIModalPresentationFullScreen];
[_imagePicker _setAllowsMultipleSelection:_allowMultipleFiles];
[_imagePicker _setRequiresPickingConfirmation:YES];
[_imagePicker _setShowsFileSizePicker:YES];

if (_mediaCaptureType != WebCore::MediaCaptureTypeNone)
[_imagePicker setCameraDevice:cameraDeviceForMediaCaptureType(_mediaCaptureType)];

// Use a popover on the iPad if the source type is not the camera.
// The camera will use a fullscreen, modal view controller.
BOOL usePopover = !currentUserInterfaceIdiomIsSmallScreen() && sourceType != UIImagePickerControllerSourceTypeCamera;
if (usePopover)
[self _presentPopoverWithContentViewController:_imagePicker.get() animated:YES];
else
[self _presentFullscreenViewController:_imagePicker.get() animated:YES];
[self _presentFullscreenViewController:_imagePicker.get() animated:YES];
}

#pragma mark - Presenting View Controllers

- (void)_presentMenuOptionForCurrentInterfaceIdiom:(UIViewController *)viewController
{
if (currentUserInterfaceIdiomIsSmallScreen())
[self _presentFullscreenViewController:viewController animated:YES];
else
[self _presentPopoverWithContentViewController:viewController animated:YES];
}

- (void)_presentPopoverWithContentViewController:(UIViewController *)contentViewController animated:(BOOL)animated
{
[self _dismissDisplayAnimated:animated];

ALLOW_DEPRECATED_DECLARATIONS_BEGIN
_presentationPopover = adoptNS([[UIPopoverController alloc] initWithContentViewController:contentViewController]);
ALLOW_DEPRECATED_DECLARATIONS_END
[_presentationPopover setDelegate:self];
[_presentationPopover presentPopoverFromRect:CGRectIntegral(CGRectMake(_interactionPoint.x, _interactionPoint.y, 1, 1)) inView:_view.getAutoreleased() permittedArrowDirections:UIPopoverArrowDirectionAny animated:animated];
}

- (void)_presentFullscreenViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[self _dismissDisplayAnimated:animated];
@@ -835,15 +800,6 @@ - (void)presentationControllerDidDismiss:(UIPresentationController *)presentatio
[self _cancel];
}

#pragma mark - UIPopoverControllerDelegate

ALLOW_DEPRECATED_IMPLEMENTATIONS_BEGIN
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
ALLOW_DEPRECATED_IMPLEMENTATIONS_END
{
[self _cancel];
}

#pragma mark - UIDocumentPickerControllerDelegate implementation

static NSString *displayStringForDocumentsAtURLs(NSArray<NSURL *> *urls)

0 comments on commit 923a734

Please sign in to comment.