react-native-image-picker配置
来源:互联网 发布:app应用下载推广源码 编辑:程序博客网 时间:2024/06/05 23:52
测试环境:android react-native 0.47.1
1、npm install react-native-image-picker@latest --save2、react-native link
Android:
1、在文件
android/settings.gradle中
添加
include ':react-native-image-picker'project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
2、更改
android/build.gradle
:buildscript { ... dependencies { classpath 'com.android.tools.build:gradle:2.2.+' // <- USE 2.2.+ version } ...}...
3、更改
android/gradle/wrapper/gradle-wrapper.properties
:...distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
4、在文件 android/app/build.gradle
中添加
dependencies { compile project(':react-native-image-picker')}
5、在文件 android/app/src/main/
AndroidManifest.xml中添加
<uses-permission android:name="android.permission.CAMERA" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
6、在文件
MainApplication.java
中添加
import com.imagepicker.ImagePickerPackage; // <-- add this importpublic class MainApplication extends Application implements ReactApplication { @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new ImagePickerPackage() // <-- add this line // OR if you want to customize dialog style new ImagePickerPackage(R.style.my_dialog_style) ); }}
7、配置弹窗样式
android/app/res/values/themes.xml
:
<?xml version="1.0" encoding="utf-8"?><resources> <style name="DefaultExplainingPermissionsTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <!-- Used for the buttons --> <item name="colorAccent">#61c3e7</item> <!-- Used for the title and text --> <item name="android:textColorPrimary">#3d3d3d</item> <!-- Used for the background --> <item name="android:background">@android:color/white</item> </style></resources>
使用:
import ImagePicker from 'react-native-image-picker'; //第三方相机var photoOptions = { //底部弹出框选项 title:'请选择', cancelButtonTitle:'取消', takePhotoButtonTitle:'拍照', chooseFromLibraryButtonTitle:'相册', quality:0.75, allowsEditing:true, noData:false, storageOptions: { skipBackup: true, path:'images' }}
<Text onPress={()=>this.openMycamera()}>选择文件</Text>openMycamera = () =>{ ImagePicker.showImagePicker(photoOptions,(response) =>{ console.log('response'+response); if (response.didCancel){ return } }) }
结果:
阅读全文
0 0
- react-native-image-picker配置
- react-native-image-picker
- react-native-image-picker
- react-native-image-picker
- react-native-image-crop-picker学习
- react-native-image-crop-picker记录学习
- React Native开源库react-native-image-crop-picker使用图解
- React Native开源库react-native-image-crop-picker使用图解
- React-Native-image-picker-调取摄像头第三方组件:
- react-native-image-picker在iOS上闪退的解决办法
- RN-第三方-react-native-image-picker,选择图片上传
- React Native 的Image 保存、Picker、上传等一系列问题
- 使用react-native-image-crop-picker上传图片
- React Native 使用react-native-image-picker插件上传图片详细步骤
- React Native 使用react-native-image-picker库实现图片上传功能
- react-native- images -crop-picker
- react native Picker 使用详解
- react-native-image-picker上传头像 + modal浮层 +AsyncStorage.setItem-getItem
- 前端模块化开发那点历史
- Event和Mutex区别
- HDU-4135 Co-prime(容斥原理)
- jvm 调优之垃圾回收
- Sticky footer布局
- react-native-image-picker配置
- 自考路漫漫之数据库系统
- 安卓实训日记第15天
- bzoj 2820(Mobius)
- Android上的Mosquitto推送
- 实现数组元素互换位置(乘机理解java参数传递)
- Java如何调整图片的大小?
- JSON数据解析生成一个每行10列,行数不固定的表格
- 使用Eclipse 导出jar包,同时将额外的jar加入一起导出