import { Text, View, TextInput, Pressable, ScrollView } from ‘react-native’; import {…
- User
import { Text, View, TextInput, Pressable, ScrollView } from ‘react-native’; import { gStyle } from ‘…/styles/style’; import Footer from ‘…/components/Footer’; import Header from ‘…/components/Header’; import { firebase } from ‘…/Firebase/firebase’; import ‘firebase/compat/auth’; import ‘firebase/compat/database’; import ‘firebase/compat/firestore’; import React, {useState, useEffect} from ‘react’; import { useNavigation } from ‘@react-navigation/native’; import ImagePicker from ‘react-native-image-crop-picker’;
export default function FormAddMK() { const [imageData, setImageData] = useState(null); const chooseImage = () => { const options = { mediaType: ‘photo’, quality: 0.5, }; ImagePicker.launchImageLibrary(options, (response) => { if (response.uri) { setImageData(response); } }); }; const [text, setValue] = useState(‘’); const [name, setName] = useState(‘’); const [description, setDescription] = useState(‘’); const [price, setPrice] = useState(‘’); const [time, setTime] = useState(‘’); const [timeOfMK, setTimeOfMK] = useState(‘’); const [person, setPerson] = useState(‘’); const [image, setImage] = useState(null);
const onChangeName = (text) => setName(text); const onChangeDescription = (text) => setDescription(text); const onChangePrice = (text) => setPrice(text); const onChangeTime = (text) => setTime(text); const onChangeTimeOfMK = (text) => setTimeOfMK(text); const onChangePerson = (text) => setPerson(text); const onChangeImage = (event) => { const file = event.target.files[0]; setImage(file); }; const addHandler = async () => { const storageRef = firebase.storage().ref(); const imageRef = storageRef.child(images/${Date.now()}); const uploadTask = imageRef.putFile(imageData.uri); uploadTask.on( ‘state_changed’, null, (error) => { console.log(error); }, async () => { const downloadURL = await uploadTask.snapshot.ref.getDownloadURL(); firebase.database().ref(‘FutureMK’).push({ id: Date.now(), name: name, description: description, price: price, time: time, timeOfMK: timeOfMK, person: person, image: downloadURL }) })} return (
); }
like this?
- Assistant
I apologize, but as an AI language model, I am unable to determine the context of your statement. Can you please provide more information or clarify? Thank you.
- User
there was an err TypeError: Cannot read property 'launchImageLibrary' of undefined, js engine: hermes
- Assistant
The error message indicates that the
ImagePickerlibrary is not being imported correctly or that it is not installed properly. Here are some potential solutions you can try:-
Check if you have installed the
react-native-image-crop-pickerpackage and that it is in yournode_modulesfolder. -
Verify that you have imported the
ImagePickercorrectly. Try using the default import syntax:import ImagePicker from 'react-native-image-crop-picker'; -
Make sure you have configured
react-native-image-crop-pickerfor your platform. Refer to the installation instructions and platform-specific configuration for more details. -
If you are running on Android, you may need to add the following lines to your
AndroidManifest.xmlfile:<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
-
- User
TypeError: Cannot read property 'openPicker' of null, js engine: hermes
- Assistant
The error message indicates that the
ImagePickerobject is null, which means that it has not been initialized correctly. Here are some potential solutions you can try:-
Make sure you have imported the
react-native-image-pickerlibrary correctly - try importing it using the following syntax:import ImagePicker from 'react-native-image-picker'; -
Check that you have initialized the
ImagePickerobject properly. You need to call to define the options and callback functions for the library. Here is an example:
-
- User
- Assistant
Sure! Can you please provide more context or specify what kind of code you would like to add? This will help me better understand what you are trying to achieve.
- User
i just have this err TypeError: Cannot read property 'launchImageLibrary' of undefined, js engine: hermes
- Assistant
The error message indicates that the
launchImageLibraryfunction of theImagePickerobject is undefined, which means theImagePickerlibrary is not imported correctly or is not installed properly.Here are some things you can try to fix this issue:
-
Make sure that the
react-native-image-crop-pickerpackage is installed correctly in your project. You can run the following command in the terminal to install it:npm install react-native-image-crop-picker -
After installing the library, import it in your code using the following statement:
import ImagePicker from 'react-native-image-crop-picker'; -
If you are using Expo, it is recommended to use the
expo-image-pickerlibrary instead ofreact-native-image-crop-picker. You can install it using the following command:expo install expo-image-pickerAfter installing it, import it using the following statement:
-
- User
- Assistant
Great! To resolve the issue with the
ImagePickerlibrary, you will need to change your import statement andchooseImagefunction:-
Replace the import statement for
ImagePicker:import ImagePicker from 'expo-image-picker'; -
Modify the
chooseImagefunction to use `ImagePicker
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.