Skip to content

Commit 942d665

Browse files
fix regression
1 parent 904ee16 commit 942d665

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type {ForwardedRef} from 'react';
2+
import {forwardRef} from 'react';
3+
import type {View} from 'react-native';
4+
import {StyleSheet} from 'react-native';
5+
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
6+
import useThemeStyles from '@hooks/useThemeStyles';
7+
import MenuItem from './MenuItem';
8+
import type {MenuItemProps} from './MenuItem';
9+
10+
type Props = MenuItemProps & {
11+
highlighted?: boolean;
12+
};
13+
14+
function HighlightableMenuItem({wrapperStyle, highlighted, ...restOfProps}: Props, ref: ForwardedRef<View>) {
15+
const styles = useThemeStyles();
16+
17+
const flattenedWrapperStyles = StyleSheet.flatten(wrapperStyle);
18+
const animatedHighlightStyle = useAnimatedHighlightStyle({
19+
shouldHighlight: highlighted ?? false,
20+
height: flattenedWrapperStyles?.height ? Number(flattenedWrapperStyles.height) : styles.sectionMenuItem.height,
21+
borderRadius: flattenedWrapperStyles?.borderRadius ? Number(flattenedWrapperStyles.borderRadius) : styles.sectionMenuItem.borderRadius,
22+
});
23+
24+
return (
25+
// eslint-disable-next-line react/jsx-props-no-spreading
26+
<MenuItem
27+
{...restOfProps}
28+
wrapperStyle={animatedHighlightStyle}
29+
ref={ref}
30+
/>
31+
);
32+
}
33+
34+
HighlightableMenuItem.displayName = 'HighlightableMenuItem';
35+
36+
export default forwardRef(HighlightableMenuItem);

src/components/MenuItem.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import type {ImageContentFit} from 'expo-image';
33
import type {ForwardedRef, ReactNode} from 'react';
44
import React, {forwardRef, useContext, useMemo} from 'react';
55
import type {GestureResponderEvent, StyleProp, TextStyle, ViewStyle} from 'react-native';
6-
import {StyleSheet, View} from 'react-native';
6+
import {View} from 'react-native';
77
import type {AnimatedStyle} from 'react-native-reanimated';
88
import type {ValueOf} from 'type-fest';
9-
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
109
import useStyleUtils from '@hooks/useStyleUtils';
1110
import useTheme from '@hooks/useTheme';
1211
import useThemeStyles from '@hooks/useThemeStyles';
@@ -72,6 +71,9 @@ type MenuItemBaseProps = {
7271
/** Used to apply offline styles to child text components */
7372
style?: StyleProp<ViewStyle>;
7473

74+
/** Outer wrapper styles */
75+
outerWrapperStyle?: StyleProp<ViewStyle>;
76+
7577
/** Any additional styles to apply */
7678
wrapperStyle?: StyleProp<ViewStyle>;
7779

@@ -150,9 +152,6 @@ type MenuItemBaseProps = {
150152
/** Whether item is focused or active */
151153
focused?: boolean;
152154

153-
/** Whether item is highlighted */
154-
highlighted?: boolean;
155-
156155
/** Should we disable this menu item? */
157156
disabled?: boolean;
158157

@@ -261,6 +260,7 @@ function MenuItem(
261260
badgeText,
262261
style,
263262
wrapperStyle,
263+
outerWrapperStyle,
264264
containerStyle,
265265
titleStyle,
266266
hoverAndPressStyle,
@@ -290,7 +290,6 @@ function MenuItem(
290290
success = false,
291291
focused = false,
292292
disabled = false,
293-
highlighted = false,
294293
title,
295294
subtitle,
296295
shouldShowBasicTitle,
@@ -330,13 +329,8 @@ function MenuItem(
330329
const StyleUtils = useStyleUtils();
331330
const combinedStyle = [style, styles.popoverMenuItem];
332331
const {isSmallScreenWidth} = useWindowDimensions();
333-
const flattenedWrapperStyles = StyleSheet.flatten(wrapperStyle);
334-
const animatedHighlightStyle = useAnimatedHighlightStyle({
335-
shouldHighlight: highlighted,
336-
height: flattenedWrapperStyles?.height ? Number(flattenedWrapperStyles.height) : styles.sectionMenuItem.height,
337-
borderRadius: flattenedWrapperStyles?.borderRadius ? Number(flattenedWrapperStyles.borderRadius) : styles.sectionMenuItem.borderRadius,
338-
});
339332
const {isExecuting, singleExecution, waitForNavigate} = useContext(MenuItemGroupContext) ?? {};
333+
340334
const isDeleted = style && Array.isArray(style) ? style.includes(styles.offlineFeedback.deleted) : false;
341335
const descriptionVerticalMargin = shouldShowDescriptionOnTop ? styles.mb1 : styles.mt1;
342336
const fallbackAvatarSize = viewMode === CONST.OPTION_MODE.COMPACT ? CONST.AVATAR_SIZE.SMALL : CONST.AVATAR_SIZE.DEFAULT;
@@ -436,7 +430,7 @@ function MenuItem(
436430
onPressIn={() => shouldBlockSelection && isSmallScreenWidth && DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()}
437431
onPressOut={ControlSelection.unblock}
438432
onSecondaryInteraction={onSecondaryInteraction}
439-
wrapperStyle={animatedHighlightStyle}
433+
wrapperStyle={outerWrapperStyle}
440434
style={({pressed}) =>
441435
[
442436
containerStyle,

src/pages/workspace/WorkspaceInitialPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import type {ValueOf} from 'type-fest';
88
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
99
import ConfirmModal from '@components/ConfirmModal';
1010
import HeaderWithBackButton from '@components/HeaderWithBackButton';
11+
import HighlightableMenuItem from '@components/HighlightableMenuItem';
1112
import * as Expensicons from '@components/Icon/Expensicons';
12-
import MenuItem from '@components/MenuItem';
1313
import OfflineWithFeedback from '@components/OfflineWithFeedback';
1414
import ScreenWrapper from '@components/ScreenWrapper';
1515
import ScrollView from '@components/ScrollView';
@@ -278,7 +278,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r
278278
In this case where user can click on workspace avatar or menu items, we need to have a check for `isExecuting`. So, we are directly mapping menuItems.
279279
*/}
280280
{menuItems.map((item) => (
281-
<MenuItem
281+
<HighlightableMenuItem
282282
key={item.translationKey}
283283
disabled={hasPolicyCreationError || isExecuting}
284284
interactive={!hasPolicyCreationError}

0 commit comments

Comments
 (0)