Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LHN flickers and scroll position restoring #55486

Merged
merged 19 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
58fc9c9
Add window dimensions to LHNOptionsList for dynamic list sizing
rezkiy37 Jan 20, 2025
7bf55d1
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fix…
rezkiy37 Jan 22, 2025
2d48c07
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fix…
rezkiy37 Jan 23, 2025
c6cad82
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fix…
rezkiy37 Jan 23, 2025
4d6dfea
Use named imports LHNOptionsList
rezkiy37 Jan 23, 2025
e7bd150
Do not default string IDs LHNOptionsList
rezkiy37 Jan 23, 2025
838ee69
rerun tests
rezkiy37 Jan 23, 2025
5850274
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fix…
rezkiy37 Jan 24, 2025
1acb9ad
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fix…
rezkiy37 Jan 27, 2025
fd4ea52
create useEstimatedListSize
rezkiy37 Jan 27, 2025
45220f2
use useEstimatedListSize
rezkiy37 Jan 27, 2025
28d2475
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fix…
rezkiy37 Jan 28, 2025
9853e57
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fix…
rezkiy37 Jan 29, 2025
717c184
Rename and refactor estimated list size hook for LHN usage
rezkiy37 Jan 29, 2025
88f6bda
Add documentation for native and web implementations of useLHNEstimat…
rezkiy37 Jan 29, 2025
de4b935
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fix…
rezkiy37 Jan 30, 2025
8eb88e0
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fix…
rezkiy37 Jan 31, 2025
6f2c91e
retest
rezkiy37 Jan 31, 2025
8576b7e
Add mock for useLHNEstimatedListSize hook in SidebarLinks performance…
rezkiy37 Jan 31, 2025
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
3 changes: 3 additions & 0 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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 usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand Down Expand Up @@ -48,6 +49,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
const styles = useThemeStyles();
const {translate, preferredLocale} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const estimatedListSize = useLHNEstimatedListSize();
const shouldShowEmptyLHN = shouldUseNarrowLayout && data.length === 0;

// When the first item renders we want to call the onFirstItemRendered callback.
Expand Down Expand Up @@ -284,6 +286,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
showsVerticalScrollIndicator={false}
onLayout={onLayout}
onScroll={onScroll}
estimatedListSize={estimatedListSize}
/>
)}
</View>
Expand Down
18 changes: 18 additions & 0 deletions src/hooks/useLHNEstimatedListSize/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import useWindowDimensions from '@hooks/useWindowDimensions';
import variables from '@styles/variables';
import type UseLHNEstimatedListSize from './types';

/**
* This a native specific implementation for FlashList of LHNOptionsList. It calculates estimated visible height and width of the list. It is not the scroll content size. Defining this prop will enable the list to be rendered immediately. Without it, the list first needs to measure its size, leading to a small delay during the first render.
*/
const useLHNEstimatedListSize: UseLHNEstimatedListSize = () => {
const {windowHeight, windowWidth} = useWindowDimensions();
const listHeight = windowHeight - variables.bottomTabHeight;

return {
height: listHeight,
width: windowWidth,
};
};

export default useLHNEstimatedListSize;
8 changes: 8 additions & 0 deletions src/hooks/useLHNEstimatedListSize/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type UseLHNEstimatedListSize from './types';

/**
* This is the web implementation. It is intentionally left unimplemented because it does not function correctly on the web.
*/
const useLHNEstimatedListSize: UseLHNEstimatedListSize = () => undefined;

export default useLHNEstimatedListSize;
8 changes: 8 additions & 0 deletions src/hooks/useLHNEstimatedListSize/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type UseLHNEstimatedListSize = () =>
| {
height: number;
width: number;
}
| undefined;

export default UseLHNEstimatedListSize;
1 change: 1 addition & 0 deletions tests/perf-test/SidebarLinks.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jest.mock('../../src/libs/Navigation/navigationRef', () => ({
jest.mock('@components/Icon/Expensicons');

jest.mock('@react-navigation/native');
jest.mock('@src/hooks/useLHNEstimatedListSize/index.native.ts');

const getMockedReportsMap = (length = 100) => {
const mockReports = Object.fromEntries(
Expand Down