Repository navigation
refactor: modernize Divider to latest MD3 spec - #5089
mikolajadamowicz wants to merge 3 commits into
Conversation
JKobrynski
left a comment
There was a problem hiding this comment.
One minor comment, we've also got conflicts
JKobrynski
left a comment
There was a problem hiding this comment.
LGTM in general, one minor comment + we've got conflicts
JKobrynski
left a comment
There was a problem hiding this comment.
@satya164 all yours!
| * horizontal divider, top and bottom on a vertical one. | ||
| */ | ||
| bold?: boolean; | ||
| horizontalInset?: boolean; |
There was a problem hiding this comment.
The MD3 spec doesn't define insets for vertical dividers. The specs table lists insets only as left/right margins (inset 16/0dp, middle-inset 16/16dp), and the guidelines describe vertical dividers without any inset variants.
Compose's VerticalDivider has no inset parameter either, spacing goes through Modifier.padding.
Here startInset becomes marginTop and horizontalInset becomes marginTop/marginBottom on a vertical divider, so <Divider orientation="vertical" horizontalInset /> insets vertically, which the name doesn't suggest.
Two options:
- Don't apply
startInset/horizontalInsetwhenorientation="vertical"and leave spacing tostyle, like Compose. I'd prefer this one. - If we want insets on vertical dividers, rename
horizontalInsettomiddleInsetto match MD3's naming, so it reads right in both orientations. That's another breaking change, so it needs a migration row and an update inDrawerSection.
| isVertical ? styles.vertical : styles.horizontal, | ||
| { backgroundColor: theme.colors.outlineVariant }, | ||
| startInset && | ||
| (isVertical ? styles.verticalStartInset : styles.startInset), | ||
| horizontalInset && | ||
| (isVertical ? styles.verticalInset : styles.horizontalInset), |
There was a problem hiding this comment.
nit: isVertical ? … : … is repeated three times here. Grouping the styles by orientation would let us pick the set once:
const s = styles[orientation];
style={[
s.line,
{ backgroundColor: theme.colors.outlineVariant },
startInset && s.startInset,
horizontalInset && s.inset,
style,
]}
const styles = {
horizontal: StyleSheet.create({
line: { height: THICKNESS },
startInset: { marginStart: INSET },
inset: { marginStart: INSET, marginEnd: INSET },
}),
vertical: StyleSheet.create({
line: { width: THICKNESS, alignSelf: 'stretch' },
startInset: { marginTop: INSET },
inset: { marginTop: INSET, marginBottom: INSET },
}),
};# Conflicts: # docs/6.x/docs/guides/migration.md # src/components/Drawer/DrawerSection.tsx # src/components/__tests__/Drawer/__snapshots__/DrawerSection.test.tsx.snap
jacekAtCK
left a comment
There was a problem hiding this comment.
seems like we need ! in the PR title since bold and leftInset are gone? also left some comments below.
|
|
||
| ```diff | ||
| - <Divider /> | ||
| + <Divider style={{ height: StyleSheet.hairlineWidth }} /> |
There was a problem hiding this comment.
nit: on a vertical divider the hairline override is width: StyleSheet.hairlineWidth not height.
| * horizontal divider, top and bottom on a vertical one. | ||
| */ | ||
| bold?: boolean; | ||
| horizontalInset?: boolean; |
Motivation
Dividerwas drawing aStyleSheet.hairlineWidthline, which is thinner than 1dp on most screens, and the full 1dp line the Material Design 3 spec asks for was only reachable throughbold.leftInsetsetmarginLeft, so in RTL the inset stayed on the left instead of moving to the leading edge. MD3 also lists a vertical divider, which we had no way to render.This is primitive level work for the v6 effort. The consumers (List, Dialog, Drawer, DataTable) pick up the corrected divider in their own tasks.
Changes
StyleSheet.hairlineWidth→1dp, applied asheightwhen horizontal andwidthwhen verticalleftInset(marginLeft: 16) →startInset(marginStart: 16), so it follows the writing directionorientation="horizontal" | "vertical". A vertical divider is 1dp wide and usesalignSelf: 'stretch'to take the height of its parentstartInsetinsets the top edge andhorizontalInsetinsets the top and bottom edgesaria-hiddenby default, so screen readers skip it and it stays out of the focus order. React Native maps that toaccessibilityElementsHiddenon iOS andimportantForAccessibility="no-hide-descendants"on Android. It is spread before...rest, so<Divider accessible aria-hidden={false} role="separator" />opts back inBreaking change
The
boldandleftInsetprops have been removed.boldexisted only to reach 1dp, which is now the default. For the old hairline line, passstyle={{ height: StyleSheet.hairlineWidth }}.The full entry is in
docs/6.x/docs/guides/migration.md.Callsites updated
src/components/Searchbar.tsxandsrc/components/Drawer/DrawerSection.tsxdroppedbold, so they render the same as beforeexample/src/Examples/DividerExample.tsxnow shows full width, start inset, both side inset and vertical dividersexample/src/Examples/FABExample.tsxdroppedboldsrc/components/__tests__/Drawer/__snapshots__/DrawerSection.test.tsx.snapupdatedRelated issue
N/A
Test plan
yarn lintcleanyarn typecheckclean, plustsc --noEmitinexample/yarn test56 suites, 743 passed, including 11 newDividertests insrc/components/__tests__/Divider.test.tsxyarn docs buildclean,Divider.mdxandcomponentDocs6x.jsonregeneratedTo check it by hand, open the example app, go to the Divider screen and compare against
main. The line is visibly thicker, and the vertical section is new.Visual verification