Skip to content

Commit

Permalink
Fix displaying delete modal on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekBoman committed Jul 12, 2024
1 parent 5df8ba6 commit 4c7775c
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/pages/Search/SearchSelectedNarrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,35 @@ type SearchSelectedNarrowProps = {options: Array<DropdownOption<SearchHeaderOpti
function SearchSelectedNarrow({options, itemsLength}: SearchSelectedNarrowProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const selectedOptionIndexRef = useRef(-1);

const [isModalVisible, setIsModalVisible] = useState(false);
const buttonRef = useRef<View>(null);

const openMenu = () => setIsModalVisible(true);
const closeMenu = () => setIsModalVisible(false);

const handleOnModalHide = () => {
if (selectedOptionIndexRef.current === -1) {
return;
}
options[selectedOptionIndexRef.current]?.onSelected?.();
};

const handleOnMenuItemPress = (option: DropdownOption<SearchHeaderOptionValue>, index: number) => {
if (option?.shouldCloseModalOnSelect) {
selectedOptionIndexRef.current = index;
closeMenu();
return;
}
option?.onSelected?.();
};

const handleOnCloseMenu = () => {
selectedOptionIndexRef.current = -1;
closeMenu();
};

return (
<View style={[styles.pb4]}>
<Button
Expand All @@ -37,18 +59,14 @@ function SearchSelectedNarrow({options, itemsLength}: SearchSelectedNarrowProps)
<Modal
isVisible={isModalVisible}
type={CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED}
onClose={closeMenu}
onClose={handleOnCloseMenu}
onModalHide={handleOnModalHide}
>
{options.map((option) => (
{options.map((option, index) => (
<MenuItem
title={option.text}
icon={option.icon}
onPress={() => {
if (option?.shouldCloseModalOnSelect) {
closeMenu();
}
option?.onSelected?.();
}}
onPress={() => handleOnMenuItemPress(option, index)}
key={option.value}
/>
))}
Expand Down

0 comments on commit 4c7775c

Please sign in to comment.