From caadd01b136ce7335837b3aae79ce4f3d0598a6d Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Wed, 8 Dec 2021 12:19:41 +0900 Subject: [PATCH 1/9] implemented ImagePreviewViewController. --- NohanaImagePicker.xcodeproj/project.pbxproj | 4 ++ .../ImagePreviewViewController.swift | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 NohanaImagePicker/ImagePreviewViewController.swift diff --git a/NohanaImagePicker.xcodeproj/project.pbxproj b/NohanaImagePicker.xcodeproj/project.pbxproj index b91be97..0803c9c 100644 --- a/NohanaImagePicker.xcodeproj/project.pbxproj +++ b/NohanaImagePicker.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 3569CAA91EC1918E000C41C0 /* NohanaImagePicker.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3569CAA61EC1918E000C41C0 /* NohanaImagePicker.xcassets */; }; + 6ACE6617276051F6008AA84D /* ImagePreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ACE6616276051F6008AA84D /* ImagePreviewViewController.swift */; }; F117F732273B6A2600E11BC7 /* AssetDateSectionCreater.swift in Sources */ = {isa = PBXBuildFile; fileRef = F117F731273B6A2600E11BC7 /* AssetDateSectionCreater.swift */; }; F181095026A5361A001C2BDE /* MomentDetailListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F181094F26A5361A001C2BDE /* MomentDetailListViewController.swift */; }; F1A26CCD2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F1A26CCC2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard */; }; @@ -82,6 +83,7 @@ 23D1CD93207CEB1200F8115E /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/NohanaImagePicker.strings; sourceTree = ""; }; 3569CAA61EC1918E000C41C0 /* NohanaImagePicker.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = NohanaImagePicker.xcassets; sourceTree = ""; }; 3590F1F51EC1A79400F32E06 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/NohanaImagePicker.strings; sourceTree = ""; }; + 6ACE6616276051F6008AA84D /* ImagePreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePreviewViewController.swift; sourceTree = ""; }; F117F731273B6A2600E11BC7 /* AssetDateSectionCreater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetDateSectionCreater.swift; sourceTree = ""; }; F181094F26A5361A001C2BDE /* MomentDetailListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MomentDetailListViewController.swift; sourceTree = ""; }; F1A26CCC2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AssetListSelectableDateSection.storyboard; sourceTree = ""; }; @@ -287,6 +289,7 @@ F181094F26A5361A001C2BDE /* MomentDetailListViewController.swift */, F1E5DE7C26A57F0B004B9EDE /* DetailListViewControllerProtocol.swift */, F1A26CCE2738E7E400433E9F /* AssetListSelectableDateSectionController.swift */, + 6ACE6616276051F6008AA84D /* ImagePreviewViewController.swift */, ); name = ViewControllers; sourceTree = ""; @@ -454,6 +457,7 @@ F218D7D61C6B3D22001FCED1 /* PhotoKitAlbumList.swift in Sources */, F24EB6901C68AEED0002EC86 /* AlbumListViewController.swift in Sources */, F28F4AC31C6C49EE00B7D725 /* PhotoKitAssetList.swift in Sources */, + 6ACE6617276051F6008AA84D /* ImagePreviewViewController.swift in Sources */, F26775EA1C71645A002E786C /* ContractingAnimationController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/NohanaImagePicker/ImagePreviewViewController.swift b/NohanaImagePicker/ImagePreviewViewController.swift new file mode 100644 index 0000000..b80794a --- /dev/null +++ b/NohanaImagePicker/ImagePreviewViewController.swift @@ -0,0 +1,40 @@ +// +// ImagePreviewViewController.swift +// NohanaImagePicker +// +// Created by atsushi.yoshimoto on 2021/12/08. +// Copyright © 2021 nohana. All rights reserved. +// + +import UIKit + +class ImagePreviewViewController: UIViewController { + + private let imageView: UIImageView = { + let imageView = UIImageView() + imageView.clipsToBounds = true + imageView.contentMode = .scaleAspectFit + return imageView + }() + + init(asset: PhotoKitAsset) { + super.init(nibName: nil, bundle: nil) + + asset.image(targetSize: UIScreen.main.bounds.size) { [weak self] (imageData) -> Void in + guard let self = self else { return } + DispatchQueue.main.async { + if let imageData = imageData { + self.imageView.image = imageData.image + } + } + } + } + + override func loadView() { + view = imageView + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} From 7b5a1e8e52309316dfab46267285ed6ae9d03937 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Wed, 8 Dec 2021 12:23:33 +0900 Subject: [PATCH 2/9] Added segue identifier. --- .../AssetListSelectableDateSection.storyboard | 6 +++--- NohanaImagePicker/NohanaImagePicker.storyboard | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSection.storyboard b/NohanaImagePicker/AssetListSelectableDateSection.storyboard index d950361..882e71e 100644 --- a/NohanaImagePicker/AssetListSelectableDateSection.storyboard +++ b/NohanaImagePicker/AssetListSelectableDateSection.storyboard @@ -1,9 +1,9 @@ - + - + @@ -65,7 +65,7 @@ - + diff --git a/NohanaImagePicker/NohanaImagePicker.storyboard b/NohanaImagePicker/NohanaImagePicker.storyboard index ff9f532..b795557 100644 --- a/NohanaImagePicker/NohanaImagePicker.storyboard +++ b/NohanaImagePicker/NohanaImagePicker.storyboard @@ -17,7 +17,7 @@ - + @@ -52,7 +52,7 @@ - + @@ -162,7 +162,7 @@ - + @@ -393,7 +393,7 @@ - + @@ -550,6 +550,6 @@ - + From 783edddff0a5097329bd3c01b8a8a52b822356cf Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Wed, 8 Dec 2021 12:35:02 +0900 Subject: [PATCH 3/9] Implemented to show the context menu. --- ...tListSelectableDateSectionController.swift | 45 +++++++++++++++++++ .../AssetListViewController.swift | 45 +++++++++++++++++++ NohanaImagePicker/MomentViewController.swift | 45 +++++++++++++++++++ 3 files changed, 135 insertions(+) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index a11096a..878890d 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -163,6 +163,51 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: dateSectionList[indexPath.section].assetResult[indexPath.row]) } } + + @available(iOS 13.0, *) + override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { + let asset = PhotoKitAsset(asset: dateSectionList[indexPath.section].assetResult[indexPath.row]) + if let cell = collectionView.cellForItem(at: indexPath) as? AssetCell, let nohanaImagePickerController = self.nohanaImagePickerController { + return UIContextMenuConfiguration(identifier: indexPath as NSCopying, previewProvider: { [weak self] in + // Create a preview view controller and return it + guard let self = self else { return nil } + let previewViewController = ImagePreviewViewController(asset: asset) + let imageSize = cell.imageView.image?.size ?? .zero + let width = self.view.bounds.width + let height = imageSize.height * (width / imageSize.width) + let contentSize = CGSize(width: width, height: height) + previewViewController.preferredContentSize = contentSize + return previewViewController + }, actionProvider: { _ in + if nohanaImagePickerController.pickedAssetList.isPicked(asset) { + let deselect = UIAction(title: "選択を外す", image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in + nohanaImagePickerController.dropAsset(asset) + collectionView.reloadItems(at: [indexPath]) + } + return UIMenu(title: "", children: [deselect]) + } else { + let select = UIAction(title: "選択する", image: UIImage(systemName: "checkmark.circle")) { _ in + nohanaImagePickerController.pickAsset(asset) + collectionView.reloadItems(at: [indexPath]) + } + return UIMenu(title: "", children: [select]) + } + }) + } else { + return nil + } + } + + @available(iOS 13.0, *) + override func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) { + animator.addCompletion { [weak self] in + guard let self = self else { return } + if let indexPath = configuration.identifier as? IndexPath { + collectionView.selectItem(at: indexPath, animated: false, scrollPosition: []) + self.performSegue(withIdentifier: "toAssetDetailListViewController", sender: nil) + } + } + } // MARK: - Storyboard diff --git a/NohanaImagePicker/AssetListViewController.swift b/NohanaImagePicker/AssetListViewController.swift index 8b71c3a..8e87616 100644 --- a/NohanaImagePicker/AssetListViewController.swift +++ b/NohanaImagePicker/AssetListViewController.swift @@ -108,6 +108,51 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: photoKitAssetList[indexPath.item].originalAsset) } } + + @available(iOS 13.0, *) + override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { + let asset = photoKitAssetList[indexPath.item] + if let cell = collectionView.cellForItem(at: indexPath) as? AssetCell, let nohanaImagePickerController = self.nohanaImagePickerController { + return UIContextMenuConfiguration(identifier: indexPath as NSCopying, previewProvider: { [weak self] in + // Create a preview view controller and return it + guard let self = self else { return nil } + let previewViewController = ImagePreviewViewController(asset: asset) + let imageSize = cell.imageView.image?.size ?? .zero + let width = self.view.bounds.width + let height = imageSize.height * (width / imageSize.width) + let contentSize = CGSize(width: width, height: height) + previewViewController.preferredContentSize = contentSize + return previewViewController + }, actionProvider: { _ in + if nohanaImagePickerController.pickedAssetList.isPicked(asset) { + let deselect = UIAction(title: "選択を外す", image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in + nohanaImagePickerController.dropAsset(asset) + collectionView.reloadItems(at: [indexPath]) + } + return UIMenu(title: "", children: [deselect]) + } else { + let select = UIAction(title: "選択する", image: UIImage(systemName: "checkmark.circle")) { _ in + nohanaImagePickerController.pickAsset(asset) + collectionView.reloadItems(at: [indexPath]) + } + return UIMenu(title: "", children: [select]) + } + }) + } else { + return nil + } + } + + @available(iOS 13.0, *) + override func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) { + animator.addCompletion { [weak self] in + guard let self = self else { return } + if let indexPath = configuration.identifier as? IndexPath { + collectionView.selectItem(at: indexPath, animated: false, scrollPosition: []) + self.performSegue(withIdentifier: "toAssetDetailListViewController", sender: nil) + } + } + } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell, diff --git a/NohanaImagePicker/MomentViewController.swift b/NohanaImagePicker/MomentViewController.swift index 4dfc2b5..fcda582 100644 --- a/NohanaImagePicker/MomentViewController.swift +++ b/NohanaImagePicker/MomentViewController.swift @@ -180,6 +180,51 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: momentInfoSectionList[indexPath.section].assetResult[indexPath.row]) } } + + @available(iOS 13.0, *) + override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { + let asset = PhotoKitAsset(asset: momentInfoSectionList[indexPath.section].assetResult[indexPath.row]) + if let cell = collectionView.cellForItem(at: indexPath) as? AssetCell, let nohanaImagePickerController = self.nohanaImagePickerController { + return UIContextMenuConfiguration(identifier: indexPath as NSCopying, previewProvider: { [weak self] in + // Create a preview view controller and return it + guard let self = self else { return nil } + let previewViewController = ImagePreviewViewController(asset: asset) + let imageSize = cell.imageView.image?.size ?? .zero + let width = self.view.bounds.width + let height = imageSize.height * (width / imageSize.width) + let contentSize = CGSize(width: width, height: height) + previewViewController.preferredContentSize = contentSize + return previewViewController + }, actionProvider: { _ in + if nohanaImagePickerController.pickedAssetList.isPicked(asset) { + let deselect = UIAction(title: "選択を外す", image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in + nohanaImagePickerController.dropAsset(asset) + collectionView.reloadItems(at: [indexPath]) + } + return UIMenu(title: "", children: [deselect]) + } else { + let select = UIAction(title: "選択する", image: UIImage(systemName: "checkmark.circle")) { _ in + nohanaImagePickerController.pickAsset(asset) + collectionView.reloadItems(at: [indexPath]) + } + return UIMenu(title: "", children: [select]) + } + }) + } else { + return nil + } + } + + @available(iOS 13.0, *) + override func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) { + animator.addCompletion { [weak self] in + guard let self = self else { return } + if let indexPath = configuration.identifier as? IndexPath { + collectionView.selectItem(at: indexPath, animated: false, scrollPosition: []) + self.performSegue(withIdentifier: "toMomentDetailListViewController", sender: nil) + } + } + } // MARK: - Storyboard From e1941c0e9e23721ffa52b8e95f33a351d5500d76 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Wed, 8 Dec 2021 14:22:28 +0900 Subject: [PATCH 4/9] Fixed copyright and license. --- .../ImagePreviewViewController.swift | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/NohanaImagePicker/ImagePreviewViewController.swift b/NohanaImagePicker/ImagePreviewViewController.swift index b80794a..b195133 100644 --- a/NohanaImagePicker/ImagePreviewViewController.swift +++ b/NohanaImagePicker/ImagePreviewViewController.swift @@ -1,10 +1,18 @@ -// -// ImagePreviewViewController.swift -// NohanaImagePicker -// -// Created by atsushi.yoshimoto on 2021/12/08. -// Copyright © 2021 nohana. All rights reserved. -// +/* + * Copyright (C) 2021 nohana, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import UIKit From 9b2e5dbb675cf2d8a3b7c84ebb14dfc2fa4c8937 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Wed, 8 Dec 2021 14:35:30 +0900 Subject: [PATCH 5/9] Updated localize text. --- NohanaImagePicker/de.lproj/NohanaImagePicker.strings | 2 ++ NohanaImagePicker/en.lproj/NohanaImagePicker.strings | 2 ++ NohanaImagePicker/ja.lproj/NohanaImagePicker.strings | 2 ++ NohanaImagePicker/ru.lproj/NohanaImagePicker.strings | 2 ++ 4 files changed, 8 insertions(+) diff --git a/NohanaImagePicker/de.lproj/NohanaImagePicker.strings b/NohanaImagePicker/de.lproj/NohanaImagePicker.strings index 2150174..0347625 100644 --- a/NohanaImagePicker/de.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/de.lproj/NohanaImagePicker.strings @@ -20,3 +20,5 @@ "albumlist.moment.title" = "Moment"; "toolbar.title.nolimit" = "Ausgewählte Fotos: %ld"; "toolbar.title.haslimit" = "Ausgewählte Fotos: %ld / %ld"; +"action.title.select" = "Auswählen"; +"action.title.deselect" = "Abwählen"; diff --git a/NohanaImagePicker/en.lproj/NohanaImagePicker.strings b/NohanaImagePicker/en.lproj/NohanaImagePicker.strings index c605d60..d986642 100644 --- a/NohanaImagePicker/en.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/en.lproj/NohanaImagePicker.strings @@ -20,3 +20,5 @@ "albumlist.moment.title" = "Moment"; "toolbar.title.nolimit" = "Selected Items: %ld"; "toolbar.title.haslimit" = "Selected Items: %ld / %ld"; +"action.title.select" = "Select"; +"action.title.deselect" = "Deselect"; diff --git a/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings b/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings index af4b69a..fa8ac94 100644 --- a/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings @@ -20,3 +20,5 @@ "albumlist.moment.title" = "日付から選択"; "toolbar.title.nolimit" = "%ld枚選択中"; "toolbar.title.haslimit" = "%ld枚選択中(最大%ld枚)"; +"action.title.select" = "選択する"; +"action.title.deselect" = "選択を外す"; diff --git a/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings b/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings index f882602..a36bb98 100644 --- a/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings @@ -20,3 +20,5 @@ "albumlist.moment.title" = "Моменты"; "toolbar.title.nolimit" = "Выбрано: %ld"; "toolbar.title.haslimit" = "Выбрано: %ld / %ld"; +"action.title.select" = "Выбирать"; +"action.title.deselect" = "Отменить выбор"; From 5a990c31d9454b93f37f0b02aa39230f8eeeaa3f Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Wed, 8 Dec 2021 14:35:47 +0900 Subject: [PATCH 6/9] Fixed action title. --- .../AssetListSelectableDateSectionController.swift | 6 ++++-- NohanaImagePicker/AssetListViewController.swift | 6 ++++-- NohanaImagePicker/MomentViewController.swift | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 878890d..27388fb 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -180,13 +180,15 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo return previewViewController }, actionProvider: { _ in if nohanaImagePickerController.pickedAssetList.isPicked(asset) { - let deselect = UIAction(title: "選択を外す", image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in + let title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.deselect", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") + let deselect = UIAction(title: title, image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in nohanaImagePickerController.dropAsset(asset) collectionView.reloadItems(at: [indexPath]) } return UIMenu(title: "", children: [deselect]) } else { - let select = UIAction(title: "選択する", image: UIImage(systemName: "checkmark.circle")) { _ in + let title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.select", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") + let select = UIAction(title: title, image: UIImage(systemName: "checkmark.circle")) { _ in nohanaImagePickerController.pickAsset(asset) collectionView.reloadItems(at: [indexPath]) } diff --git a/NohanaImagePicker/AssetListViewController.swift b/NohanaImagePicker/AssetListViewController.swift index 8e87616..5bcdd89 100644 --- a/NohanaImagePicker/AssetListViewController.swift +++ b/NohanaImagePicker/AssetListViewController.swift @@ -125,13 +125,15 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg return previewViewController }, actionProvider: { _ in if nohanaImagePickerController.pickedAssetList.isPicked(asset) { - let deselect = UIAction(title: "選択を外す", image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in + let title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.deselect", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") + let deselect = UIAction(title: title, image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in nohanaImagePickerController.dropAsset(asset) collectionView.reloadItems(at: [indexPath]) } return UIMenu(title: "", children: [deselect]) } else { - let select = UIAction(title: "選択する", image: UIImage(systemName: "checkmark.circle")) { _ in + let title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.select", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") + let select = UIAction(title: title, image: UIImage(systemName: "checkmark.circle")) { _ in nohanaImagePickerController.pickAsset(asset) collectionView.reloadItems(at: [indexPath]) } diff --git a/NohanaImagePicker/MomentViewController.swift b/NohanaImagePicker/MomentViewController.swift index fcda582..0b0b62e 100644 --- a/NohanaImagePicker/MomentViewController.swift +++ b/NohanaImagePicker/MomentViewController.swift @@ -197,13 +197,15 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe return previewViewController }, actionProvider: { _ in if nohanaImagePickerController.pickedAssetList.isPicked(asset) { - let deselect = UIAction(title: "選択を外す", image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in + let title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.deselect", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") + let deselect = UIAction(title: title, image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in nohanaImagePickerController.dropAsset(asset) collectionView.reloadItems(at: [indexPath]) } return UIMenu(title: "", children: [deselect]) } else { - let select = UIAction(title: "選択する", image: UIImage(systemName: "checkmark.circle")) { _ in + let title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.select", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") + let select = UIAction(title: title, image: UIImage(systemName: "checkmark.circle")) { _ in nohanaImagePickerController.pickAsset(asset) collectionView.reloadItems(at: [indexPath]) } From 20ea11b09cbdcb6eb9bea4de3f11dce609a607b2 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Wed, 8 Dec 2021 15:28:50 +0900 Subject: [PATCH 7/9] Added weak self. --- NohanaImagePicker/ImagePreviewViewController.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/NohanaImagePicker/ImagePreviewViewController.swift b/NohanaImagePicker/ImagePreviewViewController.swift index b195133..3a5a6f4 100644 --- a/NohanaImagePicker/ImagePreviewViewController.swift +++ b/NohanaImagePicker/ImagePreviewViewController.swift @@ -29,11 +29,9 @@ class ImagePreviewViewController: UIViewController { super.init(nibName: nil, bundle: nil) asset.image(targetSize: UIScreen.main.bounds.size) { [weak self] (imageData) -> Void in - guard let self = self else { return } - DispatchQueue.main.async { - if let imageData = imageData { - self.imageView.image = imageData.image - } + guard let self = self, let imageData = imageData else { return } + DispatchQueue.main.async { [weak self] in + self?.imageView.image = imageData.image } } } From 242cbfff3a16b420e19acd6640eb7974c60c84aa Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Wed, 8 Dec 2021 15:34:13 +0900 Subject: [PATCH 8/9] Fixed preferredContentSize. --- NohanaImagePicker/ImagePreviewViewController.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/NohanaImagePicker/ImagePreviewViewController.swift b/NohanaImagePicker/ImagePreviewViewController.swift index 3a5a6f4..2198de6 100644 --- a/NohanaImagePicker/ImagePreviewViewController.swift +++ b/NohanaImagePicker/ImagePreviewViewController.swift @@ -29,9 +29,14 @@ class ImagePreviewViewController: UIViewController { super.init(nibName: nil, bundle: nil) asset.image(targetSize: UIScreen.main.bounds.size) { [weak self] (imageData) -> Void in - guard let self = self, let imageData = imageData else { return } + guard let self = self, let image = imageData?.image else { return } DispatchQueue.main.async { [weak self] in - self?.imageView.image = imageData.image + guard let self = self else { return } + self.imageView.image = image + let width = UIScreen.main.bounds.size.width + let height = image.size.height * (width / image.size.width) + let contentSize = CGSize(width: width, height: height) + self.preferredContentSize = contentSize } } } From 564d7f235f9e1951a46670b693a46fa6af348504 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Fri, 17 Dec 2021 11:32:36 +0900 Subject: [PATCH 9/9] Fixed reload sections when selected photos. --- .../AssetListSelectableDateSectionController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 27388fb..55a8f9e 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -183,14 +183,14 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo let title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.deselect", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") let deselect = UIAction(title: title, image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in nohanaImagePickerController.dropAsset(asset) - collectionView.reloadItems(at: [indexPath]) + collectionView.reloadSections(IndexSet(integer: indexPath.section)) } return UIMenu(title: "", children: [deselect]) } else { let title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.select", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") let select = UIAction(title: title, image: UIImage(systemName: "checkmark.circle")) { _ in nohanaImagePickerController.pickAsset(asset) - collectionView.reloadItems(at: [indexPath]) + collectionView.reloadSections(IndexSet(integer: indexPath.section)) } return UIMenu(title: "", children: [select]) }