fixed action modal not appear on second press

This commit is contained in:
Nouman Tahir 2021-07-09 18:55:57 +05:00
parent b934e85255
commit 395df42470

View File

@ -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 (
<DraftListItem
created={isSchedules ? getFormatedCreatedDate(item.schedule) : item.created}
@ -62,7 +75,7 @@ const DraftsScreen = ({
thumbnail={thumbnail ? { uri: thumbnail } : null}
username={currentAccount.name}
reputation={currentAccount.reputation}
handleOnPressItem={() => (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}
/>
</View>
);