native react 图片多选_react-native实现的多图片选择器

react-native-syan-image-picker

功能介绍

基于已有原生第三方框架封装的多图片选择组件,适用于 React Native App。

原生框架依赖

功能特点

支持 iOS、Android 两端

支持单选、多选

可自定义裁剪区域大小,支持圆形裁剪

可设置压缩质量

可设置是否返回图片 base64 编码

支持记录当前已选中的图片

支持删除指定下标的图片

Live

安装使用

安装

// Step 1 基于 npm

npm install react-native-syan-image-picker --save

// 或是 yarn

yarn add react-native-syan-image-picker

// Step 2 执行 link

react-native link react-native-syan-image-picker

其他配置

iOS

1、添加原生框架中所需的 bundle 文件:

TARGETS -> Build Phases -> Copy Bundle Resources 点击"+"按钮,在弹出的窗口中点击“Add Other”按钮,选择 node_modules/react-native-syan-image-picker/ios/TZImagePickerController/TZImagePickerController.bundle

2、添加相册相关权限:

项目目录->Info.plist->增加

Privacy - Camera Usage Description 是否允许此App使用你的相机进行拍照?

Privacy - Photo Library Usage Description 请允许访问相册以选取照片

Privacy - Photo Library Additions Usage Description 请允许访问相册以选取照片

Privacy - Location When In Use Usage Description 我们需要通过您的地理位置信息获取您周边的相关数据

3、中文适配:

添加中文 PROJECT -> Info -> Localizations 点击"+"按钮,选择Chinese(Simplified)

Android

1、在 AndroidManifest.xml 中添加权限:

2、更新到 PictureSelector需要修改minSdkVersion:

// app/build.gradle

android {

minSdkVersion = 19

...

}

3、拍照前动态获取权限

requestPermission = async () => {

try {

const granted = await PermissionsAndroid.request(

PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,

{

title: '申请读写手机存储权限',

message:

'一个很牛逼的应用想借用你的摄像头,' +

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,关于React Native图片多选,可以使用react-native-image-picker这个第三方库来实现。以下是使用步骤: 1. 使用npm或者yarn安装该库:`npm install react-native-image-picker` 或者 `yarn add react-native-image-picker` 2. 在iOS中,需要执行`pod install`命令安装相关依赖库。在iOS工程目录下创建Podfile文件,输入以下内容: ``` platform :ios, '9.0' target 'YourApp' do pod 'React', :path => '../node_modules/react-native', :subspecs => [ 'Core', 'CxxBridge', 'RCTText', 'RCTNetwork', 'RCTWebSocket', 'RCTAnimation' ] pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga' pod 'react-native-image-picker', :path => '../node_modules/react-native-image-picker' end ``` 3. 在Android中,需要在AndroidManifest.xml文件中添加相关权限: ``` <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> ``` 4. 在React Native组件中导入该库: ``` import ImagePicker from 'react-native-image-picker'; ``` 5. 使用ImagePicker.launchImageLibrary方法选择图片: ``` ImagePicker.launchImageLibrary(options, (response) => { console.log('Response = ', response); if (response.didCancel) { console.log('User cancelled image picker'); } else if (response.error) { console.log('ImagePicker Error: ', response.error); } else if (response.customButton) { console.log('User tapped custom button: ', response.customButton); } else { const source = { uri: response.uri }; // You can also display the image using data: // const source = { uri: 'data:image/jpeg;base64,' + response.data }; this.setState({ avatarSource: source, }); } }); ``` 其中,options参数可以配置图片选择器的一些选项,如选择多张图片等。详细使用方法可以查看该库的官方文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值