Skip to content

Commit a68db9c

Browse files
committed
Auto commit changes after the user takes a photo or picks photo(s) from device or WP media picker.
1 parent ea22f82 commit a68db9c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,25 @@ private extension ProductImagesViewController {
216216
return
217217
}
218218
uploadMediaAssetToSiteMediaLibrary(asset: asset)
219+
// Commits product image changes automatically.
220+
doneButtonTapped()
219221
}
220222
}
221223

222224
// MARK: Action handling for device media library picker
223225
//
224226
private extension ProductImagesViewController {
225227
func onDeviceMediaLibraryPickerCompletion(assets: [PHAsset]) {
228+
let shouldCommitChanges = assets.isNotEmpty
226229
defer {
227-
dismiss(animated: true, completion: nil)
230+
dismiss(animated: !shouldCommitChanges) { [weak self] in
231+
guard shouldCommitChanges else {
232+
return
233+
}
234+
235+
// Commits product image changes automatically.
236+
self?.doneButtonTapped()
237+
}
228238
}
229239
guard assets.isEmpty == false else {
230240
return
@@ -239,7 +249,15 @@ private extension ProductImagesViewController {
239249
//
240250
private extension ProductImagesViewController {
241251
func onWPMediaPickerCompletion(mediaItems: [Media]) {
242-
dismiss(animated: true, completion: nil)
252+
let shouldCommitChanges = mediaItems.isNotEmpty
253+
dismiss(animated: !shouldCommitChanges) { [weak self] in
254+
guard shouldCommitChanges else {
255+
return
256+
}
257+
258+
// Commits product image changes automatically.
259+
self?.doneButtonTapped()
260+
}
243261
productImageActionHandler.addSiteMediaLibraryImagesToProduct(mediaItems: mediaItems)
244262
}
245263
}

0 commit comments

Comments
 (0)