Skip to content

Commit

Permalink
Merge pull request #50028 from ikevin127/ikevin127-searchRefactoringF…
Browse files Browse the repository at this point in the history
…or49457

Search highlight and scroll animation refactoring for 49457
  • Loading branch information
luacmartins authored Oct 2, 2024
2 parents 05dcac8 + 78e36d1 commit d08bb58
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
13 changes: 2 additions & 11 deletions src/components/SelectionList/BaseListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useHover from '@hooks/useHover';
import {useMouseContext} from '@hooks/useMouseContext';
import useSyncFocus from '@hooks/useSyncFocus';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type {BaseListItemProps, ListItem} from './types';

function BaseListItem<TItem extends ListItem>({
item,
pressableStyle,
wrapperStyle,
pressableWrapperStyle,
containerStyle,
isDisabled = false,
shouldPreventEnterKeySubmit = false,
Expand All @@ -36,7 +35,6 @@ function BaseListItem<TItem extends ListItem>({
onFocus = () => {},
hoverStyle,
onLongPressRow,
hasAnimateInHighlightStyle = false,
}: BaseListItemProps<TItem>) {
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -64,13 +62,6 @@ function BaseListItem<TItem extends ListItem>({
return rightHandSideComponent;
};

const animatedHighlightStyle = useAnimatedHighlightStyle({
borderRadius: variables.componentBorderRadius,
shouldHighlight: item?.shouldAnimateInHighlight ?? false,
highlightColor: theme.messageHighlightBG,
backgroundColor: theme.highlightBG,
});

return (
<OfflineWithFeedback
onClose={() => onDismissError(item)}
Expand Down Expand Up @@ -109,7 +100,7 @@ function BaseListItem<TItem extends ListItem>({
onFocus={onFocus}
onMouseLeave={handleMouseLeave}
tabIndex={item.tabIndex}
wrapperStyle={hasAnimateInHighlightStyle ? [styles.mh5, animatedHighlightStyle] : []}
wrapperStyle={pressableWrapperStyle}
>
<View style={wrapperStyle}>
{typeof children === 'function' ? children(hovered) : children}
Expand Down
13 changes: 12 additions & 1 deletion src/components/SelectionList/Search/ReportListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import BaseListItem from '@components/SelectionList/BaseListItem';
import type {ListItem, ReportListItemProps, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types';
import Text from '@components/Text';
import TextWithTooltip from '@components/TextWithTooltip';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import ActionCell from './ActionCell';
Expand Down Expand Up @@ -62,10 +65,18 @@ function ReportListItem<TItem extends ListItem>({
}: ReportListItemProps<TItem>) {
const reportItem = item as unknown as ReportListItemType;

const theme = useTheme();
const styles = useThemeStyles();
const {isLargeScreenWidth} = useResponsiveLayout();
const StyleUtils = useStyleUtils();

const animatedHighlightStyle = useAnimatedHighlightStyle({
borderRadius: variables.componentBorderRadius,
shouldHighlight: item?.shouldAnimateInHighlight ?? false,
highlightColor: theme.messageHighlightBG,
backgroundColor: theme.highlightBG,
});

if (reportItem.transactions.length === 0) {
return;
}
Expand Down Expand Up @@ -143,7 +154,7 @@ function ReportListItem<TItem extends ListItem>({
onFocus={onFocus}
shouldSyncFocus={shouldSyncFocus}
hoverStyle={item.isSelected && styles.activeComponentBG}
hasAnimateInHighlightStyle
pressableWrapperStyle={[styles.mh5, animatedHighlightStyle]}
>
<View style={styles.flex1}>
{!isLargeScreenWidth && (
Expand Down
13 changes: 12 additions & 1 deletion src/components/SelectionList/Search/TransactionListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react';
import BaseListItem from '@components/SelectionList/BaseListItem';
import type {ListItem, TransactionListItemProps, TransactionListItemType} from '@components/SelectionList/types';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import TransactionListItemRow from './TransactionListItemRow';

function TransactionListItem<TItem extends ListItem>({
Expand All @@ -20,6 +23,7 @@ function TransactionListItem<TItem extends ListItem>({
}: TransactionListItemProps<TItem>) {
const transactionItem = item as unknown as TransactionListItemType;
const styles = useThemeStyles();
const theme = useTheme();

const {isLargeScreenWidth} = useResponsiveLayout();

Expand All @@ -40,6 +44,13 @@ function TransactionListItem<TItem extends ListItem>({
isLargeScreenWidth ? {...styles.flexRow, ...styles.justifyContentBetween, ...styles.alignItemsCenter} : {...styles.flexColumn, ...styles.alignItemsStretch},
];

const animatedHighlightStyle = useAnimatedHighlightStyle({
borderRadius: variables.componentBorderRadius,
shouldHighlight: item?.shouldAnimateInHighlight ?? false,
highlightColor: theme.messageHighlightBG,
backgroundColor: theme.highlightBG,
});

return (
<BaseListItem
item={item}
Expand All @@ -59,7 +70,7 @@ function TransactionListItem<TItem extends ListItem>({
onLongPressRow={onLongPressRow}
shouldSyncFocus={shouldSyncFocus}
hoverStyle={item.isSelected && styles.activeComponentBG}
hasAnimateInHighlightStyle
pressableWrapperStyle={[styles.mh5, animatedHighlightStyle]}
>
<TransactionListItemRow
item={transactionItem}
Expand Down
5 changes: 4 additions & 1 deletion src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
TextStyle,
ViewStyle,
} from 'react-native';
import type {AnimatedStyle} from 'react-native-reanimated';
import type {BrickRoad} from '@libs/WorkspacesSettingsUtils';
// eslint-disable-next-line no-restricted-imports
import type CursorStyles from '@styles/utils/cursor/types';
Expand Down Expand Up @@ -58,6 +59,9 @@ type CommonListItemProps<TItem extends ListItem> = {
/** Styles for the pressable component */
pressableStyle?: StyleProp<ViewStyle>;

/** Styles for the pressable component wrapper view */
pressableWrapperStyle?: StyleProp<AnimatedStyle<ViewStyle>>;

/** Styles for the wrapper view */
wrapperStyle?: StyleProp<ViewStyle>;

Expand Down Expand Up @@ -291,7 +295,6 @@ type BaseListItemProps<TItem extends ListItem> = CommonListItemProps<TItem> & {
children?: ReactElement<ListItemProps<TItem>> | ((hovered: boolean) => ReactElement<ListItemProps<TItem>>);
shouldSyncFocus?: boolean;
hoverStyle?: StyleProp<ViewStyle>;
hasAnimateInHighlightStyle?: boolean;
/** Errors that this user may contain */
shouldDisplayRBR?: boolean;
};
Expand Down

0 comments on commit d08bb58

Please sign in to comment.