-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: search header flickering on selection mode #49510
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
Changes from 6 commits
3079296
3830db3
2cc1288
734ad73
c7ae781
f687155
9e80633
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type {ForwardedRef} from 'react'; | ||
import React, {forwardRef, useEffect, useState} from 'react'; | ||
import React, {forwardRef, useEffect, useRef, useState} from 'react'; | ||
import * as Expensicons from '@components/Icon/Expensicons'; | ||
import MenuItem from '@components/MenuItem'; | ||
import Modal from '@components/Modal'; | ||
|
@@ -14,10 +14,12 @@ import CONST from '@src/CONST'; | |
type SelectionListWithModalProps<TItem extends ListItem> = BaseSelectionListProps<TItem> & { | ||
turnOnSelectionModeOnLongPress?: boolean; | ||
onTurnOnSelectionMode?: (item: TItem | null) => void; | ||
shouldAutoTurnOff?: boolean; | ||
isSelected?: (item: TItem) => boolean; | ||
}; | ||
|
||
function SelectionListWithModal<TItem extends ListItem>( | ||
{turnOnSelectionModeOnLongPress, onTurnOnSelectionMode, onLongPressRow, sections, ...rest}: SelectionListWithModalProps<TItem>, | ||
{turnOnSelectionModeOnLongPress, onTurnOnSelectionMode, onLongPressRow, sections, shouldAutoTurnOff, isSelected, ...rest}: SelectionListWithModalProps<TItem>, | ||
ref: ForwardedRef<SelectionListHandle>, | ||
) { | ||
const [isModalVisible, setIsModalVisible] = useState(false); | ||
|
@@ -26,21 +28,47 @@ function SelectionListWithModal<TItem extends ListItem>( | |
// 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 | ||
const {isSmallScreenWidth} = useResponsiveLayout(); | ||
const {selectionMode} = useMobileSelectionMode(true); | ||
const {selectionMode} = useMobileSelectionMode(shouldAutoTurnOff); | ||
// Check if selection should be on when the modal is opened | ||
const wasSelectionOnRef = useRef(false); | ||
// Keep track of the number of selected items to determine if we should turn off selection mode | ||
const selectionRef = useRef(0); | ||
|
||
useEffect(() => { | ||
// We can access 0 index safely as we are not displaying multiple sections in table view | ||
const selectedItems = sections[0].data.filter((item) => item.isSelected); | ||
const selectedItems = sections[0].data.filter((item) => { | ||
if (isSelected) { | ||
return isSelected(item); | ||
} | ||
return !!item.isSelected; | ||
}); | ||
selectionRef.current = selectedItems.length; | ||
|
||
if (!isSmallScreenWidth) { | ||
if (selectedItems.length === 0) { | ||
turnOffMobileSelectionMode(); | ||
} | ||
return; | ||
} | ||
if (!wasSelectionOnRef.current && selectedItems.length > 0) { | ||
wasSelectionOnRef.current = true; | ||
} | ||
if (selectedItems.length > 0 && !selectionMode?.isEnabled) { | ||
turnOnMobileSelectionMode(); | ||
} else if (selectedItems.length === 0 && selectionMode?.isEnabled && !wasSelectionOnRef.current) { | ||
turnOffMobileSelectionMode(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case when There are actively two In the case of #50555, there are two Lists on the screens: a parent Tag list and a child Tag list. When we select a child tag, |
||
} | ||
}, [sections, selectionMode, isSmallScreenWidth]); | ||
}, [sections, selectionMode, isSmallScreenWidth, isSelected]); | ||
|
||
useEffect( | ||
() => () => { | ||
if (selectionRef.current !== 0) { | ||
return; | ||
} | ||
turnOffMobileSelectionMode(); | ||
}, | ||
[], | ||
); | ||
|
||
const handleLongPressRow = (item: TItem) => { | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
|
Uh oh!
There was an error while loading. Please reload this page.