// components/PhotoCapture.js import React, { useState, useRef, useContext } from…
- User
// components/PhotoCapture.js
import React, { useState, useRef, useContext } from 'react'; import { StyleSheet, Text, View, Button, Image, Alert } from 'react-native'; import { Camera } from 'expo-camera'; import { MediaContext } from '../context/MediaContext';
const PhotoCapture = () => { const cameraRef = useRef(null); const { media, updateMedia } = useContext(MediaContext); const [capturedPhoto, setCapturedPhoto] = useState(media.photo);
const takePhoto = async () => { if (cameraRef.current) { try { const photo = await cameraRef.current.takePictureAsync(); setCapturedPhoto(photo.uri); updateMedia('photo', photo.uri); } catch (error) { Alert.alert('Error', 'Failed to take photo: ' + error.message); } } };
return ( Capture Photo {!capturedPhoto ? ( ) : ( <Image source={{ uri: capturedPhoto }} style={styles.imagePreview} /> <Button title="Retake Photo" onPress={() => { setCapturedPhoto(null); updateMedia('photo', null); }} /> )} ); };
const styles = StyleSheet.create({ section: { marginBottom: 30, backgroundColor: '#ffffff', padding: 15, borderRadius: 10, elevation: 2, // For Android shadowColor: '#000', // For iOS shadowOffset: { width: 0, height: 2 }, // For iOS shadowOpacity: 0.25, // For iOS shadowRadius: 3.84, // For iOS }, subHeader: { fontSize: 20, marginBottom: 10, fontWeight: '600', }, camera: { width: '100%', height: 250, borderRadius: 10, overflow: 'hidden', }, buttonContainer: { backgroundColor: 'rgba(0,0,0,0.5)', padding: 10, alignItems: 'center', }, mediaContainer: { alignItems: 'center', }, imagePreview: { width: '100%', height: 250, borderRadius: 10, marginBottom: 10, resizeMode: 'cover', }, });
export default PhotoCapture;
ERROR Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of
PhotoCapture.This error is located at: in RCTView (created by View)
- Assistant