Skip to content

Instantly share code, notes, and snippets.

@0xstragner
Last active October 20, 2022 15:12
Show Gist options
  • Save 0xstragner/7ce7237f6f80377493ee693cafdaf243 to your computer and use it in GitHub Desktop.
Save 0xstragner/7ce7237f6f80377493ee693cafdaf243 to your computer and use it in GitHub Desktop.
Medium/UISheetPresentationController/1.m
//
// SA13SheetPresentationController
//
static Class _SA13SheetPresentationControllerKlass = nil;
API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos, watchos) NS_SWIFT_UI_ACTOR
@interface SUI13SheetPresentationController : NSObject
@property (nonatomic, assign) BOOL shouldFullscreen;
@property (nonatomic, assign) BOOL shouldRespectPresentationContext;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *klassName = @"_SA13SheetPresentationController";
Class superklass = NSClassFromString(@"_UISheetPresentationController");
Class klass = objc_allocateClassPair(superklass, [klassName UTF8String], 0);
objc_registerClassPair(klass);
});
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (instancetype)initWithPresentedViewController:(UIViewController *)presentedViewController
presentingViewController:(UIViewController *)presentingViewController
{
self = [[_SUI13SheetPresentationControllerKlass alloc] initWithPresentedViewController:presentedViewController
presentingViewController:presentingViewController];
return self;
}
#pragma clang diagnostic pop
@end
//
// SA15SheetPresentationController
//
API_AVAILABLE(ios(15.0)) API_UNAVAILABLE(tvos, watchos) NS_SWIFT_UI_ACTOR
@interface SA15SheetPresentationController : UISheetPresentationController
@property (nonatomic, assign) BOOL shouldFullscreen;
@property (nonatomic, assign) BOOL shouldRespectPresentationContext;
@end
@implementation SA15SheetPresentationController
@end
//
// SASheetPresentationController
//
@interface SASheetPresentationController : UIPresentationController
@property (nonatomic, assign) BOOL shouldFullscreen;
@property (nonatomic, assign) BOOL shouldRespectPresentationContext;
- (void)performAnimatedChanges:(void (NS_NOESCAPE ^)(void))changes;
- (void)invalidateDetents;
@end
@implementation SASheetPresentationController
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (instancetype)initWithPresentedViewController:(UIViewController *)presentedViewController
presentingViewController:(UIViewController *)presentingViewController
{
if (@available(iOS 15, *)) {
self = (id)[[SA15SheetPresentationController alloc] initWithPresentedViewController:presentedViewController
presentingViewController:presentingViewController];
} else if (@available(iOS 13, *)) {
self = (id)[[SA13SheetPresentationController alloc] initWithPresentedViewController:presentedViewController
presentingViewController:presentingViewController];
} else {
[[NSException exceptionWithName:NSGenericException
reason:@"SASheetPresentationController only available from iOS 13."
userInfo:nil] raise];
}
return self;
}
#pragma clang diagnostic pop
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment