首页 > 解决方案 > 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?

标签: react-nativeexpo

解决方案


如果你想使用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 });
    }
  };
}

推荐阅读