Skip to content

Commit

Permalink
feat: add drawerAllowFontScaling prop to drawer package (#10041)
Browse files Browse the repository at this point in the history
Add `drawerAllowFontScaling` to the drawer options, so consumers can enable or disable font scaling for drawer labels to respect Text Size accessibility settings. The option functions similarly to [`tabBarAllowFontScaling`](tabBarAllowFontScaling).

Co-authored-by: Kyle Edgette <kyle@join-real.com>
  • Loading branch information
edgettek and Kyle Edgette authored Feb 1, 2022
1 parent 01048a5 commit 43f981a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/drawer/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export type DrawerNavigationOptions = HeaderOptions & {
*/
drawerInactiveBackgroundColor?: string;

/**
* Whether label font should scale to respect Text Size accessibility settings.
*/
drawerAllowFontScaling?: boolean;

/**
* Style object for the single item, which can contain an icon and/or a label.
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/drawer/src/views/DrawerItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ type Props = {
* Style object for the wrapper element.
*/
style?: StyleProp<ViewStyle>;
/**
* Whether label font should scale to respect Text Size accessibility settings.
*/
allowFontScaling?: boolean;
};

const LinkPressable = ({
Expand Down Expand Up @@ -141,6 +145,7 @@ export default function DrawerItem(props: Props) {
labelStyle,
to,
focused = false,
allowFontScaling,
activeTintColor = colors.primary,
inactiveTintColor = Color(colors.text).alpha(0.68).rgb().string(),
activeBackgroundColor = Color(activeTintColor).alpha(0.12).rgb().string(),
Expand Down Expand Up @@ -186,6 +191,7 @@ export default function DrawerItem(props: Props) {
{typeof label === 'string' ? (
<Text
numberOfLines={1}
allowFontScaling={allowFontScaling}
style={[
{
color,
Expand Down
2 changes: 2 additions & 0 deletions packages/drawer/src/views/DrawerItemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function DrawerItemList({
drawerIcon,
drawerLabelStyle,
drawerItemStyle,
drawerAllowFontScaling,
} = descriptors[route.key].options;

return (
Expand All @@ -63,6 +64,7 @@ export default function DrawerItemList({
inactiveTintColor={drawerInactiveTintColor}
activeBackgroundColor={drawerActiveBackgroundColor}
inactiveBackgroundColor={drawerInactiveBackgroundColor}
allowFontScaling={drawerAllowFontScaling}
labelStyle={drawerLabelStyle}
style={drawerItemStyle}
to={buildLink(route.name, route.params)}
Expand Down

0 comments on commit 43f981a

Please sign in to comment.