Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-syan-image-picker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenSource
react-native-syan-image-picker
Commits
09ab3aea
Commit
09ab3aea
authored
May 08, 2019
by
少言
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v0.3.6
parent
b1f06c98
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
37 deletions
+65
-37
README.md
README.md
+32
-1
RNSyanImagePickerModule.java
...src/main/java/com/syanpicker/RNSyanImagePickerModule.java
+32
-35
package.json
package.json
+1
-1
No files found.
README.md
View file @
09ab3aea
...
...
@@ -135,17 +135,47 @@ android {
### Android
1. Open up `android/app/src/main/java/[...]/MainApplication.java`
- Add `import com.reactlibrary.RNSyanImagePickerPackage;` to the imports at the top of the file
- Add `new RNSyanImagePickerPackage()` to the list returned by the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```gradle
include ':react-native-syan-image-picker'
project(':react-native-syan-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-syan-image-picker/android')
```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```gradle
compile project(':react-native-syan-image-picker')
```
4. 拍照前动态获取权限
```
js
requestPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: '申请读写手机存储权限',
message:
'一个很牛逼的应用想借用你的摄像头,' +
'然后你就可以拍出酷炫的皂片啦。',
buttonNeutral: '等会再问我',
buttonNegative: '不行',
buttonPositive: '好吧',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('现在你获得摄像头权限了');
} else {
console.log('用户并不给你');
}
} catch (err) {
console.warn(err);
}
};
```
## 运行示例
...
...
@@ -167,7 +197,8 @@ showCropCircle | bool | 是 | false | 是否显示圆形裁剪区
circleCropRadius | float | 是 | screenW * 0.5 | 圆形裁剪半径,默认屏幕宽度一半
showCropFrame | bool | 是 | true | 是否显示裁剪区域
showCropGrid | bool | 是 | false | 是否隐藏裁剪区域网格
quality | int | 是 | 90 | 压缩质量
quality | int | 是 | 90 | 压缩质量(安卓无效,固定鲁班压缩)
minimumCompressSize | int | 是 | 100 | 小于100kb的图片不压缩(Android)
enableBase64 | bool | 是 | false | 是否返回base64编码,默认不返回
## 返回结果说明
...
...
android/src/main/java/com/syanpicker/RNSyanImagePickerModule.java
View file @
09ab3aea
...
...
@@ -217,10 +217,6 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
.
showCropFrame
(
showCropFrame
)
// 是否显示裁剪矩形边框 圆形裁剪时建议设为false true or false
.
showCropGrid
(
showCropGrid
)
// 是否显示裁剪矩形网格 圆形裁剪时建议设为false true or false
.
openClickSound
(
false
)
// 是否开启点击声音 true or false
.
videoQuality
(
1
)
// 视频录制质量 0 or 1 int
.
videoMaxSecond
(
15
)
// 显示多少秒以内的视频or音频也可适用 int
.
videoMinSecond
(
10
)
// 显示多少秒以内的视频or音频也可适用 int
.
recordVideoSecond
(
60
)
//视频秒数录制 默认60s int
.
cropCompressQuality
(
quality
)
// 裁剪压缩质量 默认90 int
.
minimumCompressSize
(
minimumCompressSize
)
// 小于100kb的图片不压缩
.
synOrAsy
(
true
)
//同步true或异步false 压缩 默认同步
...
...
@@ -285,23 +281,28 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
private
final
ActivityEventListener
mActivityEventListener
=
new
BaseActivityEventListener
()
{
@Override
public
void
onActivityResult
(
Activity
activity
,
int
requestCode
,
int
resultCode
,
final
Intent
data
)
{
if
(
requestCode
==
PictureConfig
.
CHOOSE_REQUEST
)
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
onGetResult
(
data
);
}
}).
run
();
}
else
if
(
requestCode
==
PictureConfig
.
REQUEST_CAMERA
)
{
onGetVideoResult
(
data
);
if
(
resultCode
==
-
1
)
{
if
(
requestCode
==
PictureConfig
.
CHOOSE_REQUEST
)
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
onGetResult
(
data
);
}
}).
run
();
}
else
if
(
requestCode
==
PictureConfig
.
REQUEST_CAMERA
)
{
onGetVideoResult
(
data
);
}
}
else
{
invokeError
(
resultCode
);
}
}
};
private
void
onGetVideoResult
(
Intent
data
)
{
List
<
LocalMedia
>
mVideoSelectList
=
PictureSelector
.
obtainMultipleResult
(
data
);
boolean
isRecordSelected
V
=
cameraOptions
.
getBoolean
(
"isRecordSelected"
);
if
(!
mVideoSelectList
.
isEmpty
()
&&
isRecordSelected
V
)
{
boolean
isRecordSelected
=
cameraOptions
.
getBoolean
(
"isRecordSelected"
);
if
(!
mVideoSelectList
.
isEmpty
()
&&
isRecordSelected
)
{
selectList
=
mVideoSelectList
;
}
WritableArray
videoList
=
new
WritableNativeArray
();
...
...
@@ -309,20 +310,16 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
if
(
TextUtils
.
isEmpty
(
media
.
getPath
())){
continue
;
}
WritableMap
avideo
=
new
WritableNativeMap
();
avideo
.
putString
(
"size"
,
new
File
(
media
.
getPath
()).
length
()
+
""
);
avideo
.
putString
(
"duration"
,
media
.
getDuration
()
+
""
);
avideo
.
putString
(
"fileName"
,
new
File
(
media
.
getPath
()).
getName
());
avideo
.
putString
(
"uri"
,
"file://"
+
media
.
getPath
());
avideo
.
putString
(
"type"
,
"video"
);
videoList
.
pushMap
(
avideo
);
WritableMap
videoMap
=
new
WritableNativeMap
();
videoMap
.
putString
(
"size"
,
new
File
(
media
.
getPath
()).
length
()
+
""
);
videoMap
.
putString
(
"duration"
,
media
.
getDuration
()
+
""
);
videoMap
.
putString
(
"fileName"
,
new
File
(
media
.
getPath
()).
getName
());
videoMap
.
putString
(
"uri"
,
"file://"
+
media
.
getPath
());
videoMap
.
putString
(
"type"
,
"video"
);
videoList
.
pushMap
(
videoMap
);
}
if
(
mVideoSelectList
.
isEmpty
())
{
invokeError
();
}
else
{
invokeSuccessWithResult
(
videoList
);
}
invokeSuccessWithResult
(
videoList
);
}
private
void
onGetResult
(
Intent
data
)
{
...
...
@@ -338,11 +335,7 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
for
(
LocalMedia
media
:
tmpSelectList
)
{
imageList
.
pushMap
(
getImageResult
(
media
,
enableBase64
));
}
if
(
tmpSelectList
.
isEmpty
())
{
invokeError
();
}
else
{
invokeSuccessWithResult
(
imageList
);
}
invokeSuccessWithResult
(
imageList
);
}
private
WritableMap
getImageResult
(
LocalMedia
media
,
Boolean
enableBase64
)
{
...
...
@@ -419,12 +412,16 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
/**
* 取消选择时触发
*/
private
void
invokeError
()
{
private
void
invokeError
(
int
resultCode
)
{
String
message
=
"取消"
;
if
(
resultCode
!=
0
)
{
message
=
String
.
valueOf
(
resultCode
);
}
if
(
this
.
mPickerCallback
!=
null
)
{
this
.
mPickerCallback
.
invoke
(
"取消"
);
this
.
mPickerCallback
.
invoke
(
message
);
this
.
mPickerCallback
=
null
;
}
else
if
(
this
.
mPickerPromise
!=
null
)
{
this
.
mPickerPromise
.
reject
(
SY_SELECT_IMAGE_FAILED_CODE
,
"取消"
);
this
.
mPickerPromise
.
reject
(
SY_SELECT_IMAGE_FAILED_CODE
,
message
);
}
}
...
...
package.json
View file @
09ab3aea
{
"name"
:
"react-native-syan-image-picker"
,
"version"
:
"0.3.
5
"
,
"version"
:
"0.3.
6
"
,
"description"
:
"React-Native 多图片选择 支持裁剪 压缩"
,
"main"
:
"index.js"
,
"scripts"
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment