Skip to content

Commit b26bd03

Browse files
committed
refactor: migrate SettingsMenuItem to the new pattern
1 parent 2689ed5 commit b26bd03

2 files changed

Lines changed: 41 additions & 33 deletions

File tree

src/pages/settings/InitialSettingsPage.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,10 @@ type MenuData = WithSentryLabel & {
9494
brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS>;
9595
action: () => void;
9696
link?: string | (() => Promise<string>);
97-
iconType?: typeof CONST.ICON_TYPE_ICON | typeof CONST.ICON_TYPE_AVATAR | typeof CONST.ICON_TYPE_WORKSPACE;
98-
iconStyles?: StyleProp<ViewStyle>;
99-
fallbackIcon?: IconAsset;
100-
shouldStackHorizontally?: boolean;
101-
avatarSize?: ValueOf<typeof CONST.AVATAR_SIZE>;
102-
floatRightAvatars?: TIcon[];
10397
title?: string;
104-
shouldShowRightIcon?: boolean;
10598
iconRight?: IconAsset;
10699
badgeText?: string;
107-
badgeStyle?: ViewStyle;
108100
isBadgeSuccess?: boolean;
109-
isBadgeStrong?: boolean;
110101
isBadgeCondensed?: boolean;
111102
};
112103

@@ -414,7 +405,6 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
414405
translationKey: 'initialSettingsPage.whatIsNew',
415406
icon: icons.TreasureChest,
416407
iconRight: icons.NewWindow,
417-
shouldShowRightIcon: true,
418408
sentryLabel: CONST.SENTRY_LABEL.SETTINGS_GENERAL.WHATS_NEW,
419409
link: CONST.WHATS_NEW_URL,
420410
action: () => {

src/pages/settings/SettingsMenuItem.tsx

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import MenuItem from '@components/MenuItem';
1+
import MenuItem from '@components/MenuItem/compound';
2+
import getContextMenuAccessibilityHint from '@components/utils/getContextMenuAccessibilityHint';
3+
import getContextMenuAccessibilityProps from '@components/utils/getContextMenuAccessibilityProps';
4+
5+
import useLocalize from '@hooks/useLocalize';
26

37
import {showContextMenu} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu';
48

@@ -21,6 +25,7 @@ type SettingsMenuItemProps = {
2125
};
2226

2327
function SettingsMenuItem({item, isFocused, keyTitle, isExecuting, isScreenFocused, onPress, wrapperStyle}: SettingsMenuItemProps) {
28+
const {translate} = useLocalize();
2429
const popoverAnchor = useRef(null);
2530

2631
const onSecondaryInteraction = item.link
@@ -49,35 +54,48 @@ function SettingsMenuItem({item, isFocused, keyTitle, isExecuting, isScreenFocus
4954
}
5055
: undefined;
5156

57+
const combinedAccessibilityLabel = [keyTitle, item.brickRoadIndicator ? translate('common.yourReviewIsRequired') : ''].filter(Boolean).join('. ');
58+
const contextMenuHint = item.link ? getContextMenuAccessibilityHint({translate}) : undefined;
59+
const {accessibilityLabel, accessibilityHint} = getContextMenuAccessibilityProps({accessibilityLabel: combinedAccessibilityLabel, contextMenuHint});
60+
61+
const hasTrailing = !!item.badgeText || !!item.brickRoadIndicator || !!item.iconRight;
62+
5263
return (
5364
<MenuItem
54-
wrapperStyle={wrapperStyle}
55-
title={keyTitle}
56-
icon={item.icon}
57-
iconType={item.iconType}
58-
disabled={isExecuting}
59-
onPress={onPress}
60-
iconStyles={item.iconStyles}
61-
badgeText={item.badgeText}
62-
badgeStyle={item.badgeStyle}
63-
isBadgeSuccess={item.isBadgeSuccess}
64-
isBadgeStrong={item.isBadgeStrong}
65-
isBadgeCondensed={item.isBadgeCondensed}
66-
fallbackIcon={item.fallbackIcon}
67-
brickRoadIndicator={item.brickRoadIndicator}
68-
shouldStackHorizontally={item.shouldStackHorizontally}
6965
ref={popoverAnchor}
70-
shouldBlockSelection={!!item.link}
66+
style={wrapperStyle}
67+
onPress={onPress}
7168
onSecondaryInteraction={onSecondaryInteraction}
72-
shouldShowContextMenuHint={!!item.link}
69+
disabled={isExecuting}
7370
focused={isFocused}
7471
role={CONST.ROLE.TAB}
75-
isPaneMenu
72+
accessibilityLabel={accessibilityLabel}
73+
accessibilityHint={accessibilityHint}
7674
sentryLabel={item.sentryLabel}
77-
iconRight={item.iconRight}
78-
shouldShowRightIcon={item.shouldShowRightIcon}
79-
shouldIconUseAutoWidthStyle
80-
/>
75+
>
76+
<MenuItem.Row>
77+
<MenuItem.Icon
78+
src={item.icon}
79+
variant={CONST.MENU_ITEM.ICON_VARIANT.COMPACT}
80+
/>
81+
<MenuItem.Content>
82+
<MenuItem.Title>{keyTitle}</MenuItem.Title>
83+
</MenuItem.Content>
84+
{hasTrailing && (
85+
<MenuItem.Trailing>
86+
{!!item.badgeText && (
87+
<MenuItem.Badge
88+
text={item.badgeText}
89+
success={item.isBadgeSuccess}
90+
isCondensed={item.isBadgeCondensed}
91+
/>
92+
)}
93+
{!!item.brickRoadIndicator && <MenuItem.BrickRoadIndicator status={item.brickRoadIndicator} />}
94+
{!!item.iconRight && <MenuItem.Chevron src={item.iconRight} />}
95+
</MenuItem.Trailing>
96+
)}
97+
</MenuItem.Row>
98+
</MenuItem>
8199
);
82100
}
83101

0 commit comments

Comments
 (0)