diff --git a/mobile/src/libs/components/card/card.tsx b/mobile/src/libs/components/card/card.tsx index a75975028..85de45fe3 100644 --- a/mobile/src/libs/components/card/card.tsx +++ b/mobile/src/libs/components/card/card.tsx @@ -11,6 +11,7 @@ import { View, } from '#libs/components/components'; import { AppColor } from '#libs/enums/enums'; +import { useCallback } from '#libs/hooks/hooks'; import { type IconName } from '#libs/types/types'; import { DEFAULT_NUMBER_OF_LINES } from './libs/constants/constants'; @@ -24,8 +25,12 @@ type Properties = { onPress: () => void; iconRight?: IconName; onIconPress?: () => void; + id?: number; + isModalVisible?: boolean; }; +const rowReferences = new Map(); + const Card: React.FC = ({ title, image = imagePlaceholder, @@ -34,7 +39,28 @@ const Card: React.FC = ({ onPress, iconRight, onIconPress, + id, + isModalVisible, }) => { + const handleSwipeableReference = useCallback( + (reference: Swipeable | null) => { + if (reference && !rowReferences.get(id)) { + rowReferences.set(id, reference); + } + }, + [id], + ); + + const handleCloseOtherSwipeables = useCallback(() => { + [...rowReferences.entries()].forEach(([key, reference]) => { + if (key !== id && reference) { + (reference as Swipeable).close(); + } + }); + }, [id, rowReferences]); + + !isModalVisible && handleCloseOtherSwipeables(); + const renderRightSwipeActions = (): React.ReactNode => { return ( Boolean(iconRight) && ( @@ -46,7 +72,12 @@ const Card: React.FC = ({ }; return ( - + {iconName && iconColor ? ( diff --git a/mobile/src/screens/chat-list/chat-list.tsx b/mobile/src/screens/chat-list/chat-list.tsx index 77b86cb20..b8ba22a01 100644 --- a/mobile/src/screens/chat-list/chat-list.tsx +++ b/mobile/src/screens/chat-list/chat-list.tsx @@ -114,6 +114,7 @@ const ChatList: React.FC = () => { return ( { handleSelectChat(item.name, item.id.toString()); @@ -122,6 +123,7 @@ const ChatList: React.FC = () => { onIconPress={(): void => { handleShowDeleteModal(item.id); }} + isModalVisible={isDeleteModalVisible} /> ); })} diff --git a/mobile/src/screens/journal/journal.tsx b/mobile/src/screens/journal/journal.tsx index 3c7a322bc..e294746d1 100644 --- a/mobile/src/screens/journal/journal.tsx +++ b/mobile/src/screens/journal/journal.tsx @@ -30,7 +30,8 @@ const Journal: React.FC = () => { const navigation = useNavigation>(); - const [isModalVisible, setIsModalVisible] = useState(false); + const [isDeleteModalVisible, setIsDeleteModalVisible] = + useState(false); const { allJournalEntries, selectedJournalEntry } = useAppSelector( ({ journal }) => { @@ -55,11 +56,11 @@ const Journal: React.FC = () => { const handleShowModal = (id: number): void => { dispatch(journalActions.setSelectedJournalEntry(id)); - setIsModalVisible(true); + setIsDeleteModalVisible(true); }; const hanleCloseModal = (): void => { - setIsModalVisible(false); + setIsDeleteModalVisible(false); }; const handleDeleteNote = (): void => { @@ -88,7 +89,7 @@ const Journal: React.FC = () => { return ( { return ( { handleSelectJournalEntry(item.id); @@ -111,6 +113,7 @@ const Journal: React.FC = () => { onIconPress={(): void => { handleShowModal(item.id); }} + isModalVisible={isDeleteModalVisible} /> ); })}