0
Good night.
I’m having a little problem with the return of an Onpress from a Touchableopacity, inside an element. Basically, sometimes it returns the action, but most of the time it does not.
The code looks like this (briefly):
Neworder
const [photos, setPhotos] = useState([]);
{photos !== '' && photos !== null && photos !== undefined ? (<PicturePreview pictures={photos} onPressItem={onDeletePicture} />) : null}
const onDeletePicture = (index) => { //exclui o item do state photos, e setPhotos novamente, com o novo array para renderizar o <PicturePreview/>}
The state photos
is powered with the date.Ri of the photo taken by the camera - so far, ok, everything works perfectly. When it arrow value, it renders the component <PicturePreview />
, which I hope will return an onPress index to delete the array’s Uri, and render again.
Picturepreview:
import PreviewItem from './picturePreviewItem';
const PicturePreview = ({pictures, onPressItem}) => {
const renderItems = () => {
if (pictures.length > 0) {
let elements = [];
pictures.map((data, index) => {
if (data !== undefined) {
elements.push(
<PreviewItem key={index} index={index} item={data} onPressItem={onPressDelete}/>
);}
});
return elements;
}
};
return (
<View style={[styles.container, pictures.length > 0 ? styles.containerFilled : '',]}>
{renderItems()}
</View>
);
};
Picturepreviewitem:
const PicturePreviewItem = ({item, index, onPressDelete}) => {
const indexValue = index;
return (
<View style={styles.containerPreview}>
<Image style={styles.imagePreview} resizeMode="contain" source={{uri: item}} />
<TouchableOpacity onPress={(f) => onPressDelete(indexValue)}>
<Icon name="cancel" style={styles.deletePictureIcon} />
</TouchableOpacity>
</View>
);
};
Anyway, as I said, sometimes by clicking on the Touchableopacity, I can perform the function onDeletePicture of the Neworder page, but, most of the time, the press does not draft any reaction.
All Imports are duly declared (React, view, icon, etc...). The problem, by the tests I did with console.log, is in the Picturepreviewitem component, which does not respond to onPress (originating from there) when triggered.
Note: I am not having any black screen error.
Thank you.
got it ???...
– novic