Skip to content

Commit 931c38e

Browse files
committed
fix: mime / feat: add photo/video size in response
1 parent cc3ae14 commit 931c38e

File tree

6 files changed

+39
-32
lines changed

6 files changed

+39
-32
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ dependencies {
127127
// noinspection GradleDynamicVersion
128128
api 'com.facebook.react:react-native:+'
129129
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
130-
implementation ('com.github.LuckSiege.PictureSelector:picture_library:v2.6.0'){
130+
implementation ('io.github.lucksiege:pictureselector:v2.7.2'){
131131
exclude group: 'com.github.LuckSiege.PictureSelector', module: 'ucrop'
132132
}
133133
implementation 'com.github.bumptech.glide:glide:4.12.0'

android/src/main/java/com/reactnativemultipleimagepicker/MultipleImagePickerModule.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ class MultipleImagePickerModule(reactContext: ReactApplicationContext) : ReactCo
172172
val height: Int = asset.getInt("height")
173173
val size: Long = asset.getDouble("size").toLong()
174174
val bucketId: Long = asset.getDouble("bucketId").toLong()
175-
val localMedia = LocalMedia(id, path, realPath, fileName, parentFolderName, duration, chooseModel, mimeType, width, height, size, bucketId)
175+
val dateAddedColumn: Long = Date().time.toLong()
176+
val localMedia = LocalMedia(id, path, realPath, fileName, parentFolderName, duration, chooseModel, mimeType, width, height, size, bucketId, dateAddedColumn)
176177
return localMedia
177178
}
178179

@@ -185,7 +186,7 @@ class MultipleImagePickerModule(reactContext: ReactApplicationContext) : ReactCo
185186
media.putString("fileName", item.fileName)
186187
media.putInt("width", item.width)
187188
media.putInt("height", item.height)
188-
media.putString("mine", item.mimeType)
189+
media.putString("mime", item.mimeType)
189190
media.putString("type", type)
190191
media.putInt("localIdentifier", item.id.toInt())
191192
media.putInt("position", item.position)
@@ -228,6 +229,7 @@ class MultipleImagePickerModule(reactContext: ReactApplicationContext) : ReactCo
228229
return ""
229230
}
230231
}
232+
231233
private fun createDirIfNotExists(path: String): File {
232234
val dir = File(path)
233235
if (dir.exists()) {

example/ios/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ PODS:
185185
- React-cxxreact (= 0.63.4)
186186
- React-jsi (= 0.63.4)
187187
- React-jsinspector (0.63.4)
188-
- react-native-multiple-image-picker (0.1.2):
188+
- react-native-multiple-image-picker (0.2.10):
189189
- React-Core
190190
- TLPhotoPicker
191191
- React-RCTActionSheet (0.63.4):
@@ -248,7 +248,7 @@ PODS:
248248
- React-Core (= 0.63.4)
249249
- React-cxxreact (= 0.63.4)
250250
- React-jsi (= 0.63.4)
251-
- TLPhotoPicker (2.1.3)
251+
- TLPhotoPicker (2.1.4)
252252
- Yoga (1.14.0)
253253

254254
DEPENDENCIES:
@@ -360,7 +360,7 @@ SPEC CHECKSUMS:
360360
React-jsi: a0418934cf48f25b485631deb27c64dc40fb4c31
361361
React-jsiexecutor: 93bd528844ad21dc07aab1c67cb10abae6df6949
362362
React-jsinspector: 58aef7155bc9a9683f5b60b35eccea8722a4f53a
363-
react-native-multiple-image-picker: a96a603caef6b0228c88b15f4d1260a27114769f
363+
react-native-multiple-image-picker: 1bf3daea720df4b8679226cfccef5539585f2255
364364
React-RCTActionSheet: 89a0ca9f4a06c1f93c26067af074ccdce0f40336
365365
React-RCTAnimation: 1bde3ecc0c104c55df246eda516e0deb03c4e49b
366366
React-RCTBlob: a97d378b527740cc667e03ebfa183a75231ab0f0
@@ -371,9 +371,9 @@ SPEC CHECKSUMS:
371371
React-RCTText: 5c51df3f08cb9dedc6e790161195d12bac06101c
372372
React-RCTVibration: ae4f914cfe8de7d4de95ae1ea6cc8f6315d73d9d
373373
ReactCommon: 73d79c7039f473b76db6ff7c6b159c478acbbb3b
374-
TLPhotoPicker: 2c4a20d62952bd368edbf44d18476f663a718ada
374+
TLPhotoPicker: f486e8499e1c3f464d0e886697635e25a72a52b8
375375
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6
376376

377377
PODFILE CHECKSUM: 739a34f1722633656d85522351accd0e9e63cc35
378378

379-
COCOAPODS: 1.10.0
379+
COCOAPODS: 1.10.1

example/src/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default function App() {
1313
selectedAssets: images,
1414
isExportThumbnail: true,
1515
maxVideo: 1,
16+
singleSelectedMode: true,
1617
// selectedColor: '#f9813a',
1718
});
1819
console.log('done: ', response);

ios/MultipleImagePicker.swift

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
5151

5252
func dismissComplete() {
5353
DispatchQueue.main.async {
54-
self.getTopMostViewController()?.dismiss(animated: true, completion: nil)
54+
self.getTopMostViewController()?.dismiss(animated: true, completion: nil)
5555
}
5656
}
5757

@@ -108,7 +108,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
108108
let mediaType = self.options["mediaType"] as! String;
109109

110110
MultipleImagePickerConfigure.mediaType = mediaType == "video" ? PHAssetMediaType.video : mediaType == "image" ? PHAssetMediaType.image : nil ;
111-
111+
112112
MultipleImagePickerConfigure.nibSet = (nibName: "Cell", bundle: MultipleImagePickerBundle.bundle())
113113

114114
// configure.allowedPhotograph = self.options["allowedPhotograph"]
@@ -143,7 +143,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
143143
}
144144

145145
func createAttachmentResponse(filePath: String?, withFilename filename: String?, withType type: String?, withAsset asset: PHAsset, withTLAsset TLAsset: TLPHAsset ) -> [AnyHashable :Any]? {
146-
146+
print("asets: ",asset, TLAsset)
147147
var media = [
148148
"path": "file://" + filePath! as String,
149149
"localIdentifier": asset.localIdentifier,
@@ -155,9 +155,21 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
155155
"type": asset.mediaType == .video ? "video" : "image"
156156
] as [String : Any]
157157

158-
if(asset.mediaType == .video && options["isExportThumbnail"] as! Bool){
159-
let thumbnail = getThumbnail(from: filePath!, in: 0.1)
160-
media["thumbnail"] = thumbnail
158+
//option in video
159+
if(asset.mediaType == .video){
160+
//get video's thumbnail
161+
if(options["isExportThumbnail"] as! Bool){
162+
let thumbnail = getThumbnail(from: filePath!, in: 0.1)
163+
media["thumbnail"] = thumbnail
164+
}
165+
//get video size
166+
TLAsset.videoSize { Int in
167+
media["size"] = Int
168+
}
169+
}else{
170+
TLAsset.photoSize { Int in
171+
media["size"] = Int
172+
}
161173
}
162174
return media
163175
}
@@ -197,23 +209,6 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
197209

198210
}
199211

200-
// func resizedImage(at url: URL, for size: CGSize) -> UIImage? {
201-
// let options: [CFString: Any] = [
202-
// kCGImageSourceCreateThumbnailFromImageIfAbsent: true,
203-
// kCGImageSourceCreateThumbnailWithTransform: true,
204-
// kCGImageSourceShouldCacheImmediately: true,
205-
// kCGImageSourceThumbnailMaxPixelSize: max(size.width, size.height)
206-
// ]
207-
//
208-
// guard let imageSource = CGImageSourceCreateWithURL(url as NSURL, nil),
209-
// let image = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options as CFDictionary)
210-
// else {
211-
// return nil
212-
// }
213-
//
214-
// return UIImage(cgImage: image)
215-
// }
216-
217212
func dismissPhotoPicker(withTLPHAssets: [TLPHAsset]) {
218213
if(withTLPHAssets.count == 0){
219214
self.resolve([]);
@@ -226,6 +221,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
226221
if(withTLPHAssetsCount == selectedAssetsCount && withTLPHAssets[withTLPHAssetsCount - 1].phAsset?.localIdentifier == self.selectedAssets[selectedAssetsCount-1].phAsset?.localIdentifier){
227222
return;
228223
}
224+
229225
let selections = NSMutableArray.init(array: withTLPHAssets);
230226
self.selectedAssets = withTLPHAssets
231227
//imageRequestOptions
@@ -240,7 +236,14 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
240236
group.enter()
241237
let asset = TLAsset.phAsset
242238
let index = TLAsset.selectedOrder - 1;
243-
TLAsset.tempCopyMediaFile(videoRequestOptions: nil, imageRequestOptions: imageRequestOptions, livePhotoRequestOptions: nil, exportPreset: AVAssetExportPresetHighestQuality, convertLivePhotosToJPG: true, progressBlock: { (Double) in
239+
240+
let videoRequestOptions = PHVideoRequestOptions.init()
241+
videoRequestOptions.version = PHVideoRequestOptionsVersion.current
242+
videoRequestOptions.deliveryMode = PHVideoRequestOptionsDeliveryMode.automatic
243+
videoRequestOptions.isNetworkAccessAllowed = true
244+
245+
TLAsset.tempCopyMediaFile(videoRequestOptions: videoRequestOptions, imageRequestOptions: imageRequestOptions, livePhotoRequestOptions: nil, exportPreset: AVAssetExportPresetHighestQuality, convertLivePhotosToJPG: true, progressBlock: { (Double) in
246+
print("progressBlock: ", Double)
244247

245248
}, completionBlock: { (filePath, fileType) in
246249
let object = NSDictionary(dictionary: self.createAttachmentResponse(

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ exportObject = {
6363
return new Promise(async (resolve, reject) => {
6464
try {
6565
const response = await MultipleImagePicker.openPicker(options);
66+
console.log('res', response);
6667
if (response?.length) {
6768
resolve(response);
6869
return;

0 commit comments

Comments
 (0)