diff --git a/package-lock.json b/package-lock.json index 42750059acaf..db0e12092bd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,7 +51,7 @@ "@react-navigation/stack": "7.3.3", "@react-ng/bounds-observer": "^0.2.1", "@rnmapbox/maps": "10.1.41", - "@shopify/flash-list": "1.8.2", + "@shopify/flash-list": "2.0.3", "@ua/react-native-airship": "~24.4.0", "awesome-phonenumber": "^5.4.0", "babel-polyfill": "^6.26.0", @@ -11718,10 +11718,11 @@ } }, "node_modules/@shopify/flash-list": { - "version": "1.8.2", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@shopify/flash-list/-/flash-list-2.0.3.tgz", + "integrity": "sha512-jUlHuZFoPdqRCDvOqsb2YkTttRPyV8Tb/EjCx3gE2wjr4UTM+fE0Ltv9bwBg0K7yo/SxRNXaW7xu5utusRb0xA==", "license": "MIT", "dependencies": { - "recyclerlistview": "4.2.3", "tslib": "2.8.1" }, "peerDependencies": { @@ -32658,19 +32659,6 @@ "node": ">= 10.13.0" } }, - "node_modules/recyclerlistview": { - "version": "4.2.3", - "license": "Apache-2.0", - "dependencies": { - "lodash.debounce": "4.0.8", - "prop-types": "15.8.1", - "ts-object-utils": "0.0.5" - }, - "peerDependencies": { - "react": ">= 15.2.1", - "react-native": ">= 0.30.0" - } - }, "node_modules/redent": { "version": "3.0.0", "dev": true, @@ -35470,10 +35458,6 @@ "node": ">=0.4.0" } }, - "node_modules/ts-object-utils": { - "version": "0.0.5", - "license": "ISC" - }, "node_modules/ts-regex-builder": { "version": "1.8.2", "dev": true, diff --git a/package.json b/package.json index 1cbe48d99a38..e4593f246ed5 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,7 @@ "@react-navigation/stack": "7.3.3", "@react-ng/bounds-observer": "^0.2.1", "@rnmapbox/maps": "10.1.41", - "@shopify/flash-list": "1.8.2", + "@shopify/flash-list": "2.0.3", "@ua/react-native-airship": "~24.4.0", "awesome-phonenumber": "^5.4.0", "babel-polyfill": "^6.26.0", diff --git a/patches/recyclerlistview+4.2.3.patch b/patches/recyclerlistview+4.2.3.patch deleted file mode 100644 index 3be777b0c2fa..000000000000 --- a/patches/recyclerlistview+4.2.3.patch +++ /dev/null @@ -1,45 +0,0 @@ -diff --git a/node_modules/recyclerlistview/dist/reactnative/core/RecyclerListView.js b/node_modules/recyclerlistview/dist/reactnative/core/RecyclerListView.js -index 3ca4550..753c2f7 100644 ---- a/node_modules/recyclerlistview/dist/reactnative/core/RecyclerListView.js -+++ b/node_modules/recyclerlistview/dist/reactnative/core/RecyclerListView.js -@@ -251,6 +251,7 @@ var RecyclerListView = /** @class */ (function (_super) { - this._virtualRenderer.setOptimizeForAnimations(false); - }; - RecyclerListView.prototype.componentDidMount = function () { -+ this._isMounted = true; - if (this._initComplete) { - this._processInitialOffset(); - this._processOnEndReached(); -diff --git a/node_modules/recyclerlistview/dist/reactnative/platform/reactnative/scrollcomponent/ScrollComponent.js b/node_modules/recyclerlistview/dist/reactnative/platform/reactnative/scrollcomponent/ScrollComponent.js -index 18c5ae2..4ca00f2 100644 ---- a/node_modules/recyclerlistview/dist/reactnative/platform/reactnative/scrollcomponent/ScrollComponent.js -+++ b/node_modules/recyclerlistview/dist/reactnative/platform/reactnative/scrollcomponent/ScrollComponent.js -@@ -49,12 +49,13 @@ var ScrollComponent = /** @class */ (function (_super) { - } - }; - _this._onLayout = function (event) { -- if (_this._height !== event.nativeEvent.layout.height || _this._width !== event.nativeEvent.layout.width) { -- _this._height = event.nativeEvent.layout.height; -+ const estimatedHeightSize = _this.props.estimatedHeightSize || event.nativeEvent.layout.height; -+ if (_this._height !== estimatedHeightSize || _this._width !== event.nativeEvent.layout.width) { -+ _this._height = estimatedHeightSize; - _this._width = event.nativeEvent.layout.width; - if (_this.props.onSizeChanged) { - _this._isSizeChangedCalledOnce = true; -- _this.props.onSizeChanged(event.nativeEvent.layout); -+ _this.props.onSizeChanged(__assign(__assign({}, event.nativeEvent.layout), { height: estimatedHeightSize })); - } - } - if (_this.props.onLayout) { -diff --git a/node_modules/recyclerlistview/src/core/scrollcomponent/BaseScrollComponent.tsx b/node_modules/recyclerlistview/src/core/scrollcomponent/BaseScrollComponent.tsx -index ee2952a..fc4326a 100644 ---- a/node_modules/recyclerlistview/src/core/scrollcomponent/BaseScrollComponent.tsx -+++ b/node_modules/recyclerlistview/src/core/scrollcomponent/BaseScrollComponent.tsx -@@ -18,6 +18,7 @@ export interface ScrollComponentProps { - renderContentContainer?: (props?: object, children?: React.ReactNode) => React.ReactNode | null; - renderAheadOffset: number; - layoutSize?: Dimension; -+ estimatedHeightSize?: number; - } - export default abstract class BaseScrollComponent extends React.Component { - public abstract scrollTo(x: number, y: number, animate: boolean): void; diff --git a/src/components/DisplayNames/index.native.tsx b/src/components/DisplayNames/index.native.tsx index f6f35f9689fd..cae91c80272e 100644 --- a/src/components/DisplayNames/index.native.tsx +++ b/src/components/DisplayNames/index.native.tsx @@ -8,7 +8,7 @@ import TextWithEmojiFragment from '@pages/home/report/comment/TextWithEmojiFragm import type DisplayNamesProps from './types'; // As we don't have to show tooltips of the Native platform so we simply render the full display names list. -function DisplayNames({accessibilityLabel, fullTitle, textStyles = [], numberOfLines = 1, renderAdditionalText, forwardedFSClass}: DisplayNamesProps) { +function DisplayNames({accessibilityLabel, fullTitle, textStyles = [], numberOfLines = 1, renderAdditionalText, forwardedFSClass, testID}: DisplayNamesProps) { const {translate} = useLocalize(); const titleContainsTextAndCustomEmoji = useMemo(() => containsCustomEmoji(fullTitle) && !containsOnlyCustomEmoji(fullTitle), [fullTitle]); return ( @@ -16,7 +16,7 @@ function DisplayNames({accessibilityLabel, fullTitle, textStyles = [], numberOfL accessibilityLabel={accessibilityLabel} style={textStyles} numberOfLines={numberOfLines} - testID={DisplayNames.displayName} + testID={`${DisplayNames.displayName}${testID !== undefined ? `-${testID}` : ''}`} fsClass={forwardedFSClass} > {titleContainsTextAndCustomEmoji ? ( diff --git a/src/components/DisplayNames/types.ts b/src/components/DisplayNames/types.ts index 1909bf774d84..687e14fa6ef0 100644 --- a/src/components/DisplayNames/types.ts +++ b/src/components/DisplayNames/types.ts @@ -46,6 +46,9 @@ type DisplayNamesProps = ForwardedFSClassProps & { /** Additional Text component to render after the displayNames */ renderAdditionalText?: () => React.ReactNode; + + /** TestID indicating order */ + testID?: number; }; export default DisplayNamesProps; diff --git a/src/components/EmojiPicker/EmojiPickerMenu/BaseEmojiPickerMenu.tsx b/src/components/EmojiPicker/EmojiPickerMenu/BaseEmojiPickerMenu.tsx index 43670be7ddec..3b489b08b16f 100644 --- a/src/components/EmojiPicker/EmojiPickerMenu/BaseEmojiPickerMenu.tsx +++ b/src/components/EmojiPicker/EmojiPickerMenu/BaseEmojiPickerMenu.tsx @@ -1,17 +1,15 @@ import {FlashList} from '@shopify/flash-list'; -import type {ListRenderItem} from '@shopify/flash-list'; -import React, {useMemo} from 'react'; +import type {FlashListRef, ListRenderItem} from '@shopify/flash-list'; +import React from 'react'; import type {ForwardedRef} from 'react'; -import {StyleSheet, View} from 'react-native'; +import {View} from 'react-native'; import type {StyleProp, ViewStyle} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import CategoryShortcutBar from '@components/EmojiPicker/CategoryShortcutBar'; import EmojiSkinToneList from '@components/EmojiPicker/EmojiSkinToneList'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; -import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; -import useWindowDimensions from '@hooks/useWindowDimensions'; import type {EmojiPickerList, EmojiPickerListItem, HeaderIndices} from '@libs/EmojiUtils'; import CONST from '@src/CONST'; @@ -81,18 +79,9 @@ function ListEmptyComponent() { function BaseEmojiPickerMenu( {headerEmojis, scrollToHeader, isFiltered, listWrapperStyle = [], data, renderItem, stickyHeaderIndices = [], extraData = [], alwaysBounceVertical = false}: BaseEmojiPickerMenuProps, - ref: ForwardedRef>, + ref: ForwardedRef>, ) { const styles = useThemeStyles(); - const {windowWidth} = useWindowDimensions(); - const {shouldUseNarrowLayout} = useResponsiveLayout(); - - // Estimated list size should be a whole integer to avoid floating point precision errors - // More info: https://github.com/Expensify/App/issues/34522 - const listWidth = shouldUseNarrowLayout ? Math.floor(windowWidth) : CONST.EMOJI_PICKER_SIZE.WIDTH; - - const flattenListWrapperStyle = useMemo(() => StyleSheet.flatten(listWrapperStyle), [listWrapperStyle]); - return ( <> {!isFiltered && ( @@ -113,8 +102,6 @@ function BaseEmojiPickerMenu( stickyHeaderIndices={stickyHeaderIndices} ListEmptyComponent={ListEmptyComponent} alwaysBounceVertical={alwaysBounceVertical} - estimatedItemSize={CONST.EMOJI_PICKER_ITEM_HEIGHT} - estimatedListSize={{height: flattenListWrapperStyle.height as number, width: listWidth}} contentContainerStyle={styles.ph4} extraData={extraData} getItemType={getItemType} diff --git a/src/components/EmojiPicker/EmojiPickerMenu/index.tsx b/src/components/EmojiPicker/EmojiPickerMenu/index.tsx index 9ac6e8e32937..9629c740ae38 100755 --- a/src/components/EmojiPicker/EmojiPickerMenu/index.tsx +++ b/src/components/EmojiPicker/EmojiPickerMenu/index.tsx @@ -259,7 +259,13 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji}: EmojiPickerMenuProps, r if ('header' in item && item.header) { return ( - + {translate(`emojiPicker.headers.${code}` as TranslationPaths)} ); diff --git a/src/components/EmojiPicker/EmojiPickerMenu/useEmojiPickerMenu.ts b/src/components/EmojiPicker/EmojiPickerMenu/useEmojiPickerMenu.ts index ac9152bb8405..7916a72b0310 100644 --- a/src/components/EmojiPicker/EmojiPickerMenu/useEmojiPickerMenu.ts +++ b/src/components/EmojiPicker/EmojiPickerMenu/useEmojiPickerMenu.ts @@ -1,4 +1,4 @@ -import type {FlashList} from '@shopify/flash-list'; +import type {FlashListRef} from '@shopify/flash-list'; import {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import emojis from '@assets/emojis'; import useKeyboardState from '@hooks/useKeyboardState'; @@ -12,7 +12,7 @@ import {getHeaderEmojis, getSpacersIndexes, mergeEmojisWithFrequentlyUsedEmojis, import ONYXKEYS from '@src/ONYXKEYS'; const useEmojiPickerMenu = () => { - const emojiListRef = useRef>(null); + const emojiListRef = useRef>(null); const [frequentlyUsedEmojis] = useOnyx(ONYXKEYS.FREQUENTLY_USED_EMOJIS, {canBeMissing: true}); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps const allEmojis = useMemo(() => mergeEmojisWithFrequentlyUsedEmojis(emojis, processFrequentlyUsedEmojis(frequentlyUsedEmojis)), [frequentlyUsedEmojis]); diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index 7708f32a9a2b..f18e7f446533 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -1,5 +1,5 @@ import {useIsFocused, useRoute} from '@react-navigation/native'; -import type {FlashListProps} from '@shopify/flash-list'; +import type {FlashListProps, FlashListRef} from '@shopify/flash-list'; import {FlashList} from '@shopify/flash-list'; import type {ReactElement} from 'react'; import React, {memo, useCallback, useContext, useEffect, useMemo, useRef} from 'react'; @@ -10,7 +10,6 @@ import * as Expensicons from '@components/Icon/Expensicons'; import LottieAnimations from '@components/LottieAnimations'; import {ScrollOffsetContext} from '@components/ScrollOffsetContextProvider'; import TextBlock from '@components/TextBlock'; -import useLHNEstimatedListSize from '@hooks/useLHNEstimatedListSize'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useOnyx from '@hooks/useOnyx'; @@ -43,7 +42,7 @@ const keyExtractor = (item: Report) => `report_${item.reportID}`; function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optionMode, shouldDisableFocusOptions = false, onFirstItemRendered = () => {}}: LHNOptionsListProps) { const {saveScrollOffset, getScrollOffset, saveScrollIndex, getScrollIndex} = useContext(ScrollOffsetContext); const {isOffline} = useNetwork(); - const flashListRef = useRef>(null); + const flashListRef = useRef>(null); const route = useRoute(); const isScreenFocused = useIsFocused(); @@ -64,7 +63,6 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio const theme = useTheme(); const styles = useThemeStyles(); const {translate, preferredLocale, localeCompare} = useLocalize(); - const estimatedListSize = useLHNEstimatedListSize(); const isReportsSplitNavigatorLast = useRootNavigationState((state) => state?.routes?.at(-1)?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR); const shouldShowEmptyLHN = data.length === 0; const estimatedItemSize = optionMode === CONST.OPTION_MODE.COMPACT ? variables.optionRowHeightCompact : variables.optionRowHeight; @@ -162,7 +160,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio * Function which renders a row in the list */ const renderItem = useCallback( - ({item}: RenderItemProps): ReactElement => { + ({item, index}: RenderItemProps): ReactElement => { const reportID = item.reportID; const itemParentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${item.parentReportID}`]; const itemReportNameValuePairs = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`]; @@ -258,6 +256,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio isReportsSplitNavigatorLast={isReportsSplitNavigatorLast} isScreenFocused={isScreenFocused} localeCompare={localeCompare} + testID={index} isReportArchived={isReportArchived} /> ); @@ -408,14 +407,14 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio testID="lhn-options-list" keyExtractor={keyExtractor} renderItem={renderItem} - estimatedItemSize={estimatedItemSize} - overrideProps={{estimatedHeightSize: estimatedItemSize * CONST.LHN_VIEWPORT_ITEM_COUNT}} extraData={extraData} showsVerticalScrollIndicator={false} onLayout={onLayout} onScroll={onScroll} - estimatedListSize={estimatedListSize} initialScrollIndex={isWebOrDesktop ? getScrollIndex(route) : undefined} + maintainVisibleContentPosition={{disabled: true}} + drawDistance={1000} + removeClippedSubviews /> )} diff --git a/src/components/LHNOptionsList/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN.tsx index 85ca068648e9..73acaf238a6e 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -61,6 +61,7 @@ function OptionRowLHN({ hasDraftComment, shouldShowRBRorGBRTooltip, isScreenFocused = false, + testID, }: OptionRowLHNProps) { const theme = useTheme(); const styles = useThemeStyles(); @@ -294,6 +295,7 @@ function OptionRowLHN({ isGroupChat(report) || isSystemChat(report) } + testID={testID} /> {isChatUsedForOnboarding && } {isStatusVisible && ( diff --git a/src/components/LHNOptionsList/OptionRowRendererComponent/index.native.tsx b/src/components/LHNOptionsList/OptionRowRendererComponent/index.native.tsx index a0179145b77c..11def4f3588d 100644 --- a/src/components/LHNOptionsList/OptionRowRendererComponent/index.native.tsx +++ b/src/components/LHNOptionsList/OptionRowRendererComponent/index.native.tsx @@ -1,12 +1,22 @@ -import {CellContainer} from '@shopify/flash-list'; -import type {CellContainerProps} from '@shopify/flash-list/dist/native/cell-container/CellContainer'; -import type {ForwardedRef} from 'react'; import {forwardRef} from 'react'; -import type {View} from 'react-native'; +import type {ForwardedRef} from 'react'; +import type {StyleProp, ViewStyle} from 'react-native'; +import {View} from 'react-native'; + +type OptionRowRendererComponentProps = { + /** The index position of this option row in the list */ + index: number; + + /** Callback function called when the component layout changes */ + onLayout?: () => void; + + /** Style prop for customizing the option row */ + style?: StyleProp; +}; -function OptionRowRendererComponent(props: CellContainerProps, ref: ForwardedRef) { +function OptionRowRendererComponent(props: OptionRowRendererComponentProps, ref: ForwardedRef) { return ( - ; /** Extra styles for the section list container */ - contentContainerStyles?: StyleProp; + contentContainerStyles?: StyleProp; /** List of reports */ data: Report[]; @@ -129,6 +128,9 @@ type OptionRowLHNDataProps = { /** Function to compare locale strings */ localeCompare: LocaleContextProps['localeCompare']; + /** TestID of the row, indicating order */ + testID: number; + /** Whether the report is archived */ isReportArchived: boolean; }; @@ -177,8 +179,11 @@ type OptionRowLHNProps = { /** Whether the screen is focused */ isScreenFocused?: boolean; + + /** The testID of the row */ + testID: number; }; -type RenderItemProps = {item: Report}; +type RenderItemProps = {item: Report; index: number}; export type {LHNOptionsListProps, OptionRowLHNDataProps, OptionRowLHNProps, RenderItemProps}; diff --git a/src/components/Search/SearchList/BaseSearchList/index.native.tsx b/src/components/Search/SearchList/BaseSearchList/index.native.tsx index ae54a0cb2e54..74d4cf0fb3bd 100644 --- a/src/components/Search/SearchList/BaseSearchList/index.native.tsx +++ b/src/components/Search/SearchList/BaseSearchList/index.native.tsx @@ -17,11 +17,7 @@ function BaseSearchList({ ListFooterComponent, onViewableItemsChanged, onLayout, - estimatedItemSize, - overrideItemLayout, - estimatedListSize, contentContainerStyle, - calculatedListHeight, }: BaseSearchListProps) { const renderItemWithoutKeyboardFocus = useCallback( ({item, index}: {item: SearchListItem; index: number}) => { @@ -45,11 +41,8 @@ function BaseSearchList({ onLayout={onLayout} removeClippedSubviews drawDistance={1000} - estimatedItemSize={estimatedItemSize} - overrideItemLayout={overrideItemLayout} - estimatedListSize={estimatedListSize} contentContainerStyle={contentContainerStyle} - overrideProps={{estimatedHeightSize: calculatedListHeight}} + maintainVisibleContentPosition={{disabled: true}} /> ); } diff --git a/src/components/Search/SearchList/BaseSearchList/index.tsx b/src/components/Search/SearchList/BaseSearchList/index.tsx index adb576850b47..ebee471218d6 100644 --- a/src/components/Search/SearchList/BaseSearchList/index.tsx +++ b/src/components/Search/SearchList/BaseSearchList/index.tsx @@ -27,11 +27,7 @@ function BaseSearchList({ ListFooterComponent, onViewableItemsChanged, onLayout, - estimatedItemSize, - overrideItemLayout, - estimatedListSize, contentContainerStyle, - calculatedListHeight, flattenedItemsLength, }: BaseSearchListProps) { const hasKeyBeenPressed = useRef(false); @@ -122,11 +118,8 @@ function BaseSearchList({ onLayout={onLayout} removeClippedSubviews drawDistance={1000} - estimatedItemSize={estimatedItemSize} - overrideItemLayout={overrideItemLayout} - estimatedListSize={estimatedListSize} contentContainerStyle={contentContainerStyle} - overrideProps={{estimatedHeightSize: calculatedListHeight}} + maintainVisibleContentPosition={{disabled: true}} /> ); } diff --git a/src/components/Search/SearchList/BaseSearchList/types.ts b/src/components/Search/SearchList/BaseSearchList/types.ts index f9c6291ffaf2..11b4d55aaa99 100644 --- a/src/components/Search/SearchList/BaseSearchList/types.ts +++ b/src/components/Search/SearchList/BaseSearchList/types.ts @@ -1,4 +1,4 @@ -import type {FlashList, FlashListProps} from '@shopify/flash-list'; +import type {FlashListProps, FlashListRef} from '@shopify/flash-list'; import type {ForwardedRef} from 'react'; import type {NativeSyntheticEvent} from 'react-native'; import type {SearchColumnType} from '@components/Search/types'; @@ -12,13 +12,8 @@ type BaseSearchListProps = Pick< | 'onEndReachedThreshold' | 'ListFooterComponent' | 'onViewableItemsChanged' - | 'estimatedItemSize' - | 'overrideItemLayout' - | 'estimatedListSize' | 'keyExtractor' | 'showsVerticalScrollIndicator' - | 'removeClippedSubviews' - | 'drawDistance' | 'onLayout' > & { /** The data to display in the list */ @@ -36,14 +31,11 @@ type BaseSearchListProps = Pick< /** The callback, which is run when a row is pressed */ onSelectRow: (item: SearchListItem) => void; - /** The height of the list */ - calculatedListHeight: number; - /** Whether the screen containing the list is focused */ isFocused?: boolean; /** The ref to the list */ - ref: ForwardedRef>; + ref: ForwardedRef>; /** The function to scroll to an index */ scrollToIndex?: (index: number, animated?: boolean) => void; diff --git a/src/components/Search/SearchList/index.tsx b/src/components/Search/SearchList/index.tsx index 0b835cd83ebb..98235fbc8769 100644 --- a/src/components/Search/SearchList/index.tsx +++ b/src/components/Search/SearchList/index.tsx @@ -1,6 +1,6 @@ import {useFocusEffect, useRoute} from '@react-navigation/native'; import {accountIDSelector} from '@selectors/Session'; -import type {FlashList, FlashListProps, ViewToken} from '@shopify/flash-list'; +import type {FlashListProps, FlashListRef, ViewToken} from '@shopify/flash-list'; import React, {forwardRef, useCallback, useContext, useImperativeHandle, useMemo, useRef, useState} from 'react'; import type {ForwardedRef} from 'react'; import {View} from 'react-native'; @@ -13,8 +13,6 @@ import Modal from '@components/Modal'; import {usePersonalDetails} from '@components/OnyxListItemProvider'; import {PressableWithFeedback} from '@components/Pressable'; import {ScrollOffsetContext} from '@components/ScrollOffsetContextProvider'; -import {createItemHeightCalculator} from '@components/Search/itemHeightCalculator'; -import ITEM_HEIGHTS from '@components/Search/itemHeights'; import type {SearchColumnType, SearchQueryJSON} from '@components/Search/types'; import type ChatListItem from '@components/SelectionList/ChatListItem'; import type TaskListItem from '@components/SelectionList/Search/TaskListItem'; @@ -22,7 +20,6 @@ import type TransactionGroupListItem from '@components/SelectionList/Search/Tran import type TransactionListItem from '@components/SelectionList/Search/TransactionListItem'; import type {ExtendedTargetedEvent, ReportActionListItemType, TaskListItemType, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionList/types'; import Text from '@components/Text'; -import useInitialWindowDimensions from '@hooks/useInitialWindowDimensions'; import useKeyboardState from '@hooks/useKeyboardState'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; @@ -90,7 +87,7 @@ type SearchListProps = Pick, 'onScroll' | 'conten isFocused: boolean; /** Called when the viewability of rows changes, as defined by the viewabilityConfig prop. */ - onViewableItemsChanged?: (info: {changed: ViewToken[]; viewableItems: ViewToken[]}) => void; + onViewableItemsChanged?: (info: {changed: Array>; viewableItems: Array>}) => void; /** Invoked on mount and layout changes */ onLayout?: () => void; @@ -98,9 +95,6 @@ type SearchListProps = Pick, 'onScroll' | 'conten /** Styles to apply to the content container */ contentContainerStyle?: StyleProp; - /** The estimated height of an item in the list */ - estimatedItemSize?: number; - /** Whether mobile selection mode is enabled */ isMobileSelectionModeEnabled: boolean; @@ -143,7 +137,6 @@ function SearchList( onViewableItemsChanged, onLayout, shouldAnimate, - estimatedItemSize = ITEM_HEIGHTS.NARROW_WITHOUT_DRAWER.STANDARD, isMobileSelectionModeEnabled, areAllOptionalColumnsHidden, violations, @@ -152,8 +145,7 @@ function SearchList( ) { const styles = useThemeStyles(); - const {initialHeight, initialWidth} = useInitialWindowDimensions(); - const {hash, groupBy, type} = queryJSON; + const {hash, groupBy} = queryJSON; const flattenedItems = useMemo(() => { if (groupBy) { if (!isTransactionGroupListItemArray(data)) { @@ -175,14 +167,14 @@ function SearchList( const {translate} = useLocalize(); const {isOffline} = useNetwork(); - const listRef = useRef>(null); + const listRef = useRef>(null); const {isKeyboardShown} = useKeyboardState(); const {safeAreaPaddingBottomStyle} = useSafeAreaPaddings(); const prevDataLength = usePrevious(data.length); // We need to use isSmallScreenWidth instead of shouldUseNarrowLayout here because there is a race condition that causes shouldUseNarrowLayout to change indefinitely in this component // See https://github.com/Expensify/App/issues/48675 for more details // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth - const {isSmallScreenWidth, isLargeScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout(); + const {isSmallScreenWidth} = useResponsiveLayout(); const [isModalVisible, setIsModalVisible] = useState(false); const [longPressedItem, setLongPressedItem] = useState(); @@ -344,51 +336,6 @@ function SearchList( const selectAllButtonVisible = canSelectMultiple && !SearchTableHeader; const isSelectAllChecked = selectedItemsLength > 0 && selectedItemsLength === flattenedItemsWithoutPendingDelete.length; - const getItemHeight = useMemo( - () => - createItemHeightCalculator({ - isLargeScreenWidth, - shouldUseNarrowLayout, - type, - }), - [isLargeScreenWidth, shouldUseNarrowLayout, type], - ); - - const overrideItemLayout = useCallback( - (layout: {span?: number; size?: number}, item: SearchListItem) => { - if (!layout) { - return; - } - const height = getItemHeight(item); - // eslint-disable-next-line no-param-reassign - return (layout.size = height > 0 ? height : estimatedItemSize); - }, - [getItemHeight, estimatedItemSize], - ); - - const calculatedListHeight = useMemo(() => { - return initialHeight - variables.contentHeaderHeight; - }, [initialHeight]); - - const calculatedListWidth = useMemo(() => { - if (shouldUseNarrowLayout) { - return initialWidth; - } - - if (isLargeScreenWidth) { - return initialWidth - variables.navigationTabBarSize - variables.sideBarWithLHBWidth; - } - - return initialWidth; - }, [initialWidth, shouldUseNarrowLayout, isLargeScreenWidth]); - - const estimatedListSize = useMemo(() => { - return { - height: calculatedListHeight, - width: calculatedListWidth, - }; - }, [calculatedListHeight, calculatedListWidth]); - return ( {tableHeaderVisible && ( @@ -438,13 +385,7 @@ function SearchList( ListFooterComponent={ListFooterComponent} onViewableItemsChanged={onViewableItemsChanged} onLayout={onLayout} - removeClippedSubviews - drawDistance={1000} - estimatedItemSize={estimatedItemSize} - overrideItemLayout={overrideItemLayout} - estimatedListSize={estimatedListSize} contentContainerStyle={contentContainerStyle} - calculatedListHeight={calculatedListHeight} /> ) => void; - contentContainerStyle?: ContentStyle; + contentContainerStyle?: StyleProp; searchResults?: SearchResults; handleSearch: (value: SearchParams) => void; isMobileSelectionModeEnabled: boolean; @@ -188,6 +188,33 @@ function prepareTransactionsList( }; } +const archivedReportsSelector = (all: OnyxCollection): ArchivedReportsIDSet => { + const ids = new Set(); + if (!all) { + return ids; + } + + const prefixLength = ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS.length; + for (const [key, value] of Object.entries(all)) { + if (isArchivedReport(value)) { + const reportID = key.slice(prefixLength); + ids.add(reportID); + } + } + return ids; +}; + +const exportReportActionsSelector = (allReportActions: OnyxCollection) => { + return Object.fromEntries( + Object.entries(allReportActions ?? {}).map(([reportID, reportActionsGroup]) => { + const filteredReportActions = Object.values(reportActionsGroup ?? {}).filter( + (action) => isExportIntegrationAction(action as ReportAction) || isIntegrationMessageAction(action as ReportAction), + ); + return [reportID, filteredReportActions]; + }), + ); +}; + function Search({queryJSON, searchResults, onSearchListScroll, contentContainerStyle, handleSearch, isMobileSelectionModeEnabled}: SearchProps) { const {isOffline} = useNetwork(); const {shouldUseNarrowLayout} = useResponsiveLayout(); @@ -223,36 +250,15 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS const [archivedReportsIdSet = new Set()] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, { canBeMissing: true, - selector: (all): ArchivedReportsIDSet => { - const ids = new Set(); - if (!all) { - return ids; - } - - const prefixLength = ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS.length; - for (const [key, value] of Object.entries(all)) { - if (isArchivedReport(value)) { - const reportID = key.slice(prefixLength); - ids.add(reportID); - } - } - return ids; - }, + selector: archivedReportsSelector, }); - // Create a selector for only the reportActions needed to determine if a report has been exported or not, grouped by report const [exportReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, { canEvict: false, canBeMissing: true, - selector: (allReportActions) => { - return Object.fromEntries( - Object.entries(allReportActions ?? {}).map(([reportID, reportActionsGroup]) => { - const filteredReportActions = Object.values(reportActionsGroup ?? {}).filter((action) => isExportIntegrationAction(action) || isIntegrationMessageAction(action)); - return [reportID, filteredReportActions]; - }), - ); - }, + selector: exportReportActionsSelector, }); + const {defaultCardFeed} = useCardFeedsForDisplay(); const [accountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: accountIDSelector}); const suggestedSearches = useMemo(() => getSuggestedSearches(accountID, defaultCardFeed?.id), [defaultCardFeed?.id, accountID]); @@ -756,11 +762,13 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS }, [hasErrors, queryJSON, searchResults, shouldResetSearchQuery, setShouldResetSearchQuery]); const fetchMoreResults = useCallback(() => { - if (!isFocused || !searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems) { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + if (!isFocused || !searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems || offset > data.length - CONST.SEARCH.RESULTS_PAGE_SIZE) { return; } - setOffset(offset + CONST.SEARCH.RESULTS_PAGE_SIZE); - }, [isFocused, offset, searchResults?.search?.hasMoreResults, shouldShowLoadingMoreItems, shouldShowLoadingState]); + + setOffset((prev) => prev + CONST.SEARCH.RESULTS_PAGE_SIZE); + }, [isFocused, searchResults?.search?.hasMoreResults, shouldShowLoadingMoreItems, shouldShowLoadingState, offset, data.length]); const toggleAllTransactions = useCallback(() => { const areItemsGrouped = !!groupBy; @@ -892,7 +900,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS /> ) } - contentContainerStyle={{...contentContainerStyle, ...styles.pb3}} + contentContainerStyle={[styles.pb3, contentContainerStyle]} containerStyle={[styles.pv0, !tableHeaderVisible && !isSmallScreenWidth && styles.pt3]} shouldPreventDefaultFocusOnSelectRow={!canUseTouchScreen()} onScroll={onSearchListScroll} diff --git a/src/pages/settings/Wallet/PaymentMethodList.tsx b/src/pages/settings/Wallet/PaymentMethodList.tsx index 7fbc44f655bd..b2c609f4a791 100644 --- a/src/pages/settings/Wallet/PaymentMethodList.tsx +++ b/src/pages/settings/Wallet/PaymentMethodList.tsx @@ -512,7 +512,6 @@ function PaymentMethodList({ <> - estimatedItemSize={variables.optionRowHeight} data={itemsToRender} renderItem={renderItem} keyExtractor={keyExtractor} diff --git a/src/pages/workspace/reports/WorkspaceReportsPage.tsx b/src/pages/workspace/reports/WorkspaceReportsPage.tsx index b0e1ed454605..97767d711bff 100644 --- a/src/pages/workspace/reports/WorkspaceReportsPage.tsx +++ b/src/pages/workspace/reports/WorkspaceReportsPage.tsx @@ -34,7 +34,6 @@ import {getConnectedIntegration, getCurrentConnectionName, hasAccountingConnecti import {getReportFieldTypeTranslationKey} from '@libs/WorkspaceReportFieldUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow'; -import variables from '@styles/variables'; import {openPolicyReportFieldsPage} from '@userActions/Policy/ReportField'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -276,7 +275,6 @@ function WorkspaceReportFieldsPage({ diff --git a/src/styles/index.ts b/src/styles/index.ts index e0c13e44344f..61229452bbeb 100644 --- a/src/styles/index.ts +++ b/src/styles/index.ts @@ -2308,6 +2308,11 @@ const styles = (theme: ThemeColors) => justifyContent: 'center', }, + emojiHeaderContainerWidth: (isSmallScreenWidth: boolean, windowWidth: number) => + ({ + width: isSmallScreenWidth ? windowWidth - 32 : CONST.EMOJI_PICKER_SIZE.WIDTH - 32, + }) satisfies ViewStyle, + emojiSkinToneTitle: { ...spacing.pv1, ...FontUtils.fontFamily.platform.EXP_NEUE_BOLD, @@ -4030,12 +4035,10 @@ const styles = (theme: ThemeColors) => verticalAlign: 'middle', }, - stickyHeaderEmoji: (isSmallScreenWidth: boolean, windowWidth: number) => - ({ - position: 'absolute', - width: isSmallScreenWidth ? windowWidth - 32 : CONST.EMOJI_PICKER_SIZE.WIDTH - 32, - ...spacing.mh4, - }) satisfies ViewStyle, + stickyHeaderEmoji: { + position: 'absolute', + ...spacing.mh4, + } satisfies ViewStyle, reactionCounterText: { fontSize: 13, diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index bfbcea2de236..cb53c1536085 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -356,11 +356,11 @@ describe.skip('Unread Indicators', () => { expect(displayNameTexts).toHaveLength(2); const firstReportOption = displayNameTexts.at(0); expect((firstReportOption?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); - expect(screen.getByText('C User')).toBeOnTheScreen(); + expect(screen.getByText('B User')).toBeOnTheScreen(); const secondReportOption = displayNameTexts.at(1); expect((secondReportOption?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); - expect(screen.getByText('B User')).toBeOnTheScreen(); + expect(screen.getByText('C User')).toBeOnTheScreen(); // Tap the new report option and navigate back to the sidebar again via the back button return navigateToSidebarOption(0); @@ -373,9 +373,9 @@ describe.skip('Unread Indicators', () => { const displayNameTexts = screen.queryAllByLabelText(hintText, {includeHiddenElements: true}); expect(displayNameTexts).toHaveLength(2); expect((displayNameTexts.at(0)?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.normal); - expect(screen.getAllByText('C User').at(0)).toBeOnTheScreen(); + expect(screen.getAllByText('B User').at(0)).toBeOnTheScreen(); expect((displayNameTexts.at(1)?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); - expect(screen.getByText('B User', {includeHiddenElements: true})).toBeOnTheScreen(); + expect(screen.getByText('C User', {includeHiddenElements: true})).toBeOnTheScreen(); })); xit('Manually marking a chat message as unread shows the new line indicator and updates the LHN', () => diff --git a/tests/unit/SidebarOrderTest.ts b/tests/unit/SidebarOrderTest.ts index c23cf82016b9..bc9fb2a22eb5 100644 --- a/tests/unit/SidebarOrderTest.ts +++ b/tests/unit/SidebarOrderTest.ts @@ -29,6 +29,18 @@ jest.mock('@react-navigation/native', () => ({ useFocusEffect: () => undefined, })); +function assertSidebarOptionsAlphabetical() { + const firstElement = screen.queryByTestId('DisplayNames-0'); + const secondElement = screen.queryByTestId('DisplayNames-1'); + const thirdElement = screen.queryByTestId('DisplayNames-2'); + const fourthElement = screen.queryByTestId('DisplayNames-3'); + + expect(firstElement).toHaveTextContent('Email Five'); + expect(secondElement).toHaveTextContent('Email Four'); + expect(thirdElement).toHaveTextContent('Email Three'); + expect(fourthElement).toHaveTextContent('Email Two'); +} + describe('Sidebar', () => { beforeAll(() => { Onyx.init({ @@ -249,12 +261,13 @@ describe('Sidebar', () => { // Then the order of the reports should be 1 > 3 > 2 // ^--- (1 goes to the front and pushes other two down) .then(() => { - const hintText = translateLocal('accessibilityHints.chatUserDisplayNames'); - const displayNames = screen.queryAllByLabelText(hintText); - expect(displayNames).toHaveLength(3); - expect(displayNames.at(0)).toHaveTextContent('Email Two'); - expect(displayNames.at(1)).toHaveTextContent('Email Four'); - expect(displayNames.at(2)).toHaveTextContent('Email Three'); + const firstElement = screen.queryByTestId('DisplayNames-0'); + const secondElement = screen.queryByTestId('DisplayNames-1'); + const thirdElement = screen.queryByTestId('DisplayNames-2'); + + expect(firstElement).toHaveTextContent('Email Two'); + expect(secondElement).toHaveTextContent('Email Four'); + expect(thirdElement).toHaveTextContent('Email Three'); }) ); }); @@ -751,13 +764,7 @@ describe('Sidebar', () => { // Then they are still in alphabetical order .then(() => { - const hintText = translateLocal('accessibilityHints.chatUserDisplayNames'); - const displayNames = screen.queryAllByLabelText(hintText); - expect(displayNames).toHaveLength(4); - expect(displayNames.at(0)).toHaveTextContent('Email Five'); - expect(displayNames.at(1)).toHaveTextContent('Email Four'); - expect(displayNames.at(2)).toHaveTextContent('Email Three'); - expect(displayNames.at(3)).toHaveTextContent('Email Two'); + assertSidebarOptionsAlphabetical(); }) ); }); @@ -827,13 +834,7 @@ describe('Sidebar', () => { // Then they are still in alphabetical order .then(() => { - const hintText = translateLocal('accessibilityHints.chatUserDisplayNames'); - const displayNames = screen.queryAllByLabelText(hintText); - expect(displayNames).toHaveLength(4); - expect(displayNames.at(0)).toHaveTextContent('Email Five'); - expect(displayNames.at(1)).toHaveTextContent('Email Four'); - expect(displayNames.at(2)).toHaveTextContent('Email Three'); - expect(displayNames.at(3)).toHaveTextContent('Email Two'); + assertSidebarOptionsAlphabetical(); }) ); }); @@ -981,13 +982,7 @@ describe('Sidebar', () => { // Then they are still in alphabetical order .then(() => { - const hintText = translateLocal('accessibilityHints.chatUserDisplayNames'); - const displayNames = screen.queryAllByLabelText(hintText); - expect(displayNames).toHaveLength(4); - expect(displayNames.at(0)).toHaveTextContent('Email Five'); - expect(displayNames.at(1)).toHaveTextContent('Email Four'); - expect(displayNames.at(2)).toHaveTextContent('Email Three'); - expect(displayNames.at(3)).toHaveTextContent('Email Two'); + assertSidebarOptionsAlphabetical(); }) ); });