Skip to content

Commit

Permalink
[Catalog] Add BottomSheetPresentationControllerDelegateExample to dem…
Browse files Browse the repository at this point in the history
…onstrate usage of MDCBottomSheetPresentationControllerDelegate.

PiperOrigin-RevId: 314784259
  • Loading branch information
bryanoltman authored and material-automation committed Jun 4, 2020
1 parent ee0b388 commit 4e461e2
Showing 1 changed file with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#import "BottomSheetPresenterViewController.h"
#import "MaterialBottomSheet.h"

/**
Demonstrates the use of MDCBottomSheetTransitionController.
*/
@interface BottomSheetPresentationControllerDelegateExamplePresentedSheetController
: UIViewController
@end

@implementation BottomSheetPresentationControllerDelegateExamplePresentedSheetController {
id<UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate>
_transitionController;
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
MDCBottomSheetTransitionController *transitionController =
[[MDCBottomSheetTransitionController alloc] init];
transitionController.dismissOnBackgroundTap = YES;
_transitionController = transitionController;
self.transitioningDelegate = _transitionController;
self.modalPresentationStyle = UIModalPresentationCustom;

self.view.backgroundColor = UIColor.purpleColor;
self.view.isAccessibilityElement = YES;
self.view.accessibilityLabel = @"Example content";
}
return self;
}

@end

/**
Demonstrates use of MDCBottomSheetPresentationController functionality.
*/
@interface BottomSheetPresentationControllerDelegateExample
: BottomSheetPresenterViewController <MDCBottomSheetPresentationControllerDelegate>
@end

@implementation BottomSheetPresentationControllerDelegateExample

- (void)viewDidLoad {
[super viewDidLoad];
[self.button setTitle:@"Present Custom Controller" forState:UIControlStateNormal];
}

- (void)presentBottomSheet {
BottomSheetPresentationControllerDelegateExamplePresentedSheetController *sheetController =
[[BottomSheetPresentationControllerDelegateExamplePresentedSheetController alloc] init];
MDCBottomSheetPresentationController *presentationController =
(MDCBottomSheetPresentationController *)sheetController.presentationController;
presentationController.delegate = self;

[self presentViewController:sheetController animated:YES completion:nil];
}

- (void)exit {
[self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - MDCBottomSheetPresentationControllerDelegate

- (void)bottomSheetDidChangeYOffset:(MDCBottomSheetPresentationController *)bottomSheet
yOffset:(CGFloat)yOffset {
NSLog(@"%@", NSStringFromSelector(_cmd));
}

- (void)bottomSheetPresentationControllerDidDismissBottomSheet:
(MDCBottomSheetPresentationController *)bottomSheet {
NSLog(@"%@", NSStringFromSelector(_cmd));
}

- (void)bottomSheetWillChangeState:(MDCBottomSheetPresentationController *)bottomSheet
sheetState:(MDCSheetState)sheetState {
NSLog(@"%@", NSStringFromSelector(_cmd));
}

@end

@implementation BottomSheetPresentationControllerDelegateExample (CatalogByConvention)

+ (NSDictionary *)catalogMetadata {
return @{
@"breadcrumbs" : @[ @"Bottom Sheet", @"Presentation Controller with Custom View Controller" ],
@"primaryDemo" : @NO,
@"presentable" : @NO,
};
}

@end

0 comments on commit 4e461e2

Please sign in to comment.