Skip to content

Instantly share code, notes, and snippets.

@PoomSmart
Created July 13, 2021 12:52
Show Gist options
  • Save PoomSmart/1237ba913333dce00b5173162afc271c to your computer and use it in GitHub Desktop.
Save PoomSmart/1237ba913333dce00b5173162afc271c to your computer and use it in GitHub Desktop.
YouTube action sheet and notification things
@interface YTUIUtils : NSObject
+ (UIViewController *)topViewControllerForPresenting;
@end
@interface YTUIResources : NSObject
+ (UIImage *)iconCheckTemplateImage;
+ (UIImage *)actionsheetDefaultImage;
@end
@interface YTActionSheetAction : NSObject
+ (instancetype)actionWithTitle:(NSString *)title subtitle:(NSString *)subtitle iconImage:(UIImage *)iconImage accessibilityIdentifier:(NSString *)accessibilityIdentifier handler:(void (^)(YTActionSheetAction *))handler;
- (NSUInteger)accessibilityTraits;
- (void)setAccessibilityTraits:(NSUInteger)accessibilityTraits;
@end
@interface YTActionSheetController : NSObject <YTActionSheetDialogViewControllerDelegate>
+ (instancetype)actionSheetController;
- (void)addCancelActionIfNeeded;
- (void)presentFromViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^)(void))completion;
@end
YTActionSheetController *actionSheetController = [%c(YTActionSheetController) actionSheetController];
for (id a in actions) {
UIImage *actionImage = a.selected ? [%c(YTUIResources) iconCheckTemplateImage] : [%c(YTUIResources) actionsheetDefaultImage];
YTActionSheetAction *action = [%c(YTActionSheetAction) actionWithTitle:a.title subtitle:a.subtitle iconImage:actionImage accessibilityIdentifier:a.id handler:^(void) {
// perform magic
}];
if (a.selected)
action.accessibilityTraits |= UIAccessibilityTraitSelected;
[actionSheetController addAction:action];
}
[actionSheetController addCancelActionIfNeeded];
actionSheetController.delegate = self;
actionSheetController.sourceView = <your source view>;
[actionSheetController presentFromViewController:[%c(YTUIUtils) topViewControllerForPresenting] animated:YES completion:nil];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment