@@ -49,11 +49,6 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
4949 generator. impactOccurred ( )
5050 }
5151
52- func dismissComplete( ) {
53- DispatchQueue . main. async {
54- self . getTopMostViewController ( ) ? . dismiss ( animated: true , completion: nil )
55- }
56- }
5752
5853 @objc ( openPicker: withResolver: withRejecter: )
5954 func openPicker( options: NSDictionary , resolve: @escaping RCTPromiseResolveBlock , reject: @escaping RCTPromiseRejectBlock ) -> Void {
@@ -67,10 +62,13 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
6762 viewController. configure = MultipleImagePickerConfigure
6863 viewController. selectedAssets = self . selectedAssets
6964 viewController. logDelegate = self
70- viewController . modalTransitionStyle = . coverVertical
71- viewController . modalPresentationStyle = . overCurrentContext
65+
66+ // viewController.navigationBar
7267
7368 DispatchQueue . main. async {
69+ viewController. modalTransitionStyle = . coverVertical
70+ viewController. modalPresentationStyle = . fullScreen
71+
7472 self . getTopMostViewController ( ) ? . present ( viewController, animated: true , completion: nil )
7573 }
7674 }
@@ -124,7 +122,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
124122 videoCount = selecteds. filter { ( $0 as! NSObject ) . value ( forKey: " type " ) as? String == " video " } . count
125123
126124 print ( " assets " , assetsExist. count)
127- print ( " self.selectedAssets.count " , self . selectedAssets. count )
125+ print ( " self.selectedAssets.count " , self . selectedAssets)
128126 if ( assetsExist. count != self . selectedAssets. count) {
129127 var assets = [ TLPHAsset] ( ) ;
130128 for index in 0 ..< assetsExist. count {
@@ -143,7 +141,6 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
143141 }
144142
145143 func createAttachmentResponse( filePath: String ? , withFilename filename: String ? , withType type: String ? , withAsset asset: PHAsset , withTLAsset TLAsset: TLPHAsset ) -> [ AnyHashable : Any ] ? {
146- print ( " asets: " , asset, TLAsset)
147144 var media = [
148145 " path " : " file:// " + filePath! as String ,
149146 " localIdentifier " : asset. localIdentifier,
@@ -152,7 +149,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
152149 " height " : Int ( asset. pixelHeight ) as NSNumber ,
153150 " mime " : type!,
154151 " creationDate " : asset. creationDate!,
155- " type " : asset. mediaType == . video ? " video " : " image "
152+ " type " : asset. mediaType == . video ? " video " : " image " ,
156153 ] as [ String : Any ]
157154
158155 //option in video
@@ -166,6 +163,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
166163 TLAsset . videoSize { Int in
167164 media [ " size " ] = Int
168165 }
166+ media [ " duration " ] = asset. duration
169167 } else {
170168 TLAsset . photoSize { Int in
171169 media [ " size " ] = Int
@@ -209,16 +207,34 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
209207
210208 }
211209
210+ func shouldDismissPhotoPicker( withTLPHAssets: [ TLPHAsset ] ) -> Bool {
211+ return false
212+ }
213+
214+ internal func dismissLoading( ) {
215+ if let vc = self . getTopMostViewController ( ) ? . presentedViewController, vc is UIAlertController {
216+ self . getTopMostViewController ( ) ? . dismiss ( animated: false , completion: nil )
217+ }
218+ }
219+
220+ func dismissComplete( ) {
221+ DispatchQueue . main. async {
222+ self . getTopMostViewController ( ) ? . dismiss ( animated: true , completion: nil )
223+ }
224+ }
225+
212226 func dismissPhotoPicker( withTLPHAssets: [ TLPHAsset ] ) {
213227 if ( withTLPHAssets. count == 0 ) {
214228 self . resolve ( [ ] ) ;
229+ dismissComplete ( )
215230 return ;
216231 }
217232 let withTLPHAssetsCount = withTLPHAssets. count;
218233 let selectedAssetsCount = self . selectedAssets. count;
219234
220235 //check difference
221236 if ( withTLPHAssetsCount == selectedAssetsCount && withTLPHAssets [ withTLPHAssetsCount - 1 ] . phAsset? . localIdentifier == self . selectedAssets [ selectedAssetsCount- 1 ] . phAsset? . localIdentifier) {
237+ dismissComplete ( )
222238 return ;
223239 }
224240
@@ -228,48 +244,66 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
228244 let imageRequestOptions = PHImageRequestOptions ( ) ;
229245 imageRequestOptions. deliveryMode = . fastFormat;
230246 imageRequestOptions. resizeMode = . fast;
247+ imageRequestOptions. isNetworkAccessAllowed = true
248+ imageRequestOptions. isSynchronous = false
231249
250+ let videoRequestOptions = PHVideoRequestOptions . init ( )
251+ videoRequestOptions. version = PHVideoRequestOptionsVersion . current
252+ videoRequestOptions. deliveryMode = PHVideoRequestOptionsDeliveryMode . automatic
253+ videoRequestOptions. isNetworkAccessAllowed = true
232254
233- let group = DispatchGroup ( )
255+ //add loading view
256+ let alert = UIAlertController ( title: nil , message: " Please wait... " , preferredStyle: . alert)
234257
235- for TLAsset in withTLPHAssets {
236- group. enter ( )
237- let asset = TLAsset . phAsset
238- let index = TLAsset . selectedOrder - 1 ;
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)
247-
248- } , completionBlock: { ( filePath, fileType) in
249- let object = NSDictionary ( dictionary: self . createAttachmentResponse (
250- filePath: filePath. absoluteString,
251- withFilename: TLAsset . originalFileName,
252- withType: fileType,
253- withAsset: asset!,
254- withTLAsset: TLAsset
255- ) !) ;
256-
257- selections [ index] = object as Any ;
258- group. leave ( ) ;
259- } )
260- }
261- group. notify ( queue: . main) {
262- self . resolve ( selections) ;
258+ let loadingIndicator = UIActivityIndicatorView ( frame: CGRect ( x: 10 , y: 5 , width: 50 , height: 50 ) )
259+ loadingIndicator. hidesWhenStopped = true
260+ loadingIndicator. style = UIActivityIndicatorView . Style. gray
261+ if #available( iOS 13 . 0 , * ) {
262+ loadingIndicator. color = . secondaryLabel
263+ } else {
264+ loadingIndicator. color = . black
263265 }
266+ loadingIndicator. startAnimating ( ) ;
267+
268+ alert. view. addSubview ( loadingIndicator)
269+ self . getTopMostViewController ( ) ? . present ( alert, animated: true , completion: {
270+ let group = DispatchGroup ( )
271+ for TLAsset in withTLPHAssets {
272+ group. enter ( )
273+ let asset = TLAsset . phAsset
274+ let index = TLAsset . selectedOrder - 1 ;
275+
276+ TLAsset . tempCopyMediaFile ( videoRequestOptions: videoRequestOptions, imageRequestOptions: imageRequestOptions, livePhotoRequestOptions: nil , exportPreset: AVAssetExportPresetHighestQuality, convertLivePhotosToJPG: true , progressBlock: { ( progress) in
277+ print ( " progress: " , progress)
278+ } , completionBlock: { ( filePath, fileType) in
279+ let object = NSDictionary ( dictionary: self . createAttachmentResponse (
280+ filePath: filePath. absoluteString,
281+ withFilename: TLAsset . originalFileName,
282+ withType: fileType,
283+ withAsset: asset!,
284+ withTLAsset: TLAsset
285+ ) !) ;
286+
287+ selections [ index] = object as Any ;
288+ group. leave ( ) ;
289+ } )
290+ }
291+ group. notify ( queue: . main) { [ self ] in
292+ resolve ( selections) ;
293+ DispatchQueue . main. async {
294+ alert. dismiss ( animated: true , completion: {
295+ dismissComplete ( )
296+ } )
297+ }
298+ }
299+ } )
264300 }
265301
266302 func getTopMostViewController( ) -> UIViewController ? {
267303 var topMostViewController = UIApplication . shared. keyWindow? . rootViewController
268-
269304 while let presentedViewController = topMostViewController? . presentedViewController {
270305 topMostViewController = presentedViewController
271306 }
272-
273307 return topMostViewController
274308 }
275309
@@ -282,7 +316,8 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
282316 func canSelectAsset( phAsset: PHAsset ) -> Bool {
283317 let maxVideo = self . options [ " maxVideo " ]
284318 if ( phAsset. mediaType == . video) {
285- if ( videoCount == maxVideo as! Int ) {
319+
320+ if ( videoCount == maxVideo as! Int && !( options [ " singleSelectedMode " ] as! Bool ) ) {
286321 showExceededMaximumAlert ( vc: self . getTopMostViewController ( ) !, isVideo: true )
287322 return false
288323 }
0 commit comments