Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/components/HighlightableMenuItemWithTopDescription.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useTheme from '@hooks/useTheme';
import MenuItem from './MenuItem';
import type {MenuItemProps} from './MenuItem';

type HighlightableMenuItemWithTopDescriptionProps = MenuItemProps & {
/** Should the menu item be highlighted? */
highlighted?: boolean;
};

function HighlightableMenuItemWithTopDescription({highlighted, outerWrapperStyle, ref, ...props}: HighlightableMenuItemWithTopDescriptionProps) {
const theme = useTheme();
const animatedHighlightStyle = useAnimatedHighlightStyle({
shouldHighlight: highlighted ?? false,
highlightColor: theme.messageHighlightBG,
itemEnterDelay: 0,
});

return (
<MenuItem
{...props}
ref={ref}
shouldShowBasicTitle
shouldShowDescriptionOnTop
// The animated highlight style is always applied (never swapped on `highlighted`) so the entry fade is never
// detached from the node mid-animation. When `highlighted` is false the hook returns a static opacity: 1, so
// this is inert for non-highlighted rows. See https://github.com/Expensify/App/issues/94005.
outerWrapperStyle={[outerWrapperStyle, animatedHighlightStyle]}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot No need for a comment here and instead of rendering a MenuItem, let's render MenuItemWithTopDescription here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot No need for a comment here and instead of rendering a MenuItem, let's render MenuItemWithTopDescription here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7f5ec07. Now renders MenuItemWithTopDescription (which already sets shouldShowBasicTitle/shouldShowDescriptionOnTop) and removed the comment.

/>
);
}

export default HighlightableMenuItemWithTopDescription;
17 changes: 1 addition & 16 deletions src/components/MenuItemWithTopDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
import React from 'react';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useTheme from '@hooks/useTheme';
import MenuItem from './MenuItem';
import type {MenuItemProps} from './MenuItem';

type MenuItemWithTopDescriptionProps = MenuItemProps & {
/** Should the menu item be highlighted? */
highlighted?: boolean;
};

function MenuItemWithTopDescription({highlighted, outerWrapperStyle, ref, ...props}: MenuItemWithTopDescriptionProps) {
const theme = useTheme();
const highlightedOuterWrapperStyle = useAnimatedHighlightStyle({
shouldHighlight: highlighted ?? false,
highlightColor: theme.messageHighlightBG,
itemEnterDelay: 0,
});

function MenuItemWithTopDescription({ref, ...props}: MenuItemProps) {
return (
<MenuItem
{...props}
ref={ref}
shouldShowBasicTitle
shouldShowDescriptionOnTop
outerWrapperStyle={highlighted ? highlightedOuterWrapperStyle : outerWrapperStyle}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import type {ValueOf} from 'type-fest';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import HighlightableMenuItemWithTopDescription from '@components/HighlightableMenuItemWithTopDescription';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -53,7 +53,7 @@ function TagFields({
const displayedTag = tagDisplay ?? '';

return (
<MenuItemWithTopDescription
<HighlightableMenuItemWithTopDescription
highlighted={!displayedTag && !previousShouldShow}
shouldShowRightIcon={!isReadOnly}
title={displayedTag}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {useOnyx as originalUseOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
import HighlightableMenuItemWithTopDescription from '@components/HighlightableMenuItemWithTopDescription';
import Icon from '@components/Icon';
import MenuItem from '@components/MenuItem';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
Expand Down Expand Up @@ -1023,7 +1024,7 @@ function MoneyRequestView({
key={name}
pendingAction={getPendingFieldAction('tag')}
>
<MenuItemWithTopDescription
<HighlightableMenuItemWithTopDescription
highlighted={hasDependentTags && shouldShow && !getTagForDisplay(transaction, index) && currentTagLength > previousTagLength}
description={name ?? translate('common.tag')}
title={tagForDisplay}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/iou/SplitExpenseEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView
import Button from '@components/Button';
import FixedFooter from '@components/FixedFooter';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import HighlightableMenuItemWithTopDescription from '@components/HighlightableMenuItemWithTopDescription';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
Expand Down Expand Up @@ -377,7 +378,7 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) {
}

return (
<MenuItemWithTopDescription
<HighlightableMenuItemWithTopDescription
shouldShowRightIcon
key={name}
highlighted={!getTagForDisplay(splitExpenseDraftTransaction, index) && !prevShouldShow}
Expand Down
Loading