Skip to content

Commit 37b8974

Browse files
committed
1 parent 0fcb10e commit 37b8974

File tree

7 files changed

+75
-52
lines changed

7 files changed

+75
-52
lines changed

example/ios/MultipleImagePickerExample.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
/* Begin PBXBuildFile section */
1010
00E356F31AD99517003FC87E /* MultipleImagePickerExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* MultipleImagePickerExampleTests.m */; };
11-
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
11+
0E8817ED29D74E5D004363C7 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0E8817EC29D74E5D004363C7 /* AppDelegate.mm */; };
12+
0E8817EE29D74E5D004363C7 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0E8817EC29D74E5D004363C7 /* AppDelegate.mm */; };
1213
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
1314
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
14-
2D02E4BC1E0B4A80006451C7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
1515
2D02E4BD1E0B4A84006451C7 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
1616
2D02E4BF1E0B4AB3006451C7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
1717
2DCD954D1E0B4F2C00145EB5 /* MultipleImagePickerExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* MultipleImagePickerExampleTests.m */; };
@@ -42,9 +42,9 @@
4242
00E356EE1AD99517003FC87E /* MultipleImagePickerExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MultipleImagePickerExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4343
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4444
00E356F21AD99517003FC87E /* MultipleImagePickerExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MultipleImagePickerExampleTests.m; sourceTree = "<group>"; };
45+
0E8817EC29D74E5D004363C7 /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = MultipleImagePickerExample/AppDelegate.mm; sourceTree = "<group>"; };
4546
13B07F961A680F5B00A75B9A /* MultipleImagePickerExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MultipleImagePickerExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
4647
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = MultipleImagePickerExample/AppDelegate.h; sourceTree = "<group>"; };
47-
13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = MultipleImagePickerExample/AppDelegate.m; sourceTree = "<group>"; };
4848
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = MultipleImagePickerExample/Images.xcassets; sourceTree = "<group>"; };
4949
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = MultipleImagePickerExample/Info.plist; sourceTree = "<group>"; };
5050
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = MultipleImagePickerExample/main.m; sourceTree = "<group>"; };
@@ -113,9 +113,9 @@
113113
13B07FAE1A68108700A75B9A /* MultipleImagePickerExample */ = {
114114
isa = PBXGroup;
115115
children = (
116+
0E8817EC29D74E5D004363C7 /* AppDelegate.mm */,
116117
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
117118
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
118-
13B07FB01A68108700A75B9A /* AppDelegate.m */,
119119
13B07FB51A68108700A75B9A /* Images.xcassets */,
120120
13B07FB61A68108700A75B9A /* Info.plist */,
121121
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
@@ -494,8 +494,8 @@
494494
isa = PBXSourcesBuildPhase;
495495
buildActionMask = 2147483647;
496496
files = (
497-
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
498497
13B07FC11A68108700A75B9A /* main.m in Sources */,
498+
0E8817ED29D74E5D004363C7 /* AppDelegate.mm in Sources */,
499499
92E8344C25E25EBE00B0304C /* Bridge.swift in Sources */,
500500
);
501501
runOnlyForDeploymentPostprocessing = 0;
@@ -504,8 +504,8 @@
504504
isa = PBXSourcesBuildPhase;
505505
buildActionMask = 2147483647;
506506
files = (
507+
0E8817EE29D74E5D004363C7 /* AppDelegate.mm in Sources */,
507508
2D02E4BF1E0B4AB3006451C7 /* main.m in Sources */,
508-
2D02E4BC1E0B4A80006451C7 /* AppDelegate.m in Sources */,
509509
);
510510
runOnlyForDeploymentPostprocessing = 0;
511511
};

example/ios/MultipleImagePickerExample/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
<key>CFBundlePackageType</key>
2222
<string>APPL</string>
2323
<key>CFBundleShortVersionString</key>
24-
<string>$(MARKETING_VERSION)</string>
24+
<string>1.0</string>
2525
<key>CFBundleSignature</key>
2626
<string>????</string>
2727
<key>CFBundleVersion</key>
28-
<string>$(CURRENT_PROJECT_VERSION)</string>
28+
<string>1</string>
2929
<key>LSRequiresIPhoneOS</key>
3030
<true/>
3131
<key>NSAppTransportSecurity</key>

example/src/App.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,28 @@ import { SafeAreaView } from 'react-native';
1010

1111
import { StyleSheet } from 'react-native';
1212
import ImageGrid from '@baronha/react-native-image-grid';
13-
import ImagePicker from '@baronha/react-native-multiple-image-picker';
13+
import { openPicker } from '@baronha/react-native-multiple-image-picker';
1414

1515
const { width } = Dimensions.get('window');
1616

1717
export default function App() {
1818
const [images, setImages] = useState([]);
19+
1920
const onPressImage = (item, index) => {
2021
console.log(item, index);
2122
};
2223

23-
const openPicker = async () => {
24+
const onPicker = async () => {
2425
try {
25-
const response = await ImagePicker.openPicker({
26+
const response = await openPicker({
2627
selectedAssets: images,
2728
isExportThumbnail: true,
2829
maxVideo: 1,
30+
singleSelectedMode: true,
31+
isCrop: true,
2932
});
30-
console.log(response);
31-
setImages(response);
33+
// console.log(response);
34+
// setImages(response);
3235
} catch (e) {}
3336
};
3437

@@ -47,7 +50,7 @@ export default function App() {
4750
conditionCheckVideo={'video'}
4851
videoURLKey={'thumbnail'}
4952
/>
50-
<TouchableOpacity style={style.buttonOpen} onPress={openPicker}>
53+
<TouchableOpacity style={style.buttonOpen} onPress={onPicker}>
5154
<Text style={style.textOpen}>Open Gallery</Text>
5255
</TouchableOpacity>
5356
</View>

ios/CropImageController.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// CropImageController.swift
3+
// react-native-multiple-image-picker
4+
//
5+
// Created by Donquijote on 01/04/2023.
6+
//
7+
8+
import Foundation

ios/MultipleImagePicker.swift

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import UIKit
22
import TLPhotoPicker
33
import Photos
4+
import CropViewController
45

56
var MultipleImagePickerConfigure = TLPhotosPickerConfigure();
67

78
@objc(MultipleImagePicker)
8-
class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavigationControllerDelegate, TLPhotosPickerLogDelegate {
9+
class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavigationControllerDelegate, TLPhotosPickerLogDelegate, CropViewControllerDelegate {
910

1011
@objc static func requiresMainQueueSetup() -> Bool {
1112
return false
@@ -123,8 +124,6 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
123124
let assetsExist = selecteds.filter{ ($0 as! NSObject).value(forKey: "localIdentifier") != nil }
124125
videoCount = selecteds.filter{ ($0 as! NSObject).value(forKey: "type") as? String == "video" }.count
125126

126-
print("assets", assetsExist.count)
127-
print("self.selectedAssets.count", self.selectedAssets)
128127
if(assetsExist.count != self.selectedAssets.count){
129128
var assets = [TLPHAsset]();
130129
for index in 0..<assetsExist.count {
@@ -229,13 +228,24 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
229228
}
230229
}
231230

231+
func cropViewController(_ cropViewController: CropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle: Int) {
232+
233+
}
234+
235+
func presentCropViewController(image: UIImage) {
236+
let cropViewController = CropViewController(image: image)
237+
cropViewController.delegate = self
238+
self.getTopMostViewController()?.present(cropViewController, animated: true, completion: nil)
239+
}
240+
232241
func dismissPhotoPicker(withTLPHAssets: [TLPHAsset]) {
233242
if(withTLPHAssets.count == 0){
234243
self.resolve([]);
235244
dismissComplete()
236245
return;
237246
}
238-
let withTLPHAssetsCount = withTLPHAssets.count;
247+
248+
let withTLPHAssetsCount = withTLPHAssets.count;
239249
let selectedAssetsCount = self.selectedAssets.count;
240250

241251
//check difference
@@ -262,16 +272,20 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
262272
let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
263273

264274
let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
275+
265276
loadingIndicator.hidesWhenStopped = true
266277
loadingIndicator.style = UIActivityIndicatorView.Style.gray
278+
267279
if #available(iOS 13.0, *) {
268280
loadingIndicator.color = .secondaryLabel
269281
} else {
270282
loadingIndicator.color = .black
271283
}
284+
272285
loadingIndicator.startAnimating();
273286

274287
alert.view.addSubview(loadingIndicator)
288+
275289
self.getTopMostViewController()?.present(alert, animated: true, completion: {
276290
let group = DispatchGroup()
277291
for TLAsset in withTLPHAssets {
@@ -294,11 +308,20 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
294308
group.leave();
295309
})
296310
}
311+
297312
group.notify(queue: .main){ [self] in
298313
resolve(selections);
299314
DispatchQueue.main.async {
300315
alert.dismiss(animated: true, completion: {
301-
dismissComplete()
316+
if((self.options["singleSelectedMode"] as! Bool) && (self.options["isCrop"] as! Bool)){
317+
let image = withTLPHAssets.first?.fullResolutionImage
318+
319+
if(image != nil){
320+
self.presentCropViewController(image: image!)
321+
return;
322+
}
323+
}
324+
self.dismissComplete()
302325
})
303326
}
304327
}
@@ -322,7 +345,6 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
322345
func canSelectAsset(phAsset: PHAsset) -> Bool {
323346
let maxVideo = self.options["maxVideo"]
324347
if(phAsset.mediaType == .video){
325-
326348
if(videoCount == maxVideo as! Int && !(options["singleSelectedMode"] as! Bool)){
327349
showExceededMaximumAlert(vc: self.getTopMostViewController()!, isVideo: true)
328350
return false

src/index.js

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,30 @@ let defaultOptions = {
5151
singleSelectedMode: false,
5252
isCrop: false,
5353
isCropCircle: false,
54-
//****//
55-
56-
// fetchOption: Object,
57-
// fetchCollectionOption: Object,
58-
59-
// emptyImage: Image,
6054
};
6155

62-
exportObject = {
63-
openPicker: (optionsPicker) => {
64-
const options = {
65-
...defaultOptions,
66-
...optionsPicker,
67-
};
68-
const isSingle = options?.singleSelectedMode ?? false;
69-
if (isSingle) options.selectedAssets = [];
56+
export const openPicker = (optionsPicker) => {
57+
const options = {
58+
...defaultOptions,
59+
...optionsPicker,
60+
};
61+
const isSingle = options?.singleSelectedMode ?? false;
62+
if (isSingle) options.selectedAssets = [];
7063

71-
return new Promise(async (resolve, reject) => {
72-
try {
73-
const response = await MultipleImagePicker.openPicker(options);
74-
// console.log('res', response);
75-
if (response?.length) {
76-
if (isSingle) {
77-
resolve(response[0]);
78-
}
79-
resolve(response);
80-
return;
64+
return new Promise(async (resolve, reject) => {
65+
try {
66+
const response = await MultipleImagePicker.openPicker(options);
67+
// console.log('res', response);
68+
if (response?.length) {
69+
if (isSingle) {
70+
resolve(response[0]);
8171
}
82-
resolve([]);
83-
} catch (e) {
84-
reject(e);
72+
resolve(response);
73+
return;
8574
}
86-
});
87-
},
75+
resolve([]);
76+
} catch (e) {
77+
reject(e);
78+
}
79+
});
8880
};
89-
90-
export default exportObject;

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-
"react-native-multiple-image-picker": ["./src/index"]
5+
"@baronha/react-native-multiple-image-picker": ["./src"]
66
},
77
"allowUnreachableCode": false,
88
"allowUnusedLabels": false,

0 commit comments

Comments
 (0)