Skip to content

Commit

Permalink
Add option for presenting the web view share sheet modally
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=246376
rdar://101050446

Reviewed by Aditya Keerthi.

Add an option to present the web view's share sheet modally instead of as a
popover.

* Source/WebKit/Platform/spi/ios/UIKitSPI.h:
* Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm:
(-[WKShareSheet presentWithShareDataArray:inRect:]):

Canonical link: https://commits.webkit.org/255794@main
  • Loading branch information
TrevorStevenson authored and pxlcoder committed Oct 20, 2022
1 parent 71d1772 commit c7c7e5c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Source/WebKit/Platform/spi/ios/UIKitSPI.h
Expand Up @@ -29,6 +29,7 @@

#import <CoreSVG/CGSVGDocument.h>
#import <UIKit/NSTextAlternatives.h>
#import <UIKit/UIActivityViewController_Private.h>
#import <UIKit/UIAlertController_Private.h>
#import <UIKit/UIApplication_Private.h>
#import <UIKit/UIBarButtonItem_Private.h>
Expand Down Expand Up @@ -737,6 +738,10 @@ typedef enum {
- (UIWindow *)window;
@end

@interface UIActivityViewController ()
@property (nonatomic) BOOL allowsCustomPresentationStyle;
@end

typedef NS_ENUM (NSInteger, _UIBackdropMaskViewFlags) {
_UIBackdropMaskViewNone = 0,
_UIBackdropMaskViewGrayscaleTint = 1 << 0,
Expand Down
22 changes: 17 additions & 5 deletions Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm
Expand Up @@ -46,6 +46,10 @@
#import <pal/spi/mac/NSSharingServicePickerSPI.h>
#endif

#if HAVE(UIKIT_WEBKIT_INTERNALS)
#include <WebKitAdditions/WKShareSheetAdditions.h>
#endif

#if PLATFORM(IOS_FAMILY)

@interface WKShareSheetFileItemProvider : UIActivityItemProvider
Expand Down Expand Up @@ -251,12 +255,20 @@ - (void)presentWithShareDataArray:(NSArray *)sharingItems inRect:(std::optional<
[self dismiss];
}];

UIPopoverPresentationController *popoverController = [_shareSheetViewController popoverPresentationController];
if (rect) {
popoverController.sourceView = webView;
popoverController.sourceRect = *rect;
#if HAVE(UIKIT_WEBKIT_INTERNALS)
if (shareSheetUsesModalPresentationForWebView(webView)) {
[_shareSheetViewController setAllowsCustomPresentationStyle:YES];
[_shareSheetViewController setModalPresentationStyle:UIModalPresentationFormSheet];
} else
popoverController._centersPopoverIfSourceViewNotSet = YES;
#endif // HAVE(UIKIT_WEBKIT_INTERNALS)
{
UIPopoverPresentationController *popoverController = [_shareSheetViewController popoverPresentationController];
if (rect) {
popoverController.sourceView = webView;
popoverController.sourceRect = *rect;
} else
popoverController._centersPopoverIfSourceViewNotSet = YES;
}

if ([_delegate respondsToSelector:@selector(shareSheet:willShowActivityItems:)])
[_delegate shareSheet:self willShowActivityItems:sharingItems];
Expand Down

0 comments on commit c7c7e5c

Please sign in to comment.