Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 36 additions & 8 deletions src/components/SelectionListWithSections/SplitListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, {useCallback, useState} from 'react';
import React, {useCallback, useLayoutEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import Icon from '@components/Icon';
import {Folder, Tag} from '@components/Icon/Expensicons';
import * as Expensicons from '@components/Icon/Expensicons';
import MoneyRequestAmountInput from '@components/MoneyRequestAmountInput';
import Text from '@components/Text';
import useStyleUtils from '@hooks/useStyleUtils';
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {getDecodedCategoryName} from '@libs/CategoryUtils';
Expand All @@ -31,7 +33,7 @@ function SplitListItem<TItem extends ListItem>({
}: SplitListItemProps<TItem>) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {didScreenTransitionEnd} = useScreenWrapperTransitionStatus();

const splitItem = item as unknown as SplitListItemType;

Expand All @@ -41,6 +43,18 @@ function SplitListItem<TItem extends ListItem>({
splitItem.onSplitExpenseAmountChange(splitItem.transactionID, Number(amount));
};

const inputRef = useRef<BaseTextInputRef | null>(null);

// Animated highlight style for selected item
const animatedHighlightStyle = useAnimatedHighlightStyle({
borderRadius: variables.componentBorderRadius,
shouldHighlight: splitItem.isSelected ?? false,
highlightColor: theme.messageHighlightBG,
backgroundColor: splitItem.isSelected ? theme.activeComponentBG : theme.highlightBG,
skipInitialFade: true,
itemEnterDelay: 0,
});

const isBottomVisible = !!splitItem.category || !!splitItem.tags?.at(0);

const [prefixCharacterMargin, setPrefixCharacterMargin] = useState<number>(CONST.CHARACTER_WIDTH);
Expand All @@ -57,25 +71,38 @@ function SplitListItem<TItem extends ListItem>({
onInputFocus(index);
}, [onInputFocus, index]);

// Auto-focus input when item is selected and screen transition ends
useLayoutEffect(() => {
if (!splitItem.isSelected || !splitItem.isEditable || !didScreenTransitionEnd || !inputRef.current) {
return;
}

inputRef.current.focus();
}, [splitItem.isSelected, splitItem.isEditable, didScreenTransitionEnd]);

const inputCallbackRef = (ref: BaseTextInputRef | null) => {
inputRef.current = ref;
};

return (
<BaseListItem
item={item}
wrapperStyle={[styles.flex1, styles.justifyContentBetween, styles.userSelectNone, styles.p3, styles.br3]}
isFocused={isFocused}
containerStyle={[styles.mh4, styles.mv1, styles.reportPreviewBoxHoverBorder, styles.br2, splitItem.isSelected && StyleUtils.getBackgroundColorStyle(theme.messageHighlightBG)]}
hoverStyle={[styles.br2]}
pressableStyle={[styles.br2]}
pressableWrapperStyle={[styles.mh4, styles.mv1, styles.flex1, styles.justifyContentBetween, styles.userSelectNone, styles.br3, animatedHighlightStyle]}
hoverStyle={[styles.br2, {borderColor: theme.hoverComponentBG}]}
pressableStyle={[styles.br2, styles.bgTransparent]}
isDisabled={isDisabled}
showTooltip={showTooltip}
onSelectRow={onSelectRow}
shouldPreventEnterKeySubmit={shouldPreventEnterKeySubmit}
rightHandSideComponent={rightHandSideComponent}
shouldUseDefaultRightHandSideCheckmark={false}
shouldHighlightSelectedItem={false}
keyForList={item.keyForList}
onFocus={onFocus}
pendingAction={item.pendingAction}
>
<View style={[styles.flexRow, styles.containerWithSpaceBetween]}>
<View style={[styles.flexRow, styles.containerWithSpaceBetween, styles.p3]}>
<View style={[styles.flex1]}>
<View style={[styles.containerWithSpaceBetween, !isBottomVisible && styles.justifyContentCenter]}>
<View style={[styles.minHeight5, styles.justifyContentCenter]}>
Expand Down Expand Up @@ -159,6 +186,7 @@ function SplitListItem<TItem extends ListItem>({
</View>
) : (
<MoneyRequestAmountInput
ref={inputCallbackRef}
autoGrow={false}
amount={splitItem.amount}
currency={splitItem.currency}
Expand Down
9 changes: 8 additions & 1 deletion src/hooks/useAnimatedHighlightStyle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ type Props = {
* @default theme.border
*/
highlightColor?: string;

/** Whether to skip the initial fade-in animation and show the component immediately
* @default false
*/
skipInitialFade?: boolean;
};

/**
Expand All @@ -58,10 +63,12 @@ export default function useAnimatedHighlightStyle({
height,
highlightColor,
backgroundColor,
skipInitialFade = false,
}: Props) {
const [startHighlight, setStartHighlight] = useState(false);
const repeatableProgress = useSharedValue(0);
const nonRepeatableProgress = useSharedValue(shouldHighlight ? 0 : 1);
const initialNonRepeatableProgressValue = skipInitialFade || !shouldHighlight ? 1 : 0;
const nonRepeatableProgress = useSharedValue(initialNonRepeatableProgressValue);
const {didScreenTransitionEnd} = useScreenWrapperTransitionStatus();
const theme = useTheme();

Expand Down