-
Notifications
You must be signed in to change notification settings - Fork 948
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Catalog] Add BottomSheetPresentationControllerDelegateExample to dem…
…onstrate usage of MDCBottomSheetPresentationControllerDelegate. PiperOrigin-RevId: 314784259
- Loading branch information
1 parent
ee0b388
commit 4e461e2
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
components/BottomSheet/examples/BottomSheetPresentationControllerDelegateExample.m
This file contains 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
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 |