Skip to content

Commit

Permalink
Merge pull request #130 from nohana/release/0.9.7
Browse files Browse the repository at this point in the history
0.9.7
  • Loading branch information
a2444mo10 authored Dec 22, 2021
2 parents 10e97c2 + 0cd268c commit 08ef3be
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NohanaImagePicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -82,6 +83,7 @@
23D1CD93207CEB1200F8115E /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/NohanaImagePicker.strings; sourceTree = "<group>"; };
3569CAA61EC1918E000C41C0 /* NohanaImagePicker.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = NohanaImagePicker.xcassets; sourceTree = "<group>"; };
3590F1F51EC1A79400F32E06 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/NohanaImagePicker.strings; sourceTree = "<group>"; };
6ACE6616276051F6008AA84D /* ImagePreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePreviewViewController.swift; sourceTree = "<group>"; };
F117F731273B6A2600E11BC7 /* AssetDateSectionCreater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetDateSectionCreater.swift; sourceTree = "<group>"; };
F181094F26A5361A001C2BDE /* MomentDetailListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MomentDetailListViewController.swift; sourceTree = "<group>"; };
F1A26CCC2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AssetListSelectableDateSection.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -287,6 +289,7 @@
F181094F26A5361A001C2BDE /* MomentDetailListViewController.swift */,
F1E5DE7C26A57F0B004B9EDE /* DetailListViewControllerProtocol.swift */,
F1A26CCE2738E7E400433E9F /* AssetListSelectableDateSectionController.swift */,
6ACE6616276051F6008AA84D /* ImagePreviewViewController.swift */,
);
name = ViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions NohanaImagePicker/AssetListSelectableDateSection.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Y8D-wX-eXv">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Y8D-wX-eXv">
<device id="retina6_5" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -65,7 +65,7 @@
<outlet property="imageView" destination="gBL-Tw-h3e" id="3MR-ED-vnu"/>
<outlet property="overlayView" destination="7pN-6U-K6c" id="iAv-Uk-1Kx"/>
<outlet property="pickButton" destination="byV-w7-CIM" id="t52-nd-9qH"/>
<segue destination="kYg-Jb-RU3" kind="show" id="UZz-4U-64b"/>
<segue destination="kYg-Jb-RU3" kind="show" identifier="toAssetDetailListViewController" id="UZz-4U-64b"/>
</connections>
</collectionViewCell>
</cells>
Expand Down
47 changes: 47 additions & 0 deletions NohanaImagePicker/AssetListSelectableDateSectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,53 @@ 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 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.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.reloadSections(IndexSet(integer: indexPath.section))
}
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

Expand Down
47 changes: 47 additions & 0 deletions NohanaImagePicker/AssetListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,53 @@ 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 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 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])
}
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,
Expand Down
51 changes: 51 additions & 0 deletions NohanaImagePicker/ImagePreviewViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 &quot;AS IS&quot; 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

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, let image = imageData?.image else { return }
DispatchQueue.main.async { [weak self] in
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
}
}
}

override func loadView() {
view = imageView
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
47 changes: 47 additions & 0 deletions NohanaImagePicker/MomentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,53 @@ 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 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 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])
}
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

Expand Down
Loading

0 comments on commit 08ef3be

Please sign in to comment.