Skip to content

Commit

Permalink
Merge pull request #48723 from rayane-djouah/Fix-App-freezes-when-cli…
Browse files Browse the repository at this point in the history
…cking-checkbox-in-subtag-list

[CP Staging] Fix useResponsiveLayout bugs
  • Loading branch information
Beamanator authored Sep 7, 2024
2 parents 1ec3088 + 26b28ec commit a9dc596
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/components/SelectionListWithModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ function SelectionListWithModal<TItem extends ListItem>(
const [isModalVisible, setIsModalVisible] = useState(false);
const [longPressedItem, setLongPressedItem] = useState<TItem | null>(null);
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
// 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);

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);
if (!shouldUseNarrowLayout) {
if (!isSmallScreenWidth) {
if (selectedItems.length === 0) {
turnOffMobileSelectionMode();
}
Expand All @@ -38,11 +40,11 @@ function SelectionListWithModal<TItem extends ListItem>(
if (selectedItems.length > 0 && !selectionMode?.isEnabled) {
turnOnMobileSelectionMode();
}
}, [sections, selectionMode, shouldUseNarrowLayout]);
}, [sections, selectionMode, isSmallScreenWidth]);

const handleLongPressRow = (item: TItem) => {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (!turnOnSelectionModeOnLongPress || !shouldUseNarrowLayout || item?.isDisabled || item?.isDisabledCheckbox) {
if (!turnOnSelectionModeOnLongPress || !isSmallScreenWidth || item?.isDisabled || item?.isDisabledCheckbox) {
return;
}
setLongPressedItem(item);
Expand Down
18 changes: 10 additions & 8 deletions src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ function ReportFieldsListValuesPage({
}: ReportFieldsListValuesPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout here to use the mobile selection mode on small screens only
// See https://github.com/Expensify/App/issues/48724 for more details
const {isSmallScreenWidth} = useResponsiveLayout();
const [formDraft] = useOnyx(ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM_DRAFT);
const {selectionMode} = useMobileSelectionMode();

const [selectedValues, setSelectedValues] = useState<Record<string, boolean>>({});
const [deleteValuesConfirmModalVisible, setDeleteValuesConfirmModalVisible] = useState(false);
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);

const canSelectMultiple = !hasAccountingConnections && (shouldUseNarrowLayout ? selectionMode?.isEnabled : true);
const canSelectMultiple = !hasAccountingConnections && (isSmallScreenWidth ? selectionMode?.isEnabled : true);

const [listValues, disabledListValues] = useMemo(() => {
let reportFieldValues: string[];
Expand Down Expand Up @@ -177,7 +179,7 @@ function ReportFieldsListValuesPage({

const getHeaderButtons = () => {
const options: Array<DropdownOption<DeepValueOf<typeof CONST.POLICY.BULK_ACTION_TYPES>>> = [];
if (shouldUseNarrowLayout ? selectionMode?.isEnabled : selectedValuesArray.length > 0) {
if (isSmallScreenWidth ? selectionMode?.isEnabled : selectedValuesArray.length > 0) {
if (selectedValuesArray.length > 0) {
options.push({
icon: Expensicons.Trashcan,
Expand Down Expand Up @@ -259,15 +261,15 @@ function ReportFieldsListValuesPage({
customText={translate('workspace.common.selected', {selectedNumber: selectedValuesArray.length})}
options={options}
isSplitButton={false}
style={[shouldUseNarrowLayout && styles.flexGrow1, shouldUseNarrowLayout && styles.mb3]}
style={[isSmallScreenWidth && styles.flexGrow1, isSmallScreenWidth && styles.mb3]}
isDisabled={!selectedValuesArray.length}
/>
);
}

return (
<Button
style={[shouldUseNarrowLayout && styles.flexGrow1, shouldUseNarrowLayout && styles.mb3]}
style={[isSmallScreenWidth && styles.flexGrow1, isSmallScreenWidth && styles.mb3]}
medium
success
icon={Expensicons.Plus}
Expand All @@ -277,7 +279,7 @@ function ReportFieldsListValuesPage({
);
};

const selectionModeHeader = selectionMode?.isEnabled && shouldUseNarrowLayout;
const selectionModeHeader = selectionMode?.isEnabled && isSmallScreenWidth;

return (
<AccessOrNotFoundWrapper
Expand All @@ -302,9 +304,9 @@ function ReportFieldsListValuesPage({
Navigation.goBack();
}}
>
{!shouldUseNarrowLayout && !hasAccountingConnections && getHeaderButtons()}
{!isSmallScreenWidth && !hasAccountingConnections && getHeaderButtons()}
</HeaderWithBackButton>
{shouldUseNarrowLayout && <View style={[styles.pl5, styles.pr5]}>{!hasAccountingConnections && getHeaderButtons()}</View>}
{isSmallScreenWidth && <View style={[styles.pl5, styles.pr5]}>{!hasAccountingConnections && getHeaderButtons()}</View>}
<View style={[styles.ph5, styles.pv4]}>
<Text style={[styles.sidebarLinkText, styles.optionAlternateText]}>{translate('workspace.reportFields.listInputSubtitle')}</Text>
</View>
Expand Down

0 comments on commit a9dc596

Please sign in to comment.