Skip to content

Commit f8ef922

Browse files
andrewovertonmaterial-automation
authored andcommitted
[Snackbar] Replace snackbar docs
Closes #10098 COPYBARA_INTEGRATE_REVIEW=#10098 from andrewoverton:material-io-snackbars-docs 3e8174f PiperOrigin-RevId: 336337486
1 parent 6ad0683 commit f8ef922

File tree

9 files changed

+63
-203
lines changed

9 files changed

+63
-203
lines changed

components/Snackbar/README.md

Lines changed: 63 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,44 @@
11
<!--docs:
2-
title: "Snackbar"
2+
title: "Material Snackbars"
33
layout: detail
44
section: components
5-
excerpt: "Snackbars provide brief feedback about an operation through a message at the bottom of the screen."
6-
iconId: toast
7-
path: /catalog/snackbars/
8-
api_doc_root: true
5+
excerpt: "Snackbars provide brief messages about app processes at the bottom of the screen."
6+
iconId:
7+
path: /catalog/Snackbars/
98
-->
109

11-
<!-- This file was auto-generated using ./scripts/generate_readme Snackbar -->
12-
13-
# Snackbar
10+
# Snackbars
1411

1512
[![Open bugs badge](https://img.shields.io/badge/dynamic/json.svg?label=open%20bugs&url=https%3A%2F%2Fapi.github.com%2Fsearch%2Fissues%3Fq%3Dis%253Aopen%2Blabel%253Atype%253ABug%2Blabel%253A%255BSnackbar%255D&query=%24.total_count)](https://github.com/material-components/material-components-ios/issues?q=is%3Aopen+is%3Aissue+label%3Atype%3ABug+label%3A%5BSnackbar%5D)
1613

17-
Snackbars provide brief feedback about an operation through a message at the bottom of the screen.
18-
Snackbars contain up to two lines of text directly related to the operation performed. They may
19-
contain a text action, but no icons.
20-
21-
<div class="article__asset article__asset--screenshot">
22-
<img src="docs/assets/snackbar.png" alt="Snackbar" width="375">
23-
</div>
24-
25-
## Design & API documentation
26-
27-
<ul class="icon-list">
28-
<li class="icon-list-item icon-list-item--spec"><a href="https://material.io/go/design-snackbar">Material Design guidelines: Snack Bar</a></li>
29-
<li class="icon-list-item icon-list-item--link">Class: <a href="https://github.com/material-components/material-components-ios/blob/develop/components/Snackbar/src/MDCSnackbarManager.h">MDCSnackbarManager</a></li>
30-
<li class="icon-list-item icon-list-item--link">Class: <a href="https://github.com/material-components/material-components-ios/blob/develop/components/Snackbar/src/MDCSnackbarMessage.h">MDCSnackbarMessage</a></li>
31-
<li class="icon-list-item icon-list-item--link">Class: <a href="https://github.com/material-components/material-components-ios/blob/develop/components/Snackbar/src/MDCSnackbarMessage.h">MDCSnackbarMessageAction</a></li>
32-
<li class="icon-list-item icon-list-item--link">Class: <a href="https://github.com/material-components/material-components-ios/blob/develop/components/Snackbar/src/MDCSnackbarMessageView.h">MDCSnackbarMessageView</a></li>
33-
<li class="icon-list-item icon-list-item--link">Protocol: <a href="https://github.com/material-components/material-components-ios/blob/develop/components/Snackbar/src/MDCSnackbarManager.h">MDCSnackbarSuspensionToken</a></li>
34-
<li class="icon-list-item icon-list-item--link">Protocol: <a href="https://github.com/material-components/material-components-ios/blob/develop/components/Snackbar/src/MDCSnackbarManagerDelegate.h">MDCSnackbarManagerDelegate</a></li>
35-
<li class="icon-list-item icon-list-item--link">Enumeration: <a href="https://github.com/material-components/material-components-ios/blob/develop/components/Snackbar/src/MDCSnackbarAlignment.h">MDCSnackbarAlignment</a></li>
36-
</ul>
14+
[Snackbars](https://material.io/components/snackbars) provide brief messages about app processes at the bottom of the screen. They can contain up to two lines of text and a text action button, but no icons.
3715

38-
## Related components
16+
![Snackbars hero image](docs/assets/snackbars-hero.png)
3917

40-
<ul class="icon-list">
41-
<li class="icon-list-item icon-list-item--link"><a href="../OverlayWindow">OverlayWindow</a></li>
42-
</ul>
18+
## Contents
4319

44-
## Table of contents
20+
* [Using snackbars](#using-snackbars)
21+
* [Installing snackbars](#installing-snackbars)
22+
* [Importing snackbars](#importing-snackbars)
23+
* [Making snackbars accessible](#making-snackbars-accessible)
24+
* [Snackbar example](#snackbar-example)
25+
* [Theming snackbars](#theming-snackbars)
4526

46-
- [Overview](#overview)
47-
- [Snackbar Manager and Message](#snackbar-manager-and-message)
48-
- [Suspending and Resuming Display of Messages](#suspending-and-resuming-display-of-messages)
49-
- [Installation](#installation)
50-
- [Installation with CocoaPods](#installation-with-cocoapods)
51-
- [Importing](#importing)
52-
- [Usage](#usage)
53-
- [Typical use: display a message](#typical-use-display-a-message)
54-
- [Typical use: display a message with an action](#typical-use-display-a-message-with-an-action)
55-
- [Extensions](#extensions)
56-
- [Color Theming](#color-theming)
27+
## Using snackbars
5728

58-
- - -
29+
Snackbars inform users of a process that an app has performed or will perform. They appear temporarily, towards the bottom of the screen. They shouldn’t interrupt the user experience, and they don’t require user input to disappear.
5930

60-
## Overview
61-
62-
### Snackbar Manager and Message
63-
64-
Snackbar is comprised of two classes: MDCSnackbarManager and MDCSnackbarMessage. Snackbar messages
65-
contain text to be displayed to a user. Messages are passed to the manager. The manager decides when
66-
it is appropriate to show a message to the user.
67-
68-
### Suspending and Resuming Display of Messages
31+
Displaying a snackbar involves two classes: `MDCSnackbarManager` and `MDCSnackbarMessage`.
32+
First, create an instance of `MDCSnackbarMessage` and provide a string to display to the user. Next,
33+
pass the `MDCSnackbarMessage` to `MDCSnackbarManager.defaultManager` with the static `-showMessage:` method. This will
34+
automatically construct an `MDCSnackbarMessageView` and appropriate overlay views so the snackbar is
35+
visible to the user.
6936

7037
Snackbar manager can be instructed to suspend and resume displaying messages as needed. When
7138
messages are suspended the manager provides a suspension token that the client must keep as long as
7239
messages are suspended. When the client releases the suspension token or calls the manager's resume
7340
method with the suspension token, then messages will resume being displayed.
74-
75-
## Installation
76-
77-
<!-- Extracted from docs/../../../docs/component-installation.md -->
78-
79-
### Installation with CocoaPods
41+
### Installing snackbars
8042

8143
Add the following to your `Podfile`:
8244

@@ -91,7 +53,7 @@ Then, run the following command:
9153
pod install
9254
```
9355

94-
### Importing
56+
### Importing snackbars
9557

9658
To import the component:
9759

@@ -108,40 +70,52 @@ import MaterialComponents.MaterialSnackbar
10870
```
10971
<!--</div>-->
11072

73+
### Making snackbars accessible
11174

112-
## Usage
75+
#### VoiceOver
11376

114-
Displaying a snackbar requires using two classes: MDCSnackbarManager and MDCSnackbarMessage.
115-
First, create an instance of MDCSnackbarMessage and provide a string to display to the user. Next,
116-
pass the MDCSnackbarMessage to the MDCSnackbarManager.defaultManager with the static showMessage method. This will
117-
automatically construct an MDCSnackbarMessageView and appropriate overlay views so the snackbar is
118-
visible to the user.
77+
Snackbars have automatic VoiceOver support through UIKit, but `MDCSnackbarMessageView` also exposes `accessibilityLabel` and `accessibilityHint` properties for overriding the default values.
11978

120-
<!-- Extracted from docs/typical-use-display-a-message.md -->
79+
#### Dynamic Type
12180

122-
### Typical use: display a message
81+
`MDCSnackbarMessageView` has a `mdc_adjustsFontForContentSizeCategory` property that is modeled after Apple's `adjustsFontForContentSizeCategory` property. Set this property to `YES` for font scaling according to the current trait environment.
12382

124-
<!--<div class="material-code-render" markdown="1">-->
125-
#### Swift
83+
## Snackbars anatomy and key properties
12684

127-
```swift
128-
let message = MDCSnackbarMessage()
129-
message.text = "The groundhog (Marmota monax) is also known as a woodchuck or whistlepig."
130-
MDCSnackbarManager.show(message)
131-
```
85+
The following is an anatomy diagram of a snackbar:
13286

133-
#### Objective-C
87+
![Snackbar anatomy diagram](docs/assets/snackbars-anatomy.png)
13488

135-
```objc
136-
MDCSnackbarMessage *message = [[MDCSnackbarMessage alloc] init];
137-
message.text = @"How much wood would a woodchuck chuck if a woodchuck could chuck wood?";
138-
[MDCSnackbarManager.defaultManager showMessage:message];
139-
```
140-
<!--</div>-->
89+
1. Text label
90+
1. Container
91+
1. Action (optional)
92+
93+
### Text label attributes
94+
95+
&nbsp; | Attribute | Related method(s) | Default value
96+
-------------------- | ------------------------ | ----------------- | -------------
97+
**Text label** | `text` | `-[MDCSnackBarMessageView setText:]` <br/> `-[MDCSnackBarMessageView text]` | `nil`
98+
**Color** | `messageTextColor` | `-[MDCSnackBarMessageView setMessageTextColor:]` <br/> `-[MDCSnackBarMessageView messageTextColor]` | White at 60% opacity
99+
**Typography** | `messageFont` | `-[MDCSnackBarMessageView setMessageFont:]` <br/> `-[MDCSnackBarMessageView messageFont]` | System body font.
100+
101+
### Container attributes
141102

142-
<!-- Extracted from docs/typical-use-display-a-message-with-action.md -->
103+
&nbsp; | Attribute | Related method(s) | Default value
104+
----------------------- | --------------------------------- | ----------------------------------------------- | -------------
105+
**Color** | `snackbarMessageViewBackgroundColor` | `-[MDCSnackBarMessageView setSnackbarMessageViewBackgroundColor:]` <br/> `-[MDCSnackBarMessageView snackbarMessageViewBackgroundColor]` | `#323232`
106+
**Elevation** | `elevation` | `-[MDCSnackBarMessageView setElevation:]` <br/> `-[MDCSnackBarMessageView elevation]` | `6`
107+
### Action attributes
143108

144-
### Typical use: display a message with an action
109+
&nbsp; | Attribute | Related method(s) | Default value
110+
-------------------- | -------------------------- | -------------------- | -------------
111+
**Color** | N/A | `-[MDCSnackBarMessageView setButtonTitleColor:forState:]` <br/> `-[MDCSnackBarMessageView buttonTitleColorForState]` | White at 60% opacity
112+
**Typography** | `buttonFont` | `-[MDCSnackBarMessageView setButtonFont:]` <br/> `-[MDCSnackBarMessageView buttonFont]` | System body font.
113+
114+
## Snackbar example
115+
116+
![Snackbar with a message and an action](docs/assets/snackbar-example.png)
117+
118+
The following is an example of a snackbar with a message and an action button:
145119

146120
<!--<div class="material-code-render" markdown="1">-->
147121
#### Swift
@@ -164,21 +138,15 @@ message.action = action
164138
MDCSnackbarMessageAction *action = [[MDCSnackbarMessageAction alloc] init];
165139
void (^actionHandler)() = ^() {
166140
MDCSnackbarMessage *answerMessage = [[MDCSnackbarMessage alloc] init];
167-
answerMessage.text = @"A lot";
141+
answerMessage.text = @"A red flair silhouetted the jagged edge of a sublime wing.";
168142
[MDCSnackbarManager.defaultManager showMessage:answerMessage];
169143
};
170144
action.handler = actionHandler;
171-
action.title = @"Answer";
145+
action.title = "Action";
172146
message.action = action;
173147
```
174148
<!--</div>-->
175149

150+
## Theming snackbars
176151

177-
## Extensions
178-
179-
<!-- Extracted from docs/color-theming.md -->
180-
181-
### Color Theming
182-
183-
There is currently no theing extension for MDCSnackbar.
184-
152+
Snacksbars on iOS do not support theming.

components/Snackbar/docs/README.md

Lines changed: 0 additions & 55 deletions
This file was deleted.
Loading
-67.3 KB
Binary file not shown.
Loading
Loading

components/Snackbar/docs/color-theming.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

components/Snackbar/docs/typical-use-display-a-message-with-action.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

components/Snackbar/docs/typical-use-display-a-message.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)