Skip to content

Commit

Permalink
/issues/5009 - Fixed share extension setup and cleaned up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Oct 18, 2021
1 parent d7ab735 commit aa790b2
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 447 deletions.
6 changes: 2 additions & 4 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -3201,8 +3201,7 @@ - (void)showAdditionalActionsMenuForEvent:(MXEvent*)selectedEvent inCell:(id<MXK
NSExtensionItem *item = [[NSExtensionItem alloc] init];
item.attachments = @[[[NSItemProvider alloc] initWithItem:selectedComponent.textMessage typeIdentifier:(__bridge NSString *)kUTTypeText]];

self.shareManager = [[ShareManager alloc] initWithShareExtensionContext:nil
extensionItems:@[item]];
self.shareManager = [[ShareManager alloc] initWithItems:@[item]];

MXWeakify(self);
[self.shareManager setCompletionCallback:^(ShareManagerResult result) {
Expand Down Expand Up @@ -3414,8 +3413,7 @@ - (void)showAdditionalActionsMenuForEvent:(MXEvent*)selectedEvent inCell:(id<MXK
NSExtensionItem *item = [[NSExtensionItem alloc] init];
item.attachments = @[[[NSItemProvider alloc] initWithItem:fileURL typeIdentifier:attachmentTypeToIdentifier[@(attachment.type)]]];

self.shareManager = [[ShareManager alloc] initWithShareExtensionContext:nil
extensionItems:@[item]];
self.shareManager = [[ShareManager alloc] initWithItems:@[item]];

MXWeakify(self);
[self.shareManager setCompletionCallback:^(ShareManagerResult result) {
Expand Down
65 changes: 28 additions & 37 deletions RiotShareExtension/ShareExtensionRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,36 @@ @interface ShareExtensionRootViewController ()

@implementation ShareExtensionRootViewController

- (instancetype)init
- (void)viewDidLoad
{
if(self = [super init]) {

[ThemeService.shared setThemeId:RiotSettings.shared.userInterfaceTheme];

_shareManager = [[ShareManager alloc] initWithShareExtensionContext:self.extensionContext
extensionItems:self.extensionContext.inputItems];

MXWeakify(self);
[_shareManager setCompletionCallback:^(ShareManagerResult result) {
MXStrongifyAndReturnIfNil(self);

switch (result)
{
case ShareManagerResultFinished:
[self.extensionContext completeRequestReturningItems:nil completionHandler:nil];
[self _dismiss];
break;
case ShareManagerResultCancelled:
[self.extensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]];
[self _dismiss];
break;
case ShareManagerResultFailed:
[self.extensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXFailureErrorDomain" code:500 userInfo:nil]];
[self _dismiss];
break;
default:
break;
}
}];
}
[super viewDidLoad];

return self;
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[ThemeService.shared setThemeId:RiotSettings.shared.userInterfaceTheme];

_shareManager = [[ShareManager alloc] initWithItems:self.extensionContext.inputItems];

MXWeakify(self);
[_shareManager setCompletionCallback:^(ShareManagerResult result) {
MXStrongifyAndReturnIfNil(self);

switch (result)
{
case ShareManagerResultFinished:
[self.extensionContext completeRequestReturningItems:nil completionHandler:nil];
[self _dismiss];
break;
case ShareManagerResultCancelled:
[self.extensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]];
[self _dismiss];
break;
case ShareManagerResultFailed:
[self.extensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXFailureErrorDomain" code:500 userInfo:nil]];
[self _dismiss];
break;
default:
break;
}
}];

[self presentViewController:self.shareManager.mainViewController animated:YES completion:nil];
}
Expand Down
7 changes: 5 additions & 2 deletions RiotShareExtension/Shared/ShareManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#import <MatrixKit/MatrixKit.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, ShareManagerResult) {
ShareManagerResultFinished,
ShareManagerResultCancelled,
Expand All @@ -26,8 +28,7 @@ typedef NS_ENUM(NSUInteger, ShareManagerResult) {

@property (nonatomic, copy) void (^completionCallback)(ShareManagerResult);

- (instancetype)initWithShareExtensionContext:(NSExtensionContext *)shareExtensionContext
extensionItems:(NSArray<NSExtensionItem *> *)extensionItems;
- (instancetype)initWithItems:(NSArray<NSExtensionItem *> *)items;

- (UIViewController *)mainViewController;

Expand All @@ -39,3 +40,5 @@ typedef NS_ENUM(NSUInteger, ShareManagerResult) {
@property BOOL isLoaded;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit aa790b2

Please sign in to comment.