Repository navigation
feat: modernize drawer #5052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: modernize drawer #5052
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
555b23e
refactor(drawer): align with latest MD3 navigation drawer spec
b746c65
docs(drawer): showcase the modernized Drawer and refresh docs
ad5c200
docs: record Drawer modernization decisions and MD3 glossary
b845692
docs: correct theme color roles in component tables
d85720f
Merge branch 'claude/wonderful-ptolemy-6f0db6' into feat/modernize-dr…
de1a5c0
fix(drawer): dim disabled destinations
ddb2b9c
fix(jest): exclude .claude worktrees from test discovery
cb43d83
Revert "docs: record Drawer modernization decisions and MD3 glossary"
f6e0a26
chore: remove some comments
ce6db57
refactor(drawer): apply review feedback
0ee42bc
chore: remove some comments
d71d652
fix: drawer width
09fe61b
docs(drawer): recapture screenshots to match the original views
c665c63
fix(drawer): use onSurface for focused inactive items
bb6126e
Merge upstream/main into feat/modernize-drawer
347a463
fix(drawer): address review feedback
6e91d4a
Merge remote-tracking branch 'upstream/main' into feat/modernize-drawer
6d96304
Merge remote-tracking branch 'upstream/main' into feat/modernize-drawer
13aafdc
fix(drawer): valid destination semantics and MD3 hover/pressed colours
7af7bba
Update migration guide for Drawer API changes
Doberjohn 16ba961
Fix section title wording in DrawerExample
Doberjohn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,211 @@ | ||
| import * as React from 'react'; | ||
| import { StyleSheet, View } from 'react-native'; | ||
| import type { ColorValue } from 'react-native'; | ||
|
|
||
| import { Badge, Drawer, Text, useTheme } from 'react-native-paper'; | ||
|
|
||
| import ScreenWrapper from '../ScreenWrapper'; | ||
|
|
||
| const DRAWER_WIDTH = 360; | ||
|
|
||
| const Section = ({ | ||
| title, | ||
| children, | ||
| }: { | ||
| title: string; | ||
| children: React.ReactNode; | ||
| }) => { | ||
| const theme = useTheme(); | ||
|
|
||
| return ( | ||
| <View style={styles.section}> | ||
| <Text | ||
| variant="labelSmall" | ||
| style={[styles.caption, { color: theme.colors.onSurfaceVariant }]} | ||
| > | ||
| {title} | ||
| </Text> | ||
| <View | ||
| style={[ | ||
| styles.drawer, | ||
| { backgroundColor: theme.colors.surfaceContainerLow }, | ||
| ]} | ||
| > | ||
| {children} | ||
| </View> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| const Destinations = () => { | ||
| const [active, setActive] = React.useState('inbox'); | ||
|
|
||
| return ( | ||
| <Drawer.Section title="Mail" showDivider={false}> | ||
| <Drawer.Item | ||
| icon="inbox" | ||
| label="Inbox" | ||
| active={active === 'inbox'} | ||
| onPress={() => setActive('inbox')} | ||
| right={() => <Text variant="labelLarge">24</Text>} | ||
| /> | ||
| <Drawer.Item | ||
| icon="star" | ||
| label="Starred" | ||
| active={active === 'starred'} | ||
| onPress={() => setActive('starred')} | ||
| /> | ||
| <Drawer.Item | ||
| icon="send" | ||
| label="Sent" | ||
| active={active === 'sent'} | ||
| onPress={() => setActive('sent')} | ||
| /> | ||
| </Drawer.Section> | ||
| ); | ||
| }; | ||
|
|
||
| const DrawerExample = () => { | ||
| const [collapsed, setCollapsed] = React.useState('inbox'); | ||
| // The destinations in the sections below share one active destination, so | ||
| // each of them can be pressed and focused like a real one. | ||
| const [selected, setSelected] = React.useState<string>(); | ||
| const destination = (key: string) => ({ | ||
| active: selected === key, | ||
| onPress: () => setSelected(key), | ||
| }); | ||
|
|
||
| return ( | ||
| <ScreenWrapper contentContainerStyle={styles.content}> | ||
| <Section title="Destinations: tap to change the active one"> | ||
| <Destinations /> | ||
| </Section> | ||
|
|
||
| <Section title="Without an icon, and with a truncated label"> | ||
| <Drawer.Section showDivider={false}> | ||
| <Drawer.Item label="No icon" {...destination('no-icon')} /> | ||
| <Drawer.Item | ||
| icon="delete" | ||
| label="A very long destination label that will be truncated" | ||
| {...destination('truncated')} | ||
| /> | ||
| </Drawer.Section> | ||
| </Section> | ||
|
|
||
| <Section title="Disabled"> | ||
| <Drawer.Section showDivider={false}> | ||
| <Drawer.Item icon="archive" label="Archive" disabled /> | ||
| <Drawer.Item | ||
| icon="star" | ||
| label="Active and disabled" | ||
| active | ||
| disabled | ||
| right={() => <Text variant="labelLarge">24</Text>} | ||
| /> | ||
| </Drawer.Section> | ||
| </Section> | ||
|
|
||
| <Section title="Trailing slot"> | ||
| <Drawer.Section showDivider={false}> | ||
| <Drawer.Item | ||
| icon="alert" | ||
| label="Badge" | ||
| right={() => <Badge visible style={styles.badge} />} | ||
| {...destination('badge')} | ||
| /> | ||
| <Drawer.Item | ||
| icon="palette" | ||
| label="Coloured dot" | ||
| {...destination('dot')} | ||
| right={({ color }: { color: ColorValue }) => ( | ||
| <Badge | ||
| visible | ||
| style={[styles.badge, { backgroundColor: color }]} | ||
| /> | ||
| )} | ||
| /> | ||
| </Drawer.Section> | ||
| </Section> | ||
|
|
||
| <Section title="Sections separated by a divider"> | ||
| <Drawer.Section title="Mailboxes"> | ||
| <Drawer.Item | ||
| icon="inbox" | ||
| label="Inbox" | ||
| {...destination('mailboxes-inbox')} | ||
| /> | ||
| </Drawer.Section> | ||
| <Drawer.Section title="Labels" showDivider={false}> | ||
| <Drawer.Item icon="tag" label="Work" {...destination('work')} /> | ||
| </Drawer.Section> | ||
| </Section> | ||
|
|
||
| <Section title="Collapsed destinations"> | ||
| <View style={styles.collapsed}> | ||
| <Drawer.CollapsedItem | ||
| focusedIcon="inbox" | ||
| unfocusedIcon="inbox-outline" | ||
| label="Inbox" | ||
| badge={24} | ||
| active={collapsed === 'inbox'} | ||
| onPress={() => setCollapsed('inbox')} | ||
| /> | ||
| <Drawer.CollapsedItem | ||
| focusedIcon="star" | ||
| unfocusedIcon="star-outline" | ||
| label="Starred" | ||
| active={collapsed === 'starred'} | ||
| onPress={() => setCollapsed('starred')} | ||
| /> | ||
| <Drawer.CollapsedItem | ||
| focusedIcon="bell" | ||
| unfocusedIcon="bell-outline" | ||
| badge | ||
| aria-label="Alerts" | ||
| active={collapsed === 'alerts'} | ||
| onPress={() => setCollapsed('alerts')} | ||
| /> | ||
|
Doberjohn marked this conversation as resolved.
Resolved
|
||
| <Drawer.CollapsedItem | ||
| focusedIcon="archive" | ||
| unfocusedIcon="archive-outline" | ||
| label="Disabled" | ||
| disabled | ||
| /> | ||
| </View> | ||
| </Section> | ||
| </ScreenWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| DrawerExample.title = 'Drawer'; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| content: { | ||
| paddingVertical: 16, | ||
| }, | ||
| section: { | ||
| marginBottom: 24, | ||
| }, | ||
| caption: { | ||
| marginBottom: 8, | ||
| marginHorizontal: 16, | ||
| }, | ||
| drawer: { | ||
| width: DRAWER_WIDTH, | ||
| maxWidth: '100%', | ||
| alignSelf: 'center', | ||
| paddingVertical: 8, | ||
| borderTopEndRadius: 16, | ||
| borderBottomEndRadius: 16, | ||
| }, | ||
| badge: { | ||
| alignSelf: 'center', | ||
| }, | ||
| collapsed: { | ||
| flexDirection: 'row', | ||
| justifyContent: 'center', | ||
| paddingVertical: 8, | ||
| }, | ||
| }); | ||
|
|
||
| export default DrawerExample; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.