bottom sheet
mobile UI design
Maps app
app development
user interface components

How can I mimic the bottom sheet from the Maps app?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Understanding Bottom Sheets

Bottom sheets are UI components primarily used to display content that can be partially hidden, allowing for more space management within applications. They are a popular component in mobile apps for presenting content without disrupting the current screen view. The Maps app, on both Android and iOS platforms, utilizes bottom sheets to provide additional information or controls, making the user experience seamless. To mimic this feature, it's essential to understand the types of bottom sheets and their implementation.

Types of Bottom Sheets

  1. Persistent Bottom Sheet: This type remains visible and is usually anchored at the bottom of the screen. Users can interact with this sheet without losing sight of the main content. Typical use includes displaying additional navigation links or app controls.
  2. Modal Bottom Sheet: This sheet overlays content and requires user interaction to dismiss. It's often used to display options or actions that require focus, such as sorting or filtering options.
  3. Expanding Bottom Sheet: A variant of the persistent bottom sheet that can expand to cover a significant portion of the screen when interacted with.

Implementing Bottom Sheets

Android Implementation

In Android, bottom sheets are part of the Material Design components and can be implemented using BottomSheetDialogFragment or BottomSheetBehavior.

  • BottomSheetDialogFragment: Used for modal sheets. It provides a simple way to create a bottom sheet as a dialog, overlaying on top of current content.
java
1public class CustomBottomSheetDialogFragment extends BottomSheetDialogFragment {
2    @Nullable
3    @Override
4    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
5        return inflater.inflate(R.layout.fragment_bottom_sheet, container, false);
6    }
7}
  • BottomSheetBehavior: Used for persistent or expanding sheets. This requires applying behavior to a CoordinatorLayout.
xml
1<LinearLayout
2    android:id="@+id/bottom_sheet"
3    android:layout_width="match_parent"
4    android:layout_height="wrap_content"
5    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
6    <!-- Content Here -->
7</LinearLayout>
java
1BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet));
2// To expand
3bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
4// To collapse
5bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

iOS Implementation

For iOS, bottom sheets can be implemented using UIViewController as a custom container or by using the UISheetPresentationController.

  • Custom UIViewController: Provides more flexibility for customizing.
swift
1class BottomSheetViewController: UIViewController {
2    override func viewDidLoad() {
3        super.viewDidLoad()
4        view.backgroundColor = .white
5        view.layer.cornerRadius = 16
6    }
7    override func viewWillAppear(_ animated: Bool) {
8        super.viewWillAppear(animated)
9        self.presentAsBottomSheet()
10    }
11}
12
13extension UIViewController {
14    func presentAsBottomSheet() {
15        if let sheet = self.sheetPresentationController {
16            sheet.detents = [.medium(), .large()]
17        }
18    }
19}
  • UISheetPresentationController: Available from iOS 15+, it simplifies the implementation with built-in detents and states.

Best Practices

  • User Interaction: Ensure that interacting with the bottom sheet is intuitive. Dragging gestures should respond smoothly to user input.
  • Adaptive Layouts: Use AutoLayout (iOS) or ConstraintLayout (Android) to ensure content fits on different screen sizes.
  • Performance Optimization: Load data asynchronously if the bottom sheet displays dynamic content to avoid freezing the UI during presentation.

Key Differences

FeatureAndroidiOS
Component AvailabilityPart of Material ComponentsAvailable from iOS 15 with UISheetPresentationController
Interaction HandlingBottomSheetBehavior and gesturesUISheetPresentationController using detents Custom implementation possible
Use CasesModal, Persistent, ExpandingMostly Modal and Standard customization
FlexibilityHigh with BottomSheetBehaviorLimited by iOS version compatibility

Enhancements

  • Animations: Add smooth transition animations to enhance the visibility and aesthetic of the bottom sheet.
  • Accessibility: Implement accessibility features such as voice control compatibility and text size adjustments.
  • Dynamic Content: Use live data to update the bottom sheet's content dynamically to provide more relevant and timely information.

By utilizing these strategies and techniques, developers can effectively mimic the bottom sheet behavior found in the Maps app, creating a user-friendly and functional UI component in their applications.


Course illustration
Course illustration

All Rights Reserved.