@koimy/rn-image-picker
v1.0.2
Published
选择图片
Downloads
12
Readme
选择图片
安装
yarn add @koimy/rn-image-picker
配置
android/build.gradle
allprojects {
repositories {
...
maven { url 'https://maven.google.com' }
maven { url 'https://www.jitpack.io' }
}
}
android/app/build.gradle
android {
...
defaultConfig {
...
vectorDrawables.useSupportLibrary = true // 选择图片
}
}
android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<!-- 前置摄像头 -->
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
使用示例
import React, { useState } from 'react';
import { Image, Text, TouchableOpacity } from 'react-native';
import image_picker, { ImageData } from '@koimy/rn-image-picker';
export default () => {
// 图片
const [image, set_image] = useState<ImageData>({});
/**
* 选取图片
*/
const picker = async () => {
const res = await image_picker({
multiple: false,
mediaType: 'photo'
});
set_image(res[0]);
};
return (
<TouchableOpacity style={{ width: '100%', height: '100%' }} onPress={() => picker()}>
{
image.path ? (
<Image resizeMode='cover' style={{ width: '100%', height: '100%' }} source={{ uri: image.path }}></Image>
) : (
<Text>选择图片</Text>
)
}
</TouchableOpacity>
);
};