Skip to content

Commit c111737

Browse files
committed
Handle product images from WP media picker and device library before committing and dismissing the product images screen.
1 parent 87808ae commit c111737

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

WooCommerce/Classes/ViewRelated/Products/Media/ProductImagesViewController.swift

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -228,21 +228,16 @@ private extension ProductImagesViewController {
228228
//
229229
private extension ProductImagesViewController {
230230
func onDeviceMediaLibraryPickerCompletion(assets: [PHAsset]) {
231-
let shouldCommitChanges = assets.isNotEmpty
232-
defer {
233-
dismiss(animated: !shouldCommitChanges) { [weak self] in
234-
guard shouldCommitChanges else {
235-
return
236-
}
237-
238-
self?.commitAndDismiss()
231+
let shouldAnimateMediaLibraryDismissal = assets.isEmpty
232+
dismiss(animated: shouldAnimateMediaLibraryDismissal) { [weak self] in
233+
guard let self = self, assets.isNotEmpty else {
234+
return
239235
}
240-
}
241-
guard assets.isEmpty == false else {
242-
return
243-
}
244-
assets.forEach { asset in
245-
uploadMediaAssetToSiteMediaLibrary(asset: asset)
236+
237+
assets.forEach { asset in
238+
self.uploadMediaAssetToSiteMediaLibrary(asset: asset)
239+
}
240+
self.commitAndDismiss()
246241
}
247242
}
248243
}
@@ -251,15 +246,15 @@ private extension ProductImagesViewController {
251246
//
252247
private extension ProductImagesViewController {
253248
func onWPMediaPickerCompletion(mediaItems: [Media]) {
254-
let shouldCommitChanges = mediaItems.isNotEmpty
255-
dismiss(animated: !shouldCommitChanges) { [weak self] in
256-
guard shouldCommitChanges else {
249+
let shouldAnimateWPMediaPickerDismissal = mediaItems.isEmpty
250+
dismiss(animated: shouldAnimateWPMediaPickerDismissal) { [weak self] in
251+
guard let self = self, mediaItems.isNotEmpty else {
257252
return
258253
}
259254

260-
self?.commitAndDismiss()
255+
self.productImageActionHandler.addSiteMediaLibraryImagesToProduct(mediaItems: mediaItems)
256+
self.commitAndDismiss()
261257
}
262-
productImageActionHandler.addSiteMediaLibraryImagesToProduct(mediaItems: mediaItems)
263258
}
264259
}
265260

0 commit comments

Comments
 (0)