Skip to content

Commit 1c84e36

Browse files
committed
fix callback from swift
1 parent 3020341 commit 1c84e36

File tree

5 files changed

+14
-26
lines changed

5 files changed

+14
-26
lines changed

example/src/App.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export default function App() {
2727
selectedAssets: images,
2828
isExportThumbnail: true,
2929
maxVideo: 1,
30-
singleSelectedMode: true,
31-
isCrop: true,
30+
// singleSelectedMode: true,
31+
// isCrop: true,
3232
});
3333
// console.log(response);
34-
// setImages(response);
34+
setImages(response);
3535
} catch (e) {}
3636
};
3737

@@ -40,7 +40,7 @@ export default function App() {
4040
<ScrollView contentContainerStyle={{ paddingTop: 132 }}>
4141
<View style={{ alignItems: 'center' }}>
4242
<ImageGrid
43-
dataImage={images}
43+
dataImage={Array.isArray(images) ? images : [images]}
4444
onPressImage={onPressImage}
4545
// spaceSize={10}
4646
containerStyle={{ marginTop: 3 }}

ios/MediaResponse.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,14 @@ public struct MediaResponse {
1414
public enum MediaType: String {
1515
case image, video
1616
}
17-
18-
// public var path: String = "";
19-
// public var localIdentifier: String = "";
20-
// public var fileName: String = "";
21-
// public var width: NSNumber = 0;
22-
// public var height: NSNumber = 0;
23-
// public var mime: String = "";
24-
// public var creationDate: Date;
25-
// public var type: MediaType = .image;
26-
//
17+
2718
public var data: NSDictionary? = nil
2819

2920

3021
init(filePath: String?, mime: String?, withTLAsset TLAsset: TLPHAsset, isExportThumbnail: Bool = false) {
31-
var asset = TLAsset.phAsset
22+
23+
let asset = TLAsset.phAsset
24+
3225
if(asset != nil){
3326
var media = [
3427
"path": filePath! as String,
@@ -57,6 +50,7 @@ public struct MediaResponse {
5750
media["size"] = photoSize
5851
}
5952
}
53+
6054
self.data = NSDictionary(dictionary: media)
6155
}
6256
}

ios/MultipleImagePicker.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
217217
}
218218

219219
func fetchAsset(TLAsset: TLPHAsset ,completion: @escaping (MediaResponse) -> Void) {
220-
let index = TLAsset.selectedOrder - 1;
221-
222220
TLAsset.tempCopyMediaFile(videoRequestOptions: self.videoRequestOptions, imageRequestOptions: self.imageRequestOptions, livePhotoRequestOptions: nil, exportPreset: AVAssetExportPresetHighestQuality, convertLivePhotosToJPG: true, progressBlock: { (progress) in
223221
}, completionBlock: { (filePath, fileType) in
224222

@@ -228,14 +226,13 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
228226
completion(object)
229227
}
230228
})
231-
232229
}
233230

234231
func dismissPhotoPicker(withTLPHAssets: [TLPHAsset]) {
235232

236233
// check with asset picker
237234
if(withTLPHAssets.count == 0){
238-
self.resolve([]);
235+
resolve([]);
239236
dismissComplete()
240237
return;
241238
}
@@ -281,16 +278,14 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
281278
for TLAsset in withTLPHAssets {
282279
group.enter()
283280
self.fetchAsset(TLAsset: TLAsset) { object in
284-
// check nil object response
285-
if(object != nil) {
286-
selections[index] = object as MediaResponse;
287-
}
281+
let index = TLAsset.selectedOrder - 1;
282+
selections[index] = object.data as Any;
288283
group.leave();
289284
}
290285
}
291286

292287
group.notify(queue: .main){ [self] in
293-
resolve(selections);
288+
resolve(selections)
294289
DispatchQueue.main.async {
295290
alert.dismiss(animated: true, completion: {
296291
self.dismissComplete()

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export const openPicker = (optionsPicker) => {
6464
return new Promise(async (resolve, reject) => {
6565
try {
6666
const response = await MultipleImagePicker.openPicker(options);
67-
// console.log('res', response);
6867
if (response?.length) {
6968
if (isSingle) {
7069
resolve(response[0]);

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"baseUrl": ".",
44
"paths": {
5-
"@baronha/react-native-multiple-image-picker": ["./src"]
5+
"@baronha/react-native-multiple-image-picker": ["src"]
66
},
77
"allowUnreachableCode": false,
88
"allowUnusedLabels": false,

0 commit comments

Comments
 (0)