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
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function BaseSelectionListWithSections<TItem extends ListItem>({
shouldHighlightSelectedItem = true,
shouldDisableHoverStyle = false,
setShouldDisableHoverStyle = () => {},
isPercentageMode,
shouldSkipContentHeaderHeightOffset,
ref,
}: SelectionListProps<TItem>) {
const styles = useThemeStyles();
Expand Down Expand Up @@ -357,8 +357,8 @@ function BaseSelectionListWithSections<TItem extends ListItem>({
}

let viewOffset = variables.contentHeaderHeight - viewOffsetToKeepFocusedItemAtTopOfViewableArea;
// Remove contentHeaderHeight from viewOffset calculation if isPercentageMode (for scroll offset calculation on native)
if (isPercentageMode) {
// Skip contentHeaderHeight for native split expense tabs scroll correction
if (shouldSkipContentHeaderHeightOffset) {
viewOffset = viewOffsetToKeepFocusedItemAtTopOfViewableArea;
}
listRef.current.scrollToLocation({sectionIndex, itemIndex, animated, viewOffset});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,4 @@ function SplitAmountDisplay({splitItem, contentWidth = '100%', shouldRemoveSpaci
);
}

SplitAmountDisplay.displayName = 'SplitAmountDisplay';

export default SplitAmountDisplay;
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,4 @@ function SplitAmountInput({splitItem, formattedOriginalAmount, contentWidth, onS
);
}

SplitAmountInput.displayName = 'SplitAmountInput';

export default SplitAmountInput;
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ function SplitPercentageDisplay({splitItem, contentWidth}: SplitPercentageDispla
);
}

SplitPercentageDisplay.displayName = 'SplitPercentageDisplay';

export default SplitPercentageDisplay;
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,4 @@ function SplitPercentageInput({splitItem, contentWidth, percentageDraft, onSplit
);
}

SplitPercentageInput.displayName = 'SplitPercentageInput';

export default SplitPercentageInput;
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,4 @@ function SplitListItemInput({
);
}

SplitListItemInput.displayName = 'SplitListItemInput';

export default SplitListItemInput;
5 changes: 2 additions & 3 deletions src/components/SelectionListWithSections/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ function SelectionListWithSections<TItem extends ListItem>({onScroll, shouldHide
isRowMultilineSupported
shouldDisableHoverStyle={shouldDisableHoverStyle}
setShouldDisableHoverStyle={setShouldDisableHoverStyle}
// We only allow the prop to pass on Native (for scroll offset calculation)
// web should be false by default since there are no issues on web
isPercentageMode={false}
// Web doesn't require scroll offset correction, only native does
shouldSkipContentHeaderHeightOffset={false}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/SelectionListWithSections/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,8 @@ type SelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
shouldDisableHoverStyle?: boolean;
setShouldDisableHoverStyle?: React.Dispatch<React.SetStateAction<boolean>>;

/** Whether the list is percentage mode (for scroll offset calculation) */
isPercentageMode?: boolean;
/** When true, skips the contentHeaderHeight from the viewOffset calculation during scroll-to-index. Only needed on native platforms for split expense tabs (Amount/Percentage/Date) scroll correction. Web should always pass false. */
shouldSkipContentHeaderHeightOffset?: boolean;
} & TRightHandSideComponent<TItem>;

type SelectionListHandle = {
Expand Down
15 changes: 9 additions & 6 deletions src/pages/iou/SplitExpensePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import SplitAmountList from './SplitAmountList';
import SplitPercentageList from './SplitPercentageList';
import SplitList from './SplitList';

type SplitExpensePageProps = PlatformStackScreenProps<SplitExpenseParamList, typeof SCREENS.MONEY_REQUEST.SPLIT_EXPENSE>;

Expand Down Expand Up @@ -481,11 +480,12 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
{() => (
<TabScreenWithFocusTrapWrapper>
<View style={styles.flex1}>
<SplitAmountList
<SplitList
sections={sections}
initiallyFocusedOptionKey={initiallyFocusedOptionKey ?? undefined}
onSelectRow={onSelectRow}
listFooterContent={listFooterContent}
mode={CONST.TAB.SPLIT.AMOUNT}
/>
{footerContent}
</View>
Expand All @@ -496,11 +496,12 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
{() => (
<TabScreenWithFocusTrapWrapper>
<View style={styles.flex1}>
<SplitPercentageList
<SplitList
sections={sections}
initiallyFocusedOptionKey={initiallyFocusedOptionKey ?? undefined}
onSelectRow={onSelectRow}
listFooterContent={listFooterContent}
mode={CONST.TAB.SPLIT.PERCENTAGE}
/>
{footerContent}
</View>
Expand All @@ -512,11 +513,12 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
<TabScreenWithFocusTrapWrapper>
<View style={styles.flex1}>
{headerDateContent}
<SplitAmountList
<SplitList
sections={sections}
initiallyFocusedOptionKey={initiallyFocusedOptionKey ?? undefined}
onSelectRow={onSelectRow}
listFooterContent={<View style={[shouldUseNarrowLayout && styles.mb3]} />}
mode={CONST.TAB.SPLIT.DATE}
/>
{footerContent}
</View>
Expand All @@ -527,11 +529,12 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
</View>
) : (
<View style={styles.flex1}>
<SplitAmountList
<SplitList
sections={sections}
initiallyFocusedOptionKey={initiallyFocusedOptionKey ?? undefined}
onSelectRow={onSelectRow}
listFooterContent={listFooterContent}
mode={CONST.TAB.SPLIT.AMOUNT}
/>
{footerContent}
</View>
Expand Down
27 changes: 16 additions & 11 deletions src/pages/iou/SplitAmountList.tsx → src/pages/iou/SplitList.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, {useMemo} from 'react';
import {KeyboardAwareScrollView} from 'react-native-keyboard-controller';
import type {ValueOf} from 'type-fest';
// eslint-disable-next-line no-restricted-imports
import SelectionList from '@components/SelectionListWithSections';
import type {SectionListDataType, SplitListItemType} from '@components/SelectionListWithSections/types';
import useDisplayFocusedInputUnderKeyboard from '@hooks/useDisplayFocusedInputUnderKeyboard';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';

type SplitAmountListProps = {
type SplitListProps = {
/** The split expense sections data. */
sections: Array<SectionListDataType<SplitListItemType>>;
/** The initially focused option key. */
Expand All @@ -16,25 +17,30 @@ type SplitAmountListProps = {
onSelectRow: (item: SplitListItemType) => void;
/** Footer content to render at the bottom of the list. */
listFooterContent?: React.JSX.Element | null;
/** The split mode to use (amount, percentage, or date). */
mode: ValueOf<typeof CONST.TAB.SPLIT>;
};

/**
* Dedicated component for the Amount tab in Split Expense flow.
* Renders split items with amount inputs, managing its own scroll/height state.
* Unified component for split expense tabs (Amount, Percentage, Date).
* Renders split items with the appropriate input type based on mode,
* managing its own scroll/height state.
*/
function SplitAmountList({sections, initiallyFocusedOptionKey, onSelectRow, listFooterContent}: SplitAmountListProps) {
function SplitList({sections, initiallyFocusedOptionKey, onSelectRow, listFooterContent, mode}: SplitListProps) {
const styles = useThemeStyles();
const {listRef, bottomOffset, scrollToFocusedInput, SplitListItem} = useDisplayFocusedInputUnderKeyboard();

const amountSections = useMemo(() => {
const splitSections = useMemo(() => {
return sections.map((section) => ({
...section,
data: section.data.map((item) => ({
...item,
mode: CONST.TAB.SPLIT.AMOUNT,
mode,
})),
}));
}, [sections]);
}, [sections, mode]);

const isPercentageMode = mode === CONST.TAB.SPLIT.PERCENTAGE;

return (
<SelectionList
Expand All @@ -48,7 +54,7 @@ function SplitAmountList({sections, initiallyFocusedOptionKey, onSelectRow, list
)}
onSelectRow={onSelectRow}
ref={listRef}
sections={amountSections}
sections={splitSections}
initiallyFocusedOptionKey={initiallyFocusedOptionKey}
ListItem={SplitListItem}
containerStyle={[styles.flexBasisAuto]}
Expand All @@ -59,10 +65,9 @@ function SplitAmountList({sections, initiallyFocusedOptionKey, onSelectRow, list
shouldPreventDefaultFocusOnSelectRow
removeClippedSubviews={false}
shouldHideListOnInitialRender={false}
shouldSkipContentHeaderHeightOffset={isPercentageMode}
/>
);
}

SplitAmountList.displayName = 'SplitAmountList';

export default SplitAmountList;
export default SplitList;
69 changes: 0 additions & 69 deletions src/pages/iou/SplitPercentageList.tsx

This file was deleted.

Loading