-
Drag
MyShareExtensionDismissControlRecognizer.h
andMyShareExtensionDismissControlRecognizer.m
files into your extension target. -
Add the recognizer to
ShareViewController
:
@implementation ShareViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIGestureRecognizer *recognizer = [[MyShareExtensionDismissControlRecognizer alloc] initWithDismissStrategy:MyShareExtensionSwipeDismissStrategyTopRegion];
[self.view addGestureRecognizer:recognizer];
- With
MyShareExtensionSwipeDismissStrategyTopRegion
, you can drag the top region of the sheet to dismiss it. - With
MyShareExtensionSwipeDismissStrategyProhibited
, you can't dismiss the via gesture. Instead, you have to use a button.
You can either add the button on native side or on flutter side.
- To add the dismiss button on native side, you can simply use a navigation bar:
- (void)viewDidLoad {
[super viewDidLoad];
FlutterViewController *vc = [[FlutterViewController alloc] initWithProject:nil nibName:nil bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
[self addChildViewController:nav];
[self.view addSubview:nav.view];
nav.view.frame = self.view.bounds;
vc.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStyleDone target:self action:@selector(saveButtonClicked)];
}
- (void)saveButtonClicked {
NSLog(@"save button clicked");
[self.extensionContext completeRequestReturningItems:nil completionHandler:^(BOOL expired) {
NSLog(@"Dismissed");
}];
}
- To add the dismiss button on flutter side, you can use a method channel, and call the
completeRequestReturningItems
API.