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
d8ea109f
Commit
d8ea109f
authored
Mar 30, 2018
by
少言
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
0.1.4
parent
5841717f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
15 deletions
+15
-15
README.md
README.md
+1
-1
RNSyanImagePickerModule.java
...c/main/java/com/reactlibrary/RNSyanImagePickerModule.java
+2
-2
RNSyanImagePicker.m
ios/RNSyanImagePicker.m
+11
-11
package.json
package.json
+1
-1
No files found.
README.md
View file @
d8ea109f
...
...
@@ -16,7 +16,7 @@
### 功能特点
*
支持 iOS、Android 两端
*
支持单选、多选
,类型包括图片、GIF
*
支持单选、多选
*
可自定义裁剪区域大小,支持圆形裁剪
*
可设置压缩质量
*
支持返回图片 base64 编码
...
...
android/src/main/java/com/reactlibrary/RNSyanImagePickerModule.java
View file @
d8ea109f
...
...
@@ -259,7 +259,7 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
byte
[]
encode
=
Base64
.
encode
(
bytes
,
Base64
.
DEFAULT
);
String
encodeString
=
new
String
(
encode
);
return
encodeString
;
return
"data:image/jpeg;base64,"
+
encodeString
;
}
/**
...
...
@@ -286,4 +286,4 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
this
.
mPickerPromise
.
reject
(
SY_SELECT_IMAGE_FAILED_CODE
,
"取消"
);
}
}
}
\ No newline at end of file
}
ios/RNSyanImagePicker.m
View file @
d8ea109f
...
...
@@ -99,7 +99,7 @@ RCT_EXPORT_METHOD(deleteCache) {
}
}
}
__block
TZImagePickerController
*
weakPicker
=
imagePickerVc
;
[
imagePickerVc
setDidFinishPickingPhotosWithInfosHandle
:
^
(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
,
NSArray
<
NSDictionary
*>
*
infos
)
{
NSMutableArray
*
selectedPhotos
=
[
NSMutableArray
array
];
...
...
@@ -114,11 +114,11 @@ RCT_EXPORT_METHOD(deleteCache) {
[
self
invokeSuccessWithResult
:
selectedPhotos
];
[
weakPicker
hideProgressHUD
];
}];
[
imagePickerVc
setImagePickerControllerDidCancelHandle
:
^
{
[
self
invokeError
];
}];
[[
self
topViewController
]
presentViewController
:
imagePickerVc
animated
:
YES
completion
:
nil
];
}
...
...
@@ -191,12 +191,12 @@ RCT_EXPORT_METHOD(deleteCache) {
[
picker
dismissViewControllerAnimated
:
YES
completion
:
nil
];
NSString
*
type
=
[
info
objectForKey
:
UIImagePickerControllerMediaType
];
if
([
type
isEqualToString
:
@"public.image"
])
{
TZImagePickerController
*
tzImagePickerVc
=
[[
TZImagePickerController
alloc
]
initWithMaxImagesCount
:
1
delegate
:
nil
];
tzImagePickerVc
.
sortAscendingByModificationDate
=
NO
;
[
tzImagePickerVc
showProgressHUD
];
UIImage
*
image
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
// save photo and get asset / 保存图片,获取到asset
[[
TZImageManager
manager
]
savePhotoWithImage
:
image
location
:
NULL
completion
:^
(
NSError
*
error
){
if
(
error
)
{
...
...
@@ -206,7 +206,7 @@ RCT_EXPORT_METHOD(deleteCache) {
[[
TZImageManager
manager
]
getCameraRollAlbum
:
NO
allowPickingImage
:
YES
needFetchAssets
:
YES
completion
:^
(
TZAlbumModel
*
model
)
{
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
model
.
result
allowPickingVideo
:
NO
allowPickingImage
:
YES
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
[
tzImagePickerVc
hideProgressHUD
];
TZAssetModel
*
assetModel
=
[
models
firstObject
];
BOOL
isCrop
=
[
self
.
cameraOptions
sy_boolForKey
:
@"isCrop"
];
BOOL
showCropCircle
=
[
self
.
cameraOptions
sy_boolForKey
:
@"showCropCircle"
];
...
...
@@ -214,7 +214,7 @@ RCT_EXPORT_METHOD(deleteCache) {
NSInteger
CropH
=
[
self
.
cameraOptions
sy_integerForKey
:
@"CropH"
];
NSInteger
circleCropRadius
=
[
self
.
cameraOptions
sy_integerForKey
:
@"circleCropRadius"
];
NSInteger
quality
=
[
self
.
cameraOptions
sy_integerForKey
:
@"quality"
];
if
(
isCrop
)
{
TZImagePickerController
*
imagePicker
=
[[
TZImagePickerController
alloc
]
initCropTypeWithAsset
:
assetModel
.
asset
photo
:
image
completion
:^
(
UIImage
*
cropImage
,
id
asset
)
{
[
self
invokeSuccessWithResult
:@[[
self
handleImageData
:
cropImage
quality
:
quality
]]];
...
...
@@ -258,12 +258,12 @@ RCT_EXPORT_METHOD(deleteCache) {
-
(
NSDictionary
*
)
handleImageData
:
(
UIImage
*
)
image
quality
:
(
NSInteger
)
quality
{
NSMutableDictionary
*
photo
=
[
NSMutableDictionary
dictionary
];
NSData
*
imageData
=
UIImageJPEGRepresentation
(
image
,
quality
*
1
.
0
/
100
);
// 剪切图片并放在tmp中
photo
[
@"width"
]
=
@
(
image
.
size
.
width
);
photo
[
@"height"
]
=
@
(
image
.
size
.
height
);
photo
[
@"size"
]
=
@
(
imageData
.
length
);
NSString
*
fileName
=
[
NSString
stringWithFormat
:
@"%@.jpg"
,
[[
NSUUID
UUID
]
UUIDString
]];
[
self
createDir
];
NSString
*
filePath
=
[
NSString
stringWithFormat
:
@"%@ImageCaches/%@"
,
NSTemporaryDirectory
(),
fileName
];
...
...
@@ -272,9 +272,9 @@ RCT_EXPORT_METHOD(deleteCache) {
}
else
{
NSLog
(
@"保存压缩图片失败%@"
,
filePath
);
}
if
([
self
.
cameraOptions
sy_boolForKey
:
@"enableBase64"
])
{
photo
[
@"base64"
]
=
[
imageData
base64EncodedStringWithOptions
:
0
];
photo
[
@"base64"
]
=
[
NSString
stringWithFormat
:
@"data:image/jpeg;base64,%@"
,
[
imageData
base64EncodedStringWithOptions
:
0
]
];
}
return
photo
;
}
...
...
package.json
View file @
d8ea109f
{
"name"
:
"react-native-syan-image-picker"
,
"version"
:
"0.1.
2
"
,
"version"
:
"0.1.
4
"
,
"description"
:
""
,
"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