From 395df42470afc1f8480c812ed2ea2e83dfd3a29b Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Fri, 9 Jul 2021 18:55:57 +0500 Subject: [PATCH] fixed action modal not appear on second press --- src/screens/drafts/screen/draftsScreen.js | 35 +++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/screens/drafts/screen/draftsScreen.js b/src/screens/drafts/screen/draftsScreen.js index 9a8071ca5..e4df97db1 100644 --- a/src/screens/drafts/screen/draftsScreen.js +++ b/src/screens/drafts/screen/draftsScreen.js @@ -30,19 +30,20 @@ const DraftsScreen = ({ const [selectedId, setSelectedId] = useState(null); const ActionSheetRef = useRef(null); const firstMount = useRef(true); + const selectedIdRef = useRef(); useEffect(() => { - if (firstMount.current) { - firstMount.current = false; - return; + selectedIdRef.current = selectedId; + }, [selectedId]) + + + const _onActionPress = (index) => { + if(index === 0){ + moveScheduleToDraft(selectedIdRef.current) } - if (ActionSheetRef.current) { - ActionSheetRef.current.show(); - } - }, [selectedId]); + } // Component Functions - const _renderItem = (item, type) => { const tags = item.tags ? item.tags.split(/[ ,]+/) : []; const tag = tags[0] || ''; @@ -51,6 +52,18 @@ const DraftsScreen = ({ const summary = postBodySummary({ ...item, last_update: item.modified }, 100); const isSchedules = type === 'schedules'; + const _onItemPress = () => { + if(isSchedules){ + setSelectedId(item._id) + if(ActionSheetRef.current){ + ActionSheetRef.current.show(); + } + }else { + editDraft(item._id) + } + } + + return ( (isSchedules ? setSelectedId(item._id) : editDraft(item._id))} + handleOnPressItem={_onItemPress} handleOnRemoveItem={isSchedules ? removeSchedule : removeDraft} id={item._id} key={item._id} @@ -151,9 +164,7 @@ const DraftsScreen = ({ }), ]} cancelButtonIndex={1} - onPress={(index) => { - index === 0 && moveScheduleToDraft(selectedId); - }} + onPress={_onActionPress} /> );