import React, {useEffect, useState} from 'react'; import {TouchableOpacity, View} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {useTracked} from '../../provider'; import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager'; import {SIZE} from '../../utils/SizeUtils'; import {PressableButton} from '../PressableButton'; import {ActionStrip} from './action-strip'; import {Filler} from './back-fill'; const SelectionWrapper = ({ children, item, index, background, onLongPress, onPress, testID, }) => { const [state, dispatch] = useTracked(); const {colors, selectionMode, selectedItemsList} = state; const [selected, setSelected] = useState(false); const [actionStrip, setActionStrip] = useState(false); useEffect(() => { if (selectionMode) { setActionStrip(false); let exists = selectedItemsList.filter( (o) => o.dateCreated === item.dateCreated, ); if (exists[0]) { if (!selected) { setSelected(true); } } else { if (selected) { setSelected(false); } } } }, [selectedItemsList]); const onLong = () => { if (selectionMode) return; if (item.type === 'topic' && item.title === 'General') return; setActionStrip(!actionStrip); }; const _onPress = async () => { if (actionStrip) { setActionStrip(false); return; } await onPress(); }; const closeStrip = () => { setActionStrip(false); }; useEffect(() => { eSubscribeEvent('navigate', closeStrip); return () => { eUnSubscribeEvent('navigate', closeStrip); }; }, []); return ( {actionStrip && ( )} {item.type === 'note' && } {selectionMode && ( {item.type !== 'topic' || (item.type === 'topic' && item.title !== 'General') ? ( ) : null} )} {children} ); }; export default SelectionWrapper;