react-native - React Native - 在博览会弹出后重新安装博览会
问题描述
我在使用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?
解决方案
如果你想使用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 });
}
};
}
推荐阅读
- wpf - 如何将 StartupEventArgs 传递给 Prism 应用程序中的其他 ViewModel
- azure - Azure Devops - 多项目看板
- datastage - IBM DataStage:作业活动未按顺序继续
- html - 防止左列flexbox(导航)与主要内容一起滚动?
- jquery - jQuery对话框的问题,链接某些ID
- python - 在 PHP 中调用 Python 代码并显示输出
- java - 使用智能手机的电视天线作为发送和接收射频信号的天线
- javascript - ReactJS 时间戳
- python - 使用 infer_vector() 检查 doc2vec 的模型过拟合
- wordpress - 是否可以将分类术语用作类别?