diff --git a/src/components/FlatList/index.android.tsx b/src/components/FlatList/index.android.tsx index a1982542a093..afe3bac07ad6 100644 --- a/src/components/FlatList/index.android.tsx +++ b/src/components/FlatList/index.android.tsx @@ -3,12 +3,14 @@ import React, {useCallback, useRef} from 'react'; import type {NativeScrollEvent, NativeSyntheticEvent} from 'react-native'; import {FlatList} from 'react-native'; import KeyboardDismissibleFlatList from '@components/KeyboardDismissibleFlatList'; +import useThemeStyles from '@hooks/useThemeStyles'; import type {CustomFlatListProps} from './types'; // FlatList wrapped with the freeze component will lose its scroll state when frozen (only for Android). // CustomFlatList saves the offset and use it for scrollToOffset() when unfrozen. -function CustomFlatList({ref, enableAnimatedKeyboardDismissal = false, onMomentumScrollEnd, ...props}: CustomFlatListProps) { +function CustomFlatList({ref, enableAnimatedKeyboardDismissal = false, onMomentumScrollEnd, shouldHideContent = false, ...props}: CustomFlatListProps) { const lastScrollOffsetRef = useRef(0); + const styles = useThemeStyles(); const onScreenFocus = useCallback(() => { if (typeof ref === 'function') { @@ -37,6 +39,8 @@ function CustomFlatList({ref, enableAnimatedKeyboardDismissal = false, onMome }, [onScreenFocus]), ); + const contentContainerStyle = [props.contentContainerStyle, shouldHideContent && styles.opacity0]; + if (enableAnimatedKeyboardDismissal) { return ( ({ref, enableAnimatedKeyboardDismissal = false, onMome {...props} ref={ref} onMomentumScrollEnd={handleScrollEnd} + contentContainerStyle={contentContainerStyle} /> ); } @@ -54,6 +59,7 @@ function CustomFlatList({ref, enableAnimatedKeyboardDismissal = false, onMome {...props} ref={ref} onMomentumScrollEnd={handleScrollEnd} + contentContainerStyle={contentContainerStyle} /> ); } diff --git a/src/components/FlatList/index.ios.tsx b/src/components/FlatList/index.ios.tsx index 657c2a5f2905..726310918249 100644 --- a/src/components/FlatList/index.ios.tsx +++ b/src/components/FlatList/index.ios.tsx @@ -3,6 +3,7 @@ import type {NativeScrollEvent, NativeSyntheticEvent} from 'react-native'; import {FlatList} from 'react-native'; import KeyboardDismissibleFlatList from '@components/KeyboardDismissibleFlatList'; import useEmitComposerScrollEvents from '@hooks/useEmitComposerScrollEvents'; +import useThemeStyles from '@hooks/useThemeStyles'; import type {CustomFlatListProps} from './types'; // On iOS, we have to unset maintainVisibleContentPosition while the user is scrolling to prevent jumping to the beginning issue @@ -14,9 +15,11 @@ function CustomFlatList({ onMomentumScrollBegin, onMomentumScrollEnd, onScroll: onScrollProp, + shouldHideContent = false, ...restProps }: CustomFlatListProps) { const [isScrolling, setIsScrolling] = useState(false); + const styles = useThemeStyles(); const handleScrollBegin = useCallback( (event: NativeSyntheticEvent) => { @@ -45,6 +48,8 @@ function CustomFlatList({ const maintainVisibleContentPosition = isScrolling || shouldDisableVisibleContentPosition ? undefined : maintainVisibleContentPositionProp; + const contentContainerStyle = [restProps.contentContainerStyle, shouldHideContent && styles.opacity0]; + if (enableAnimatedKeyboardDismissal) { return ( ({ onScroll={onScrollProp} onMomentumScrollBegin={handleScrollBegin} onMomentumScrollEnd={handleScrollEnd} + contentContainerStyle={contentContainerStyle} /> ); } @@ -69,6 +75,7 @@ function CustomFlatList({ onScroll={handleScroll} onMomentumScrollBegin={handleScrollBegin} onMomentumScrollEnd={handleScrollEnd} + contentContainerStyle={contentContainerStyle} /> ); } diff --git a/src/components/FlatList/index.tsx b/src/components/FlatList/index.tsx index 61e2c9537498..4b8e1852c92f 100644 --- a/src/components/FlatList/index.tsx +++ b/src/components/FlatList/index.tsx @@ -4,6 +4,7 @@ import React, {useCallback, useEffect, useMemo, useRef} from 'react'; import type {NativeScrollEvent, NativeSyntheticEvent} from 'react-native'; import {FlatList} from 'react-native'; import useEmitComposerScrollEvents from '@hooks/useEmitComposerScrollEvents'; +import useThemeStyles from '@hooks/useThemeStyles'; import {isMobileSafari} from '@libs/Browser'; import type {CustomFlatListProps} from './types'; @@ -43,7 +44,16 @@ function getScrollableNode(flatList: FlatList | null): HTMLElement | undefined { return flatList?.getScrollableNode() as HTMLElement | undefined; } -function MVCPFlatList({maintainVisibleContentPosition, horizontal = false, onScroll: onScrollProp, initialNumToRender, ref, ...restProps}: CustomFlatListProps) { +function MVCPFlatList({ + maintainVisibleContentPosition, + horizontal = false, + onScroll: onScrollProp, + initialNumToRender, + shouldHideContent = false, + ref, + ...restProps +}: CustomFlatListProps) { + const styles = useThemeStyles(); const {minIndexForVisible: mvcpMinIndexForVisible, autoscrollToTopThreshold: mvcpAutoscrollToTopThreshold} = maintainVisibleContentPosition ?? {}; const scrollRef = useRef(null); const prevFirstVisibleOffsetRef = useRef(0); @@ -251,6 +261,7 @@ function MVCPFlatList({maintainVisibleContentPosition, horizontal = false } restProps.onLayout?.(e); }} + contentContainerStyle={[restProps.contentContainerStyle, shouldHideContent && styles.visibilityHidden]} /> ); } diff --git a/src/components/FlatList/types.ts b/src/components/FlatList/types.ts index eeb6fcdeed84..b6ddf4096302 100644 --- a/src/components/FlatList/types.ts +++ b/src/components/FlatList/types.ts @@ -22,6 +22,11 @@ type CustomFlatListProps = Omit, 'CellRendererComponent'> & * Custom cell renderer component */ CellRendererComponent?: React.ComponentType> | null; + + /** + * Whether to hide the content (e.g. when first displaying the report actions list, we initially show only the top report actions. We then show the full report actions list after the user scrolls) + */ + shouldHideContent?: boolean; }; // eslint-disable-next-line import/prefer-default-export diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 80433c2ddc54..d471980565bf 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -871,11 +871,8 @@ function ReportActionsList({ data={sortedVisibleReportActions} renderItem={renderItem} renderScrollComponent={renderActionSheetAwareScrollView} - contentContainerStyle={[ - styles.chatContentScrollView, - shouldScrollToEndAfterLayout ? styles.visibilityHidden : styles.visibilityVisible, - shouldFocusToTopOnMount ? styles.justifyContentEnd : undefined, - ]} + contentContainerStyle={[styles.chatContentScrollView, shouldFocusToTopOnMount ? styles.justifyContentEnd : undefined]} + shouldHideContent={shouldScrollToEndAfterLayout} shouldDisableVisibleContentPosition={shouldScrollToEndAfterLayout} showsVerticalScrollIndicator={!shouldScrollToEndAfterLayout} keyExtractor={keyExtractor}