@@ -208,11 +208,39 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
208208
209209 func cropViewController( _ cropViewController: CropViewController , didCropToImage image: UIImage , withRect cropRect: CGRect , angle: Int ) {
210210
211+ let TLAsset = self . selectedAssets. first;
212+ let filePath = getImagePathFromUIImage ( uiImage: image, prefix: " crop " )
213+
214+ TLAsset ? . phAsset? . setValue ( image. size. width, forKey: " pixelWidth " )
215+ TLAsset ? . phAsset? . setValue ( image. size. height, forKey: " pixelHeight " )
216+
217+ let object = MediaResponse ( filePath: filePath, mime: " image/jpeg " , withTLAsset: TLAsset!)
218+
219+ if ( object. data != nil ) {
220+ object. data![ " isCrop " ] = true
221+ resolve ( [ object. data] )
222+ } else {
223+ resolve ( [ ] )
224+ }
225+
226+ DispatchQueue . main. async {
227+ self . getTopMostViewController ( ) ? . dismiss ( animated: true , completion: {
228+ self . getTopMostViewController ( ) ? . dismiss ( animated: true , completion: nil )
229+ } )
230+ }
231+ //
232+ // self.dismissComplete()
233+ // self.dismissComplete()
211234 }
212235
213236 func presentCropViewController( image: UIImage ) {
214237 let cropViewController = CropViewController ( image: image)
215238 cropViewController. delegate = self
239+ cropViewController. doneButtonTitle = MultipleImagePickerConfigure . doneTitle
240+ cropViewController. doneButtonColor = MultipleImagePickerConfigure . selectedColor
241+
242+ cropViewController. cancelButtonTitle = MultipleImagePickerConfigure . cancelTitle
243+
216244 self . getTopMostViewController ( ) ? . present ( cropViewController, animated: true , completion: nil )
217245 }
218246
@@ -237,23 +265,34 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
237265 return ;
238266 }
239267
240- // count
268+ // define count
241269 let withTLPHAssetsCount = withTLPHAssets. count;
242270 let selectedAssetsCount = self . selectedAssets. count;
243271
272+ // check logic code for isCrop
273+ let cropCondition = ( options [ " singleSelectedMode " ] as! Bool ) && ( options [ " isCrop " ] as! Bool ) && withTLPHAssets. first? . type == . photo
274+
244275 // check difference
245- if ( withTLPHAssetsCount == selectedAssetsCount && withTLPHAssets [ withTLPHAssetsCount - 1 ] . phAsset? . localIdentifier == self . selectedAssets [ selectedAssetsCount- 1 ] . phAsset? . localIdentifier) {
246- // if diff => close
276+ if ( withTLPHAssetsCount == selectedAssetsCount && withTLPHAssets [ withTLPHAssetsCount - 1 ] . phAsset? . localIdentifier == self . selectedAssets [ selectedAssetsCount- 1 ] . phAsset? . localIdentifier && !cropCondition) {
247277 dismissComplete ( )
248278 return ;
249279 }
280+
250281
251- let selections = NSMutableArray . init ( array: withTLPHAssets) ;
252282 self . selectedAssets = withTLPHAssets
253- //imageRequestOptions
254-
255283
256- //add loading view
284+ if ( cropCondition) {
285+ let uiImage = withTLPHAssets. first? . fullResolutionImage
286+ if ( uiImage != nil ) {
287+ presentCropViewController ( image: ( withTLPHAssets. first? . fullResolutionImage) !)
288+ return
289+ }
290+ }
291+
292+
293+ let selections = NSMutableArray . init ( array: withTLPHAssets) ;
294+
295+ // add loading view
257296 let alert = UIAlertController ( title: nil , message: " Please wait... " , preferredStyle: . alert)
258297
259298 let loadingIndicator = UIActivityIndicatorView ( frame: CGRect ( x: 10 , y: 5 , width: 50 , height: 50 ) )
@@ -271,6 +310,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
271310
272311 alert. view. addSubview ( loadingIndicator)
273312
313+ // handle controller
274314 self . getTopMostViewController ( ) ? . present ( alert, animated: true , completion: {
275315
276316 let group = DispatchGroup ( )
0 commit comments