Contents
Bottom sheets are supplementary surfaces primarily used on mobile.
In order to install with Cocoapods, first add the component to your Podfile
:
pod 'MaterialComponents/BottomSheet'
Then run the installer:
pod install
From there, import the relevant target or file.
import MaterialComponents.MaterialBottomSheet
#import "MaterialBottomSheet.h"
As a user of the bottom sheet component, it is up to you to determine that its contents are accessible. The bottom sheet ccomponent does not have any specific APIs for managing the accessibility of a bottom sheet's contents. MDCBottomSheetController
does, however, have such APIs for the scrim:
isScrimAccessibilityElement
scrimAccessibilityLabel
scrimAccessibilityHint
scrimAccessibilityTraits
We recommend giving all of these properties appropriate values for your use case.
Types
There are three types suitable for different use cases:
Note: Standard bottom sheets aren't supported on iOS. This is because the iOS bottom sheet implementation makes use of custom view controller transitions, which do not allow interaction with the presenting view controller, even when the presented view controller does not take up the whole screen.
Modal bottom sheets present a set of choices while blocking interaction with the rest of the screen. They are an alternative to inline menus and simple dialogs on mobile, providing additional room for content, iconography, and actions.
Modal bottom sheets are used in mobile apps only.
Use MDCBottomSheetController
and its accompanying presentation controller class, MDCBottomSheetPresentationController
, to achieve a modal bottom sheet on iOS.
Something like the above example can be achieved using the code below.
// View controller the bottom sheet will hold let viewController: ViewController = ViewController() // Initialize the bottom sheet with the view controller just created let bottomSheet: MDCBottomSheetController = MDCBottomSheetController(contentViewController: viewController) // At this point perform any customizations, like adding a slider, for example. // Present the bottom sheet present(bottomSheet, animated: true, completion: nil)
// View controller the bottom sheet will hold ViewController *viewController = [[ViewController alloc] init]; // Initialize the bottom sheet with the view controller just created MDCBottomSheetController *bottomSheet = [[MDCBottomSheetController alloc] initWithContentViewController:viewController]; // At this point perform any customizations, like adding a slider, for example. // Present the bottom sheet [self presentViewController:bottomSheet animated:true completion:nil];
You can also choose to have your bottom sheet not be dismissable when dragged downwards by using the dismissOnDraggingDownSheet
property on MDCBottomSheetController
.
let viewController: ViewController = ViewController() let bottomSheet: MDCBottomSheetController = MDCBottomSheetController(contentViewController: viewController) bottomSheet.dismissOnDraggingDownSheet = false present(bottomSheet, animated: true, completion: nil)
ViewController *viewController = [[ViewController alloc] init]; MDCBottomSheetController *bottomSheet = [[MDCBottomSheetController alloc] initWithContentViewController:viewController]; bottomSheet.dismissOnDraggingDownSheet = NO; [self presentViewController:bottomSheet animated:true completion:nil];
The following shows the anatomy of a modal bottom sheet:
Note: A bottom sheet similar to the one shown above is easily attainable with the ActionSheet component, which makes use of MDCBottomSheetPresentationController
.
Attribute | Related methods | Default value | |
---|---|---|---|
Sheet height | preferredSheetHeight | -[MDCBottomSheetPresentationController setPreferredSheetHeight:] -[MDCBottomSheetPresentationController preferredSheetHeight] | N/A |
Elevation | elevation | -[MDCBottomSheetPresentationController setElevation:] -[MDCBottomSheetPresentationController elevation] | 16 |
Attribute | Related methods | Default value | |
---|---|---|---|
Contents | contentViewController | -[MDCBottomSheetController initWithContentViewController:] -[MDCBottomSheetController contentViewController] | N/A |
Elevation | elevation | -[MDCBottomSheetPresentationController setElevation:] -[MDCBottomSheetPresentationController elevation] | 16 |
Title text | title | -[MDCActionSheetComtroller setTitle:] -[MDCActionSheetComtroller title] | nil |
Message text | message | -[MDCActionSheetComtroller setMessage:] -[MDCActionSheetComtroller message] | nil |
Title font | titleFont | -[MDCActionSheetComtroller setTitleFont:] -[MDCActionSheetComtroller titleFont] | nil |
Message font | messageFont | -[MDCActionSheetComtroller setMessageFont:] -[MDCActionSheetComtroller messageFont] | nil |
Action font | actionFont | -[MDCActionSheetComtroller setActionFont:] -[MDCActionSheetComtroller actionFont] | nil |
Ripple color | rippleColor | -[MDCActionSheetComtroller setRippleColor:] -[MDCActionSheetComtroller rippleColor] | nil |
Background color | backgroundColor | -[MDCActionSheetComtroller -setBackgroundColor:] -[MDCActionSheetComtroller backgroundColor] | nil |
Title text color | titleTextColor | -[MDCActionSheetComtroller -setTitleTextColor:] -[MDCActionSheetComtroller titleTextColor] | nil |
Message text color | messageTextColor | -[MDCActionSheetComtroller -setMessageTextColor:] -[MDCActionSheetComtroller messageTextColor] | nil |
Action text color | actionTextColor | -[MDCActionSheetComtroller -setActionTextColor:] -[MDCActionSheetComtroller actionTextColor] | nil |
Action tint color | actionTintColor | -[MDCActionSheetComtroller -setActionTintColor:] -[MDCActionSheetComtroller actionTintColor] | nil |
Attribute | Related methods | Default value | |
---|---|---|---|
Color | scrimColor | -[MDCBottomSheetPresentationController setScrimColor:] -[MDCBottomSheetPresentationController scrimColor] | White at 40% opacity |
An expanding bottom sheet is a surface anchored to the bottom of the screen that users can expand to access a feature or task. It can be used for:
Expanding bottom sheets are recommended for use on mobile and tablet.
To generate an expanding bottom sheet on iOS, set the trackingScrollView
property on your MDCBottomSheetController
. If the contentSize
of the scroll view has a large enough height the bottom sheet will expand to the top.
bottomSheet.trackingScrollView = scrollView
bottomSheet.trackingScrollView = self.scrollView;