मुझे react-native-image-picker
लाइब्रेरी का उपयोग करने में समस्या आ रही थी। इसलिए, मैंने RCTCameraRoll को Xcode लाइब्रेरी में जोड़कर लिंक करने का प्रयास किया। हालाँकि, Xcode का उपयोग करके अपना प्रोजेक्ट खोलने के लिए मुझे expo eject
चलाना पड़ा।
अब, मैं अपना प्रोजेक्ट कैसे चला सकता हूँ? कमांड चलाते समय: expo start
यह वापस आता है:
Property 'expo' in app.json is not an object. Please make sure app.json includes a managed Expo app config like this: {"expo":{"name":"My app","slug":"my-app","sdkVersion":"..."}}
No Expo configuration found. Are you sure this is a project directory?
1 उत्तर
यदि आप expo
का उपयोग करना चाहते हैं, तो आप ImagePicker का उपयोग कर सकते हैं, लेकिन आपको Expo
को एक स्टैंड-अलोन ऐप बनाने की आवश्यकता नहीं है।
आप expo install expo-image-picker
चला सकते हैं
प्रयोग
import * as React from 'react';
import { Button, Image, View } from 'react-native';
import * as ImagePicker from 'expo-image-picker';
import Constants from 'expo-constants';
import * as Permissions from 'expo-permissions';
export default class ImagePickerExample extends React.Component {
state = {
image: null,
};
render() {
let { image } = this.state;
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button
title="Pick an image from camera roll"
onPress={this._pickImage}
/>
{image &&
<Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
</View>
);
}
componentDidMount() {
this.getPermissionAsync();
}
getPermissionAsync = async () => {
if (Constants.platform.ios) {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status !== 'granted') {
alert('Sorry, we need camera roll permissions to make this work!');
}
}
}
_pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
});
console.log(result);
if (!result.cancelled) {
this.setState({ image: result.uri });
}
};
}
संबंधित सवाल
नए सवाल
react-native
React native एक जावास्क्रिप्ट लाइब्रेरी है, जिसका उपयोग React का उपयोग करके देशी मोबाइल ऐप बनाने के लिए किया जाता है। रिएक्ट नेटिव का फोकस उन सभी प्लेटफार्मों पर डेवलपर दक्षता पर है जिनकी आप परवाह करते हैं - एक बार सीखें, कहीं भी लिखें।