Created
July 13, 2021 12:52
YouTube action sheet and notification things
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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