From c1c1cf7910fbffd208817f766a1196276de37afc Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Fri, 17 Dec 2021 17:22:49 +0900 Subject: [PATCH 01/33] Modified deployment target. --- NohanaImagePicker.xcodeproj/project.pbxproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/NohanaImagePicker.xcodeproj/project.pbxproj b/NohanaImagePicker.xcodeproj/project.pbxproj index 0803c9c..f5fdd9b 100644 --- a/NohanaImagePicker.xcodeproj/project.pbxproj +++ b/NohanaImagePicker.xcodeproj/project.pbxproj @@ -509,7 +509,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Demo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.nohana.NohanaImagePicker.Demo; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -524,7 +524,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Demo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.nohana.NohanaImagePicker.Demo; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -581,7 +581,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -635,7 +635,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -658,7 +658,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = NohanaImagePicker/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.nohana.NohanaImagePicker; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -680,7 +680,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = NohanaImagePicker/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.nohana.NohanaImagePicker; PRODUCT_NAME = "$(TARGET_NAME)"; From 968cb939d3cda3881dcc8ae6823e4bc30ccce34d Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Mon, 20 Dec 2021 21:55:43 +0900 Subject: [PATCH 02/33] Updated project.pbxproj. --- NohanaImagePicker.xcodeproj/project.pbxproj | 4 +++- .../xcschemes/NohanaImagePicker.xcscheme | 24 ++++++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/NohanaImagePicker.xcodeproj/project.pbxproj b/NohanaImagePicker.xcodeproj/project.pbxproj index f5fdd9b..2405c3c 100644 --- a/NohanaImagePicker.xcodeproj/project.pbxproj +++ b/NohanaImagePicker.xcodeproj/project.pbxproj @@ -352,7 +352,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 1000; + LastUpgradeCheck = 1310; ORGANIZATIONNAME = nohana; TargetAttributes = { F208E5501CD7370B00FFC9F6 = { @@ -556,6 +556,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -616,6 +617,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; diff --git a/NohanaImagePicker.xcodeproj/xcshareddata/xcschemes/NohanaImagePicker.xcscheme b/NohanaImagePicker.xcodeproj/xcshareddata/xcschemes/NohanaImagePicker.xcscheme index ecf32c3..0b10667 100644 --- a/NohanaImagePicker.xcodeproj/xcshareddata/xcschemes/NohanaImagePicker.xcscheme +++ b/NohanaImagePicker.xcodeproj/xcshareddata/xcschemes/NohanaImagePicker.xcscheme @@ -1,6 +1,6 @@ + + + + @@ -39,17 +48,6 @@ - - - - - - - - Date: Mon, 20 Dec 2021 21:32:25 +0900 Subject: [PATCH 03/33] Fixed style for UIActivityIndicatorView. --- NohanaImagePicker/AlbumListViewController.swift | 3 ++- .../AssetListSelectableDateSectionController.swift | 3 ++- NohanaImagePicker/MomentViewController.swift | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index e31f9fb..581c299 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -241,7 +241,8 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity var isLoading = true func setUpActivityIndicator() { - activityIndicator = UIActivityIndicatorView(style: .gray) + activityIndicator = UIActivityIndicatorView(style: .medium) + activityIndicator?.color = .gray let screenRect = Size.screenRectWithoutAppBar(self) activityIndicator?.center = CGPoint(x: screenRect.size.width / 2, y: screenRect.size.height / 2) activityIndicator?.startAnimating() diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 55a8f9e..a7bb254 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -146,7 +146,8 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo var isLoading = true func setUpActivityIndicator() { - activityIndicator = UIActivityIndicatorView(style: .gray) + activityIndicator = UIActivityIndicatorView(style: .medium) + activityIndicator?.color = .gray let screenRect = Size.screenRectWithoutAppBar(self) activityIndicator?.center = CGPoint(x: screenRect.size.width / 2, y: screenRect.size.height / 2) activityIndicator?.startAnimating() diff --git a/NohanaImagePicker/MomentViewController.swift b/NohanaImagePicker/MomentViewController.swift index 0b0b62e..290efd6 100644 --- a/NohanaImagePicker/MomentViewController.swift +++ b/NohanaImagePicker/MomentViewController.swift @@ -163,7 +163,8 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe var isLoading = true func setUpActivityIndicator() { - activityIndicator = UIActivityIndicatorView(style: .gray) + activityIndicator = UIActivityIndicatorView(style: .medium) + activityIndicator?.color = .gray let screenRect = Size.screenRectWithoutAppBar(self) activityIndicator?.center = CGPoint(x: screenRect.size.width / 2, y: screenRect.size.height / 2) activityIndicator?.startAnimating() From a761529a7c40267c474c40612176ca6097742f63 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Mon, 20 Dec 2021 21:53:21 +0900 Subject: [PATCH 04/33] Fixed warnings. --- NohanaImagePicker.xcodeproj/project.pbxproj | 12 ++++++ ...tListSelectableDateSectionController.swift | 2 +- .../AssetListViewController.swift | 2 +- NohanaImagePicker/MomentViewController.swift | 2 +- NohanaImagePicker/Size.swift | 4 +- NohanaImagePicker/UIApplication+Ex.swift | 40 +++++++++++++++++++ 6 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 NohanaImagePicker/UIApplication+Ex.swift diff --git a/NohanaImagePicker.xcodeproj/project.pbxproj b/NohanaImagePicker.xcodeproj/project.pbxproj index 2405c3c..8ba688c 100644 --- a/NohanaImagePicker.xcodeproj/project.pbxproj +++ b/NohanaImagePicker.xcodeproj/project.pbxproj @@ -9,6 +9,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 */; }; + 6AD1607F2770B23D00A8B066 /* UIApplication+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.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 */; }; @@ -84,6 +85,7 @@ 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 = ""; }; + 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Ex.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 = ""; }; @@ -160,6 +162,14 @@ path = Resources; sourceTree = ""; }; + 6AD1607D2770B22500A8B066 /* Extension */ = { + isa = PBXGroup; + children = ( + 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.swift */, + ); + name = Extension; + sourceTree = ""; + }; F1E5DE7E26A5831D004B9EDE /* Models */ = { isa = PBXGroup; children = ( @@ -268,6 +278,7 @@ F2C08D771C68651900B00181 /* NohanaImagePicker.h */, F2C08D791C68651900B00181 /* Info.plist */, F26775E61C7073B1002E786C /* Common */, + 6AD1607D2770B22500A8B066 /* Extension */, F23554291C69F38900796DCA /* Photos */, F218D7DC1C6C3A3E001FCED1 /* Views */, F2E508901C68B1770082EF93 /* ViewControllers */, @@ -432,6 +443,7 @@ F26775DE1C701FA7002E786C /* ItemList.swift in Sources */, F23CC89E1CB745C800BCE443 /* ActivityIndicatable.swift in Sources */, F202573C1C7418920069B33A /* PickedAssetList.swift in Sources */, + 6AD1607F2770B23D00A8B066 /* UIApplication+Ex.swift in Sources */, F25C10C21C8ED9BF007453C3 /* MomentViewController.swift in Sources */, F25C69881CA23A0A005935D6 /* MomentCell.swift in Sources */, F2FE1F781C901D9400FDBE7B /* MomentSectionHeaderView.swift in Sources */, diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index a7bb254..b8ef24d 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -28,7 +28,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo return CGSize.zero } var numberOfColumns = nohanaImagePickerController.numberOfColumnsInLandscape - if UIApplication.shared.statusBarOrientation.isPortrait { + if UIApplication.shared.currentStatusBarOrientation.isPortrait { numberOfColumns = nohanaImagePickerController.numberOfColumnsInPortrait } let cellMargin: CGFloat = 2 diff --git a/NohanaImagePicker/AssetListViewController.swift b/NohanaImagePicker/AssetListViewController.swift index 5bcdd89..b651266 100644 --- a/NohanaImagePicker/AssetListViewController.swift +++ b/NohanaImagePicker/AssetListViewController.swift @@ -35,7 +35,7 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg return CGSize.zero } var numberOfColumns = nohanaImagePickerController.numberOfColumnsInLandscape - if UIApplication.shared.statusBarOrientation.isPortrait { + if UIApplication.shared.currentStatusBarOrientation.isPortrait { numberOfColumns = nohanaImagePickerController.numberOfColumnsInPortrait } let cellMargin: CGFloat = 2 diff --git a/NohanaImagePicker/MomentViewController.swift b/NohanaImagePicker/MomentViewController.swift index 290efd6..66e9cbe 100644 --- a/NohanaImagePicker/MomentViewController.swift +++ b/NohanaImagePicker/MomentViewController.swift @@ -29,7 +29,7 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe return CGSize.zero } var numberOfColumns = nohanaImagePickerController.numberOfColumnsInLandscape - if UIApplication.shared.statusBarOrientation.isPortrait { + if UIApplication.shared.currentStatusBarOrientation.isPortrait { numberOfColumns = nohanaImagePickerController.numberOfColumnsInPortrait } let cellMargin: CGFloat = 2 diff --git a/NohanaImagePicker/Size.swift b/NohanaImagePicker/Size.swift index 0b238c5..85d9107 100644 --- a/NohanaImagePicker/Size.swift +++ b/NohanaImagePicker/Size.swift @@ -17,10 +17,10 @@ struct Size { static var statusBarHeight: CGFloat { - if UIApplication.shared.isStatusBarHidden { + if UIApplication.shared.currentStatusBarHidden { return 0 } - return UIApplication.shared.statusBarFrame.size.height + return UIApplication.shared.currentStatusBarFrame.size.height } static func navigationBarHeight(_ viewController: UIViewController) -> CGFloat { diff --git a/NohanaImagePicker/UIApplication+Ex.swift b/NohanaImagePicker/UIApplication+Ex.swift new file mode 100644 index 0000000..43cd005 --- /dev/null +++ b/NohanaImagePicker/UIApplication+Ex.swift @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016 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 + +extension UIApplication { + var currentStatusBarOrientation: UIInterfaceOrientation { + guard let orientation = windows.first(where: { $0.isKeyWindow })?.windowScene?.interfaceOrientation else { + return .unknown + } + return orientation + } + + var currentStatusBarFrame: CGRect { + guard let frame = windows.first(where: { $0.isKeyWindow })?.windowScene?.statusBarManager?.statusBarFrame else { + return .zero + } + return frame + } + + var currentStatusBarHidden: Bool { + guard let isStatusBarHidden = windows.first(where: { $0.isKeyWindow })?.windowScene?.statusBarManager?.isStatusBarHidden else { + return false + } + return isStatusBarHidden + } +} From d44c7253a4e9aae3edb1c93253e5be2685fa1988 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Thu, 23 Dec 2021 14:05:45 +0900 Subject: [PATCH 05/33] Add a case to the demo app. --- Demo/DemoListViewController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Demo/DemoListViewController.swift b/Demo/DemoListViewController.swift index 8e3e17f..d1ae76d 100644 --- a/Demo/DemoListViewController.swift +++ b/Demo/DemoListViewController.swift @@ -89,6 +89,8 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController handler(false) case .authorized: handler(true) + case .limited: + handler(true) @unknown default: fatalError() } From 1400e6c6acc845bb85fa4fcfce2e8e25a4051ccb Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Fri, 17 Dec 2021 12:47:19 +0900 Subject: [PATCH 06/33] Modified to split storyboard. --- NohanaImagePicker.xcodeproj/project.pbxproj | 12 + NohanaImagePicker/AlbumList.storyboard | 134 +++++ NohanaImagePicker/AssetList.storyboard | 182 +++++++ NohanaImagePicker/Moment.storyboard | 214 ++++++++ .../NohanaImagePicker.storyboard | 492 +----------------- 5 files changed, 543 insertions(+), 491 deletions(-) create mode 100644 NohanaImagePicker/AlbumList.storyboard create mode 100644 NohanaImagePicker/AssetList.storyboard create mode 100644 NohanaImagePicker/Moment.storyboard diff --git a/NohanaImagePicker.xcodeproj/project.pbxproj b/NohanaImagePicker.xcodeproj/project.pbxproj index 8ba688c..6dabb09 100644 --- a/NohanaImagePicker.xcodeproj/project.pbxproj +++ b/NohanaImagePicker.xcodeproj/project.pbxproj @@ -10,6 +10,9 @@ 3569CAA91EC1918E000C41C0 /* NohanaImagePicker.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3569CAA61EC1918E000C41C0 /* NohanaImagePicker.xcassets */; }; 6ACE6617276051F6008AA84D /* ImagePreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ACE6616276051F6008AA84D /* ImagePreviewViewController.swift */; }; 6AD1607F2770B23D00A8B066 /* UIApplication+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.swift */; }; + 6A8047FF276C3D77000F3B28 /* AlbumList.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A8047FE276C3D77000F3B28 /* AlbumList.storyboard */; }; + 6A804801276C3E80000F3B28 /* Moment.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A804800276C3E80000F3B28 /* Moment.storyboard */; }; + 6A804803276C3F01000F3B28 /* AssetList.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A804802276C3F01000F3B28 /* AssetList.storyboard */; }; 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 */; }; @@ -86,6 +89,9 @@ 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 = ""; }; 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Ex.swift"; sourceTree = ""; }; + 6A8047FE276C3D77000F3B28 /* AlbumList.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AlbumList.storyboard; sourceTree = ""; }; + 6A804800276C3E80000F3B28 /* Moment.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Moment.storyboard; sourceTree = ""; }; + 6A804802276C3F01000F3B28 /* AssetList.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AssetList.storyboard; 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 = ""; }; @@ -213,6 +219,9 @@ isa = PBXGroup; children = ( F23554251C69D19C00796DCA /* NohanaImagePicker.storyboard */, + 6A804802276C3F01000F3B28 /* AssetList.storyboard */, + 6A8047FE276C3D77000F3B28 /* AlbumList.storyboard */, + 6A804800276C3E80000F3B28 /* Moment.storyboard */, F1A26CCC2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard */, F27029CD1C71C43A001647AB /* NohanaImagePicker.strings */, F237249A1C6DCF96005D1E8A /* NohanaImagePicker.xcassets */, @@ -415,8 +424,11 @@ buildActionMask = 2147483647; files = ( F23554261C69D19C00796DCA /* NohanaImagePicker.storyboard in Resources */, + 6A804803276C3F01000F3B28 /* AssetList.storyboard in Resources */, F27029CB1C71C43A001647AB /* NohanaImagePicker.strings in Resources */, + 6A804801276C3E80000F3B28 /* Moment.storyboard in Resources */, F237249B1C6DCF96005D1E8A /* NohanaImagePicker.xcassets in Resources */, + 6A8047FF276C3D77000F3B28 /* AlbumList.storyboard in Resources */, F1A26CCD2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/NohanaImagePicker/AlbumList.storyboard b/NohanaImagePicker/AlbumList.storyboard new file mode 100644 index 0000000..a3838ab --- /dev/null +++ b/NohanaImagePicker/AlbumList.storyboard @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NohanaImagePicker/AssetList.storyboard b/NohanaImagePicker/AssetList.storyboard new file mode 100644 index 0000000..dd309da --- /dev/null +++ b/NohanaImagePicker/AssetList.storyboard @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NohanaImagePicker/Moment.storyboard b/NohanaImagePicker/Moment.storyboard new file mode 100644 index 0000000..c65595b --- /dev/null +++ b/NohanaImagePicker/Moment.storyboard @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NohanaImagePicker/NohanaImagePicker.storyboard b/NohanaImagePicker/NohanaImagePicker.storyboard index b795557..41adea7 100644 --- a/NohanaImagePicker/NohanaImagePicker.storyboard +++ b/NohanaImagePicker/NohanaImagePicker.storyboard @@ -7,274 +7,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -298,9 +30,6 @@ - - - @@ -327,229 +56,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - From 2994f35cbafd6bfa1c60c1349f6bb946b261af2b Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Mon, 20 Dec 2021 10:08:51 +0900 Subject: [PATCH 07/33] Added root viewcontroller. --- NohanaImagePicker.xcodeproj/project.pbxproj | 4 ++ .../NohanaImagePicker.storyboard | 34 +++++++++++++++++ NohanaImagePicker/RootViewController.swift | 38 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 NohanaImagePicker/RootViewController.swift diff --git a/NohanaImagePicker.xcodeproj/project.pbxproj b/NohanaImagePicker.xcodeproj/project.pbxproj index 6dabb09..ed95390 100644 --- a/NohanaImagePicker.xcodeproj/project.pbxproj +++ b/NohanaImagePicker.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 6A8047FF276C3D77000F3B28 /* AlbumList.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A8047FE276C3D77000F3B28 /* AlbumList.storyboard */; }; 6A804801276C3E80000F3B28 /* Moment.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A804800276C3E80000F3B28 /* Moment.storyboard */; }; 6A804803276C3F01000F3B28 /* AssetList.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A804802276C3F01000F3B28 /* AssetList.storyboard */; }; + 6AD1607C27700F0C00A8B066 /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1607B27700F0C00A8B066 /* RootViewController.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 */; }; @@ -92,6 +93,7 @@ 6A8047FE276C3D77000F3B28 /* AlbumList.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AlbumList.storyboard; sourceTree = ""; }; 6A804800276C3E80000F3B28 /* Moment.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Moment.storyboard; sourceTree = ""; }; 6A804802276C3F01000F3B28 /* AssetList.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AssetList.storyboard; sourceTree = ""; }; + 6AD1607B27700F0C00A8B066 /* RootViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewController.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 = ""; }; @@ -302,6 +304,7 @@ children = ( F1E5DE7E26A5831D004B9EDE /* Models */, F23554271C69D5DB00796DCA /* NohanaImagePickerController.swift */, + 6AD1607B27700F0C00A8B066 /* RootViewController.swift */, F24EB68F1C68AEED0002EC86 /* AlbumListViewController.swift */, F2DF3B141C6C76E500C1C0E4 /* AssetListViewController.swift */, F25C10C11C8ED9BF007453C3 /* MomentViewController.swift */, @@ -464,6 +467,7 @@ F1E5DE8026A58346004B9EDE /* MomentInfoSection.swift in Sources */, F181095026A5361A001C2BDE /* MomentDetailListViewController.swift in Sources */, F25C69921CA28728005935D6 /* AlbumListEmptyIndicator.swift in Sources */, + 6AD1607C27700F0C00A8B066 /* RootViewController.swift in Sources */, F2131F431C79615700797887 /* SwipeInteractionController.swift in Sources */, F2DF3B2D1C6D780100C1C0E4 /* AssetDetailCell.swift in Sources */, F25C69901CA27311005935D6 /* EmptyIndicatable.swift in Sources */, diff --git a/NohanaImagePicker/NohanaImagePicker.storyboard b/NohanaImagePicker/NohanaImagePicker.storyboard index 41adea7..f9715ba 100644 --- a/NohanaImagePicker/NohanaImagePicker.storyboard +++ b/NohanaImagePicker/NohanaImagePicker.storyboard @@ -4,6 +4,7 @@ + @@ -30,6 +31,9 @@ + + + @@ -56,10 +60,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift new file mode 100644 index 0000000..bf53381 --- /dev/null +++ b/NohanaImagePicker/RootViewController.swift @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2016 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 + +class RootViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destination. + // Pass the selected object to the new view controller. + } + */ + +} From ee9e05e78c5f35bd6b0320aaaaff4c028f43a645 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Mon, 20 Dec 2021 11:57:27 +0900 Subject: [PATCH 08/33] Added button. --- NohanaImagePicker/NohanaImagePicker.storyboard | 14 +++++++++++++- NohanaImagePicker/RootViewController.swift | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/NohanaImagePicker/NohanaImagePicker.storyboard b/NohanaImagePicker/NohanaImagePicker.storyboard index f9715ba..ed8f83b 100644 --- a/NohanaImagePicker/NohanaImagePicker.storyboard +++ b/NohanaImagePicker/NohanaImagePicker.storyboard @@ -81,7 +81,18 @@ - + + + + + + + + + + + + @@ -92,6 +103,7 @@ + diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index bf53381..19b4d93 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -34,5 +34,15 @@ class RootViewController: UIViewController { // Pass the selected object to the new view controller. } */ + + // MARK: - IBAction + @IBAction func didTapDone(_ sender: AnyObject) { + let pickedPhotoKitAssets = nohanaImagePickerController.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset } + nohanaImagePickerController.delegate?.nohanaImagePicker(nohanaImagePickerController, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets ) + } + + @IBAction func didTapClose(_ sender: AnyObject) { + dismiss(animated: true) + } } From c4dba89202e6f066e73a9c6a3f663f4fb073a1a8 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Mon, 20 Dec 2021 13:01:25 +0900 Subject: [PATCH 09/33] Implemented init. --- NohanaImagePicker/RootViewController.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index 19b4d93..ebb8e8c 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -17,6 +17,17 @@ import UIKit class RootViewController: UIViewController { + + private let nohanaImagePickerController: NohanaImagePickerController + + init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController) { + self.nohanaImagePickerController = nohanaImagePickerController + super.init(coder: coder) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } override func viewDidLoad() { super.viewDidLoad() From c5ffb6322851ff46ca2ea9b0311b903a4aa6f2f5 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Thu, 23 Dec 2021 15:13:40 +0900 Subject: [PATCH 10/33] Removed navigation controller from storyboard. --- .../NohanaImagePicker.storyboard | 65 +------------------ 1 file changed, 1 insertion(+), 64 deletions(-) diff --git a/NohanaImagePicker/NohanaImagePicker.storyboard b/NohanaImagePicker/NohanaImagePicker.storyboard index ed8f83b..4fb2bde 100644 --- a/NohanaImagePicker/NohanaImagePicker.storyboard +++ b/NohanaImagePicker/NohanaImagePicker.storyboard @@ -1,5 +1,5 @@ - + @@ -8,66 +8,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -99,9 +39,6 @@ - - - From 5342c50de7535ae7b6c674f77b4e5abf032c0815 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Thu, 23 Dec 2021 15:14:02 +0900 Subject: [PATCH 11/33] Implemented show root viewcontroller. --- .../AnimatableNavigationController.swift | 10 ++-- .../NohanaImagePickerController.swift | 46 +++++++++---------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/NohanaImagePicker/AnimatableNavigationController.swift b/NohanaImagePicker/AnimatableNavigationController.swift index 8ec914c..b6f3fc5 100644 --- a/NohanaImagePicker/AnimatableNavigationController.swift +++ b/NohanaImagePicker/AnimatableNavigationController.swift @@ -20,11 +20,15 @@ class AnimatableNavigationController: UINavigationController, UINavigationContro let swipeInteractionController = SwipeInteractionController() - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) + override init(rootViewController: UIViewController) { + super.init(rootViewController: rootViewController) self.delegate = self } - + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { switch operation { case .push where fromVC is AssetListViewController || fromVC is MomentViewController: diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index 9826ef5..569aef0 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -101,34 +101,28 @@ open class NohanaImagePickerController: UIViewController { override open func viewDidLoad() { super.viewDidLoad() - // show albumListViewController + // show rootViewController let storyboard = UIStoryboard(name: "NohanaImagePicker", bundle: assetBundle) - let viewControllerId = enableExpandingPhotoAnimation ? "EnableAnimationNavigationController" : "DisableAnimationNavigationController" - guard let navigationController = storyboard.instantiateViewController(withIdentifier: viewControllerId) as? UINavigationController else { - fatalError("navigationController init failed.") - } + let rootViewController = storyboard.instantiateViewController(identifier: "RootViewController", creator: { coder in + RootViewController(coder: coder, nohanaImagePickerController: self) + }) + let navigationController: UINavigationController = { + if enableExpandingPhotoAnimation { + return AnimatableNavigationController(rootViewController: rootViewController) + } else { + return UINavigationController(rootViewController: rootViewController) + } + }() addChild(navigationController) view.addSubview(navigationController.view) + NSLayoutConstraint.activate([ + navigationController.view.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor), + navigationController.view.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor), + navigationController.view.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor), + navigationController.view.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor), + ]) + navigationController.view.layoutIfNeeded() navigationController.didMove(toParent: self) - - // setup albumListViewController - guard let albumListViewController = navigationController.topViewController as? AlbumListViewController else { - fatalError("albumListViewController is not topViewController.") - } - albumListViewController.photoKitAlbumList = - PhotoKitAlbumList( - assetCollectionTypes: [.smartAlbum, .album], - assetCollectionSubtypes: assetCollectionSubtypes, - mediaType: mediaType, - shouldShowEmptyAlbum: shouldShowEmptyAlbum, - ascending: !canPickDateSection, - handler: { [weak albumListViewController] in - DispatchQueue.main.async(execute: { () -> Void in - albumListViewController?.isLoading = false - albumListViewController?.tableView.reloadData() - }) - }) - albumListViewController.nohanaImagePickerController = self } open func pickAsset(_ asset: Asset) { @@ -138,6 +132,10 @@ open class NohanaImagePickerController: UIViewController { open func dropAsset(_ asset: Asset) { _ = pickedAssetList.drop(asset: asset) } + + open override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + print(#function) + } } extension NohanaImagePickerController { From 04ef1da57c5f5964d47aa165ca7f32503e61ea32 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Mon, 20 Dec 2021 13:01:25 +0900 Subject: [PATCH 12/33] Added IBSegueAction. --- .../AssetDetailListViewController.swift | 25 +++----- NohanaImagePicker/AssetList.storyboard | 2 +- .../AssetListSelectableDateSection.storyboard | 2 +- ...tListSelectableDateSectionController.swift | 60 +++++++++--------- .../AssetListViewController.swift | 60 +++++++++--------- NohanaImagePicker/Moment.storyboard | 2 +- .../MomentDetailListViewController.swift | 39 ++++++------ NohanaImagePicker/MomentViewController.swift | 61 ++++++++++--------- 8 files changed, 127 insertions(+), 124 deletions(-) diff --git a/NohanaImagePicker/AssetDetailListViewController.swift b/NohanaImagePicker/AssetDetailListViewController.swift index f7f3d8f..bd71062 100644 --- a/NohanaImagePicker/AssetDetailListViewController.swift +++ b/NohanaImagePicker/AssetDetailListViewController.swift @@ -39,13 +39,11 @@ class AssetDetailListViewController: AssetListViewController, DetailListViewCont override func viewDidLoad() { super.viewDidLoad() - if let nohanaImagePickerController = nohanaImagePickerController { - let droppedImage: UIImage? = nohanaImagePickerController.config.image.droppedLarge ?? UIImage(named: "btn_select_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil) - let pickedImage: UIImage? = nohanaImagePickerController.config.image.pickedLarge ?? UIImage(named: "btn_selected_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil) - - pickButton.setImage(droppedImage, for: UIControl.State()) - pickButton.setImage(pickedImage, for: .selected) - } + let droppedImage: UIImage? = nohanaImagePickerController.config.image.droppedLarge ?? UIImage(named: "btn_select_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil) + let pickedImage: UIImage? = nohanaImagePickerController.config.image.pickedLarge ?? UIImage(named: "btn_selected_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil) + + pickButton.setImage(droppedImage, for: UIControl.State()) + pickButton.setImage(pickedImage, for: .selected) } override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { @@ -65,9 +63,6 @@ class AssetDetailListViewController: AssetListViewController, DetailListViewCont } func didChangeAssetDetailPage(_ indexPath: IndexPath) { - guard let nohanaImagePickerController = nohanaImagePickerController else { - return - } let asset = photoKitAssetList[indexPath.item] pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset) pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) ) @@ -75,8 +70,7 @@ class AssetDetailListViewController: AssetListViewController, DetailListViewCont } override func scrollCollectionView(to indexPath: IndexPath) { - let count: Int? = photoKitAssetList?.count - guard count != nil && count! > 0 else { + guard photoKitAssetList.count > 0 else { return } DispatchQueue.main.async { @@ -99,11 +93,11 @@ class AssetDetailListViewController: AssetListViewController, DetailListViewCont @IBAction func didPushPickButton(_ sender: UIButton) { let asset = photoKitAssetList[currentIndexPath.row] if pickButton.isSelected { - if nohanaImagePickerController!.pickedAssetList.drop(asset: asset) { + if nohanaImagePickerController.pickedAssetList.drop(asset: asset) { pickButton.isSelected = false } } else { - if nohanaImagePickerController!.pickedAssetList.pick(asset: asset) { + if nohanaImagePickerController.pickedAssetList.pick(asset: asset) { pickButton.isSelected = true } } @@ -112,8 +106,7 @@ class AssetDetailListViewController: AssetListViewController, DetailListViewCont // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetDetailCell", for: indexPath) as? AssetDetailCell, - let nohanaImagePickerController = nohanaImagePickerController else { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetDetailCell", for: indexPath) as? AssetDetailCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetDetailCell\")") } cell.scrollView.zoomScale = 1 diff --git a/NohanaImagePicker/AssetList.storyboard b/NohanaImagePicker/AssetList.storyboard index dd309da..c69666d 100644 --- a/NohanaImagePicker/AssetList.storyboard +++ b/NohanaImagePicker/AssetList.storyboard @@ -65,7 +65,7 @@ - + diff --git a/NohanaImagePicker/AssetListSelectableDateSection.storyboard b/NohanaImagePicker/AssetListSelectableDateSection.storyboard index 882e71e..d3a2094 100644 --- a/NohanaImagePicker/AssetListSelectableDateSection.storyboard +++ b/NohanaImagePicker/AssetListSelectableDateSection.storyboard @@ -65,7 +65,7 @@ - + diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index b8ef24d..b0c570d 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -19,14 +19,11 @@ import Photos class AssetListSelectableDateSectionController: UICollectionViewController, UICollectionViewDelegateFlowLayout, ActivityIndicatable { - weak var nohanaImagePickerController: NohanaImagePickerController? - var photoKitAssetList: PhotoKitAssetList! + private let nohanaImagePickerController: NohanaImagePickerController + let photoKitAssetList: PhotoKitAssetList var dateSectionList: [AssetDateSection] = [] var cellSize: CGSize { - guard let nohanaImagePickerController = nohanaImagePickerController else { - return CGSize.zero - } var numberOfColumns = nohanaImagePickerController.numberOfColumnsInLandscape if UIApplication.shared.currentStatusBarOrientation.isPortrait { numberOfColumns = nohanaImagePickerController.numberOfColumnsInPortrait @@ -35,10 +32,20 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo let cellWidth = (view.frame.width - cellMargin * (CGFloat(numberOfColumns) - 1)) / CGFloat(numberOfColumns) return CGSize(width: cellWidth, height: cellWidth) } + + init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController, photoKitAssetList: PhotoKitAssetList) { + self.nohanaImagePickerController = nohanaImagePickerController + self.photoKitAssetList = photoKitAssetList + super.init(coder: coder) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = nohanaImagePickerController?.config.color.background ?? .white + view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white updateTitle() setUpToolbarItems() addPickPhotoKitAssetNotificationObservers() @@ -53,9 +60,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - if let nohanaImagePickerController = nohanaImagePickerController { - setToolbarTitle(nohanaImagePickerController) - } + setToolbarTitle(nohanaImagePickerController) collectionView?.reloadData() } @@ -90,8 +95,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell, - let nohanaImagePickerController = nohanaImagePickerController else { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")") } @@ -120,8 +124,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo switch kind { case UICollectionView.elementKindSectionHeader: let album = dateSectionList[indexPath.section] - guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AssetDateSectionHeader", for: indexPath) as? AssetDateSectionHeaderView, - let nohanaImagePickerController = nohanaImagePickerController else { + guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AssetDateSectionHeader", for: indexPath) as? AssetDateSectionHeaderView else { fatalError("failed to create AssetDateSectionHeader") } header.date = album.creationDate @@ -160,15 +163,13 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - if let nohanaImagePickerController = nohanaImagePickerController { - nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: dateSectionList[indexPath.section].assetResult[indexPath.row]) - } + 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 { + if let cell = collectionView.cellForItem(at: indexPath) as? AssetCell { 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 } @@ -179,18 +180,19 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo 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: "") + }, actionProvider: { [weak self] _ in + guard let self = self else { return nil } + if self.nohanaImagePickerController.pickedAssetList.isPicked(asset) { + let title = self.nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.deselect", tableName: "NohanaImagePicker", bundle: self.nohanaImagePickerController.assetBundle, comment: "") let deselect = UIAction(title: title, image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in - nohanaImagePickerController.dropAsset(asset) + self.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 title = self.nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.select", tableName: "NohanaImagePicker", bundle: self.nohanaImagePickerController.assetBundle, comment: "") let select = UIAction(title: title, image: UIImage(systemName: "checkmark.circle")) { _ in - nohanaImagePickerController.pickAsset(asset) + self.nohanaImagePickerController.pickAsset(asset) collectionView.reloadSections(IndexSet(integer: indexPath.section)) } return UIMenu(title: "", children: [select]) @@ -232,18 +234,18 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo } let assetListDetailViewController = segue.destination as! AssetDetailListViewController - assetListDetailViewController.photoKitAssetList = photoKitAssetList - assetListDetailViewController.nohanaImagePickerController = nohanaImagePickerController assetListDetailViewController.currentIndexPath = IndexPath(item: assetListDetailCurrentRow, section: 0) } // MARK: - IBAction @IBAction func didPushDone(_ sender: AnyObject) { - if let nohanaImagePickerController = nohanaImagePickerController { - let pickedPhotoKitAssets = nohanaImagePickerController.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset } + let pickedPhotoKitAssets = nohanaImagePickerController.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset } nohanaImagePickerController.delegate?.nohanaImagePicker(nohanaImagePickerController, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets) - } + } + + @IBSegueAction func makeDetailList(_ coder: NSCoder) -> AssetDetailListViewController? { + AssetDetailListViewController(coder: coder, nohanaImagePickerController: nohanaImagePickerController, photoKitAssetList: photoKitAssetList) } } @@ -262,7 +264,7 @@ extension AssetListSelectableDateSectionController: AssetCellDelegate { let rowResetIndexPath = IndexPath(row: 0, section: indexPath.section) let header = collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionHeader, at: rowResetIndexPath) as? AssetDateSectionHeaderView let assets = dateSectionList[indexPath.section].assetResult.map { PhotoKitAsset(asset: $0) } - header?.update(assets: assets, indexPath: indexPath, nohanaImagePickerController: nohanaImagePickerController!) + header?.update(assets: assets, indexPath: indexPath, nohanaImagePickerController: nohanaImagePickerController) } else { UIView.animate(withDuration: 0) { [weak self] in self?.collectionView.performBatchUpdates({ [weak self] in diff --git a/NohanaImagePicker/AssetListViewController.swift b/NohanaImagePicker/AssetListViewController.swift index b651266..ff8bb51 100644 --- a/NohanaImagePicker/AssetListViewController.swift +++ b/NohanaImagePicker/AssetListViewController.swift @@ -19,21 +19,28 @@ import Photos class AssetListViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout { - weak var nohanaImagePickerController: NohanaImagePickerController? - var photoKitAssetList: PhotoKitAssetList! - + let nohanaImagePickerController: NohanaImagePickerController + let photoKitAssetList: PhotoKitAssetList + + init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController, photoKitAssetList: PhotoKitAssetList) { + self.nohanaImagePickerController = nohanaImagePickerController + self.photoKitAssetList = photoKitAssetList + super.init(coder: coder) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = nohanaImagePickerController?.config.color.background ?? .white + view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white updateTitle() setUpToolbarItems() addPickPhotoKitAssetNotificationObservers() } var cellSize: CGSize { - guard let nohanaImagePickerController = nohanaImagePickerController else { - return CGSize.zero - } var numberOfColumns = nohanaImagePickerController.numberOfColumnsInLandscape if UIApplication.shared.currentStatusBarOrientation.isPortrait { numberOfColumns = nohanaImagePickerController.numberOfColumnsInPortrait @@ -49,9 +56,7 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - if let nohanaImagePickerController = nohanaImagePickerController { - setToolbarTitle(nohanaImagePickerController) - } + setToolbarTitle(nohanaImagePickerController) collectionView?.reloadData() scrollCollectionViewToInitialPosition() } @@ -77,8 +82,7 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg } func scrollCollectionView(to indexPath: IndexPath) { - let count: Int? = photoKitAssetList?.count - guard count != nil && count! > 0 else { + guard photoKitAssetList.count > 0 else { return } DispatchQueue.main.async { @@ -104,15 +108,13 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - if let nohanaImagePickerController = nohanaImagePickerController { - nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: photoKitAssetList[indexPath.item].originalAsset) - } + 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 { + if let cell = collectionView.cellForItem(at: indexPath) as? AssetCell { 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 } @@ -123,18 +125,19 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg 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: "") + }, actionProvider: { [weak self] _ in + guard let self = self else { return nil } + if self.nohanaImagePickerController.pickedAssetList.isPicked(asset) { + let title = self.nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.deselect", tableName: "NohanaImagePicker", bundle: self.nohanaImagePickerController.assetBundle, comment: "") let deselect = UIAction(title: title, image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in - nohanaImagePickerController.dropAsset(asset) + self.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 title = self.nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.select", tableName: "NohanaImagePicker", bundle: self.nohanaImagePickerController.assetBundle, comment: "") let select = UIAction(title: title, image: UIImage(systemName: "checkmark.circle")) { _ in - nohanaImagePickerController.pickAsset(asset) + self.nohanaImagePickerController.pickAsset(asset) collectionView.reloadItems(at: [indexPath]) } return UIMenu(title: "", children: [select]) @@ -157,8 +160,7 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell, - let nohanaImagePickerController = nohanaImagePickerController else { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")") } cell.tag = indexPath.item @@ -195,14 +197,16 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg } let assetListDetailViewController = segue.destination as! AssetDetailListViewController - assetListDetailViewController.photoKitAssetList = photoKitAssetList - assetListDetailViewController.nohanaImagePickerController = nohanaImagePickerController assetListDetailViewController.currentIndexPath = selectedIndexPath } // MARK: - IBAction @IBAction func didPushDone(_ sender: AnyObject) { - let pickedPhotoKitAssets = nohanaImagePickerController!.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset } - nohanaImagePickerController!.delegate?.nohanaImagePicker(nohanaImagePickerController!, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets ) + let pickedPhotoKitAssets = nohanaImagePickerController.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset } + nohanaImagePickerController.delegate?.nohanaImagePicker(nohanaImagePickerController, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets ) + } + + @IBSegueAction func makeDetailList(_ coder: NSCoder) -> AssetDetailListViewController? { + return AssetDetailListViewController(coder: coder, nohanaImagePickerController: nohanaImagePickerController, photoKitAssetList: photoKitAssetList) } } diff --git a/NohanaImagePicker/Moment.storyboard b/NohanaImagePicker/Moment.storyboard index c65595b..efbbd49 100644 --- a/NohanaImagePicker/Moment.storyboard +++ b/NohanaImagePicker/Moment.storyboard @@ -65,7 +65,7 @@ - + diff --git a/NohanaImagePicker/MomentDetailListViewController.swift b/NohanaImagePicker/MomentDetailListViewController.swift index 31f6788..f7a8637 100644 --- a/NohanaImagePicker/MomentDetailListViewController.swift +++ b/NohanaImagePicker/MomentDetailListViewController.swift @@ -32,10 +32,19 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec return Size.screenRectWithoutAppBar(self).size } - weak var nohanaImagePickerController: NohanaImagePickerController? + let nohanaImagePickerController: NohanaImagePickerController var momentInfoSection: MomentInfoSection? var isFirstAppearance = true + init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController) { + self.nohanaImagePickerController = nohanaImagePickerController + super.init(coder: coder) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func loadView() { super.loadView() self.collectionView.backgroundColor = .black @@ -43,18 +52,16 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = nohanaImagePickerController?.config.color.background ?? .white + view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white title = "" setUpToolbarItems() addPickPhotoKitAssetNotificationObservers() - if let nohanaImagePickerController = nohanaImagePickerController { - let droppedImage: UIImage? = nohanaImagePickerController.config.image.droppedLarge ?? UIImage(named: "btn_select_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil) - let pickedImage: UIImage? = nohanaImagePickerController.config.image.pickedLarge ?? UIImage(named: "btn_selected_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil) - - pickButton.setImage(droppedImage, for: UIControl.State()) - pickButton.setImage(pickedImage, for: .selected) - } + let droppedImage: UIImage? = nohanaImagePickerController.config.image.droppedLarge ?? UIImage(named: "btn_select_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil) + let pickedImage: UIImage? = nohanaImagePickerController.config.image.pickedLarge ?? UIImage(named: "btn_selected_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil) + + pickButton.setImage(droppedImage, for: UIControl.State()) + pickButton.setImage(pickedImage, for: .selected) } deinit { @@ -63,9 +70,7 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - if let nohanaImagePickerController = nohanaImagePickerController { - setToolbarTitle(nohanaImagePickerController) - } + setToolbarTitle(nohanaImagePickerController) collectionView?.reloadData() scrollCollectionViewToInitialPosition() } @@ -93,7 +98,7 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec } func didChangeAssetDetailPage(_ indexPath: IndexPath) { - guard let nohanaImagePickerController = nohanaImagePickerController, let momentInfoSection = momentInfoSection else { + guard let momentInfoSection = momentInfoSection else { return } let asset = PhotoKitAsset(asset: momentInfoSection.assetResult[indexPath.item]) @@ -130,15 +135,13 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - if let nohanaImagePickerController = nohanaImagePickerController, let momentInfoSection = momentInfoSection { + if let momentInfoSection = momentInfoSection { nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: momentInfoSection.assetResult[indexPath.item]) } } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetDetailCell", for: indexPath) as? AssetDetailCell, - let nohanaImagePickerController = nohanaImagePickerController, - let momentInfoSection = momentInfoSection else { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetDetailCell", for: indexPath) as? AssetDetailCell, let momentInfoSection = momentInfoSection else { fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetDetailCell\")") } cell.scrollView.zoomScale = 1 @@ -188,7 +191,7 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec // MARK: - IBAction @IBAction func didPushPickButton(_ sender: UIButton) { - guard let nohanaImagePickerController = nohanaImagePickerController, let momentInfoSection = momentInfoSection else { return } + guard let momentInfoSection = momentInfoSection else { return } let asset = PhotoKitAsset(asset: momentInfoSection.assetResult[currentIndexPath.item]) if pickButton.isSelected { if nohanaImagePickerController.pickedAssetList.drop(asset: asset) { diff --git a/NohanaImagePicker/MomentViewController.swift b/NohanaImagePicker/MomentViewController.swift index 66e9cbe..22b5467 100644 --- a/NohanaImagePicker/MomentViewController.swift +++ b/NohanaImagePicker/MomentViewController.swift @@ -19,15 +19,11 @@ import Photos final class MomentViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, ActivityIndicatable { - weak var nohanaImagePickerController: NohanaImagePickerController? - var photoKitAssetList: PhotoKitAssetList! + private let nohanaImagePickerController: NohanaImagePickerController var momentInfoSectionList: [MomentInfoSection] = [] var isFirstAppearance = true var cellSize: CGSize { - guard let nohanaImagePickerController = nohanaImagePickerController else { - return CGSize.zero - } var numberOfColumns = nohanaImagePickerController.numberOfColumnsInLandscape if UIApplication.shared.currentStatusBarOrientation.isPortrait { numberOfColumns = nohanaImagePickerController.numberOfColumnsInPortrait @@ -36,16 +32,26 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe let cellWidth = (view.frame.width - cellMargin * (CGFloat(numberOfColumns) - 1)) / CGFloat(numberOfColumns) return CGSize(width: cellWidth, height: cellWidth) } - + + init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController) { + self.nohanaImagePickerController = nohanaImagePickerController + super.init(coder: coder) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = nohanaImagePickerController?.config.color.background ?? .white + view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white updateTitle() setUpToolbarItems() addPickPhotoKitAssetNotificationObservers() setUpActivityIndicator() DispatchQueue.main.async { [weak self] in - guard let self = self, let mediaType = self.nohanaImagePickerController?.mediaType else { return } + guard let self = self else { return } + let mediaType = self.nohanaImagePickerController.mediaType self.momentInfoSectionList = MomentInfoSectionCreater().createSections(mediaType: mediaType) self.isLoading = false self.collectionView?.reloadData() @@ -56,17 +62,13 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - if let nohanaImagePickerController = nohanaImagePickerController { - setToolbarTitle(nohanaImagePickerController) - } + setToolbarTitle(nohanaImagePickerController) collectionView?.reloadData() scrollCollectionViewToInitialPosition() } func updateTitle() { - if let nohanaImagePickerController = nohanaImagePickerController { - title = NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") - } + title = NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") } func scrollCollectionView(to indexPath: IndexPath) { @@ -109,8 +111,7 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell, - let nohanaImagePickerController = nohanaImagePickerController else { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")") } @@ -177,15 +178,13 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - if let nohanaImagePickerController = nohanaImagePickerController { - nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: momentInfoSectionList[indexPath.section].assetResult[indexPath.row]) - } + 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 { + if let cell = collectionView.cellForItem(at: indexPath) as? AssetCell { 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 } @@ -196,18 +195,19 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe 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: "") + }, actionProvider: { [weak self] _ in + guard let self = self else { return nil } + if self.nohanaImagePickerController.pickedAssetList.isPicked(asset) { + let title = self.nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.deselect", tableName: "NohanaImagePicker", bundle: self.nohanaImagePickerController.assetBundle, comment: "") let deselect = UIAction(title: title, image: UIImage(systemName: "minus.circle"), attributes: [.destructive]) { _ in - nohanaImagePickerController.dropAsset(asset) + self.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 title = self.nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("action.title.select", tableName: "NohanaImagePicker", bundle: self.nohanaImagePickerController.assetBundle, comment: "") let select = UIAction(title: title, image: UIImage(systemName: "checkmark.circle")) { _ in - nohanaImagePickerController.pickAsset(asset) + self.nohanaImagePickerController.pickAsset(asset) collectionView.reloadItems(at: [indexPath]) } return UIMenu(title: "", children: [select]) @@ -237,16 +237,17 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe } let momentDetailListViewController = segue.destination as! MomentDetailListViewController momentDetailListViewController.momentInfoSection = momentInfoSectionList[selectedIndexPath.section] - momentDetailListViewController.nohanaImagePickerController = nohanaImagePickerController momentDetailListViewController.currentIndexPath = selectedIndexPath } // MARK: - IBAction @IBAction func didPushDone(_ sender: AnyObject) { - if let nohanaImagePickerController = nohanaImagePickerController { - let pickedPhotoKitAssets = nohanaImagePickerController.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset } + let pickedPhotoKitAssets = nohanaImagePickerController.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset } nohanaImagePickerController.delegate?.nohanaImagePicker(nohanaImagePickerController, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets) - } + } + + @IBSegueAction func makeMomentDetail(_ coder: NSCoder) -> MomentDetailListViewController? { + return MomentDetailListViewController(coder: coder, nohanaImagePickerController: nohanaImagePickerController) } } From 1ea62662bbf761ce754a5deb5aaa6359031870da Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Thu, 23 Dec 2021 16:41:15 +0900 Subject: [PATCH 13/33] Implemented AlbumListViewControllerDelegate. --- .../AlbumListViewController.swift | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index 581c299..f736d96 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -17,6 +17,12 @@ import UIKit import Photos +protocol AlbumListViewControllerDelegate: AnyObject { + func didSelectMoment() + func didSelectAlbum(album: PhotoKitAssetList) + func didDissmissViewController(viewController: AlbumListViewController) +} + class AlbumListViewController: UITableViewController, EmptyIndicatable, ActivityIndicatable { enum AlbumListViewControllerSectionType: Int { @@ -37,6 +43,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity weak var nohanaImagePickerController: NohanaImagePickerController? var photoKitAlbumList: PhotoKitAlbumList! + weak var delegate: AlbumListViewControllerDelegate? override func viewDidLoad() { super.viewDidLoad() @@ -80,14 +87,19 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity } switch sectionType { case .moment: + delegate?.didSelectMoment() nohanaImagePickerController.delegate?.nohanaImagePickerDidSelectMoment?(nohanaImagePickerController) - case .albums: - if nohanaImagePickerController.canPickDateSection { - performSegue(withIdentifier: "toAssetListViewSelectableDateSectionController", sender: nil) - } else { - performSegue(withIdentifier: "toAssetListViewController", sender: nil) + dismiss(animated: true) { [weak self] in + guard let self = self else { return } + self.delegate?.didDissmissViewController(viewController: self) } + case .albums: + delegate?.didSelectAlbum(album: photoKitAlbumList[indexPath.row]) nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAssetList: photoKitAlbumList[indexPath.row].assetList) + dismiss(animated: true) { [weak self] in + guard let self = self else { return } + self.delegate?.didDissmissViewController(viewController: self) + } } } @@ -178,32 +190,6 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity } } - // MARK: - Storyboard - - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - guard let sectionType = AlbumListViewControllerSectionType(rawValue: tableView.indexPathForSelectedRow!.section) else { - fatalError("Invalid section") - } - switch sectionType { - case .moment: - let momentViewController = segue.destination as! MomentViewController - momentViewController.nohanaImagePickerController = nohanaImagePickerController - case .albums: - switch segue.identifier { - case "toAssetListViewController": - let assetListViewController = segue.destination as! AssetListViewController - assetListViewController.photoKitAssetList = photoKitAlbumList[tableView.indexPathForSelectedRow!.row] - assetListViewController.nohanaImagePickerController = nohanaImagePickerController - case "toAssetListViewSelectableDateSectionController": - let assetListSelectableDateSectionController = segue.destination as! AssetListSelectableDateSectionController - assetListSelectableDateSectionController.photoKitAssetList = photoKitAlbumList[tableView.indexPathForSelectedRow!.row] - assetListSelectableDateSectionController.nohanaImagePickerController = nohanaImagePickerController - default: - fatalError("unexpected segue identifer") - } - } - } - // MARK: - IBAction @IBAction func didPushCancel(_ sender: AnyObject) { From 77b5577c1ad32a6e734d23994a728d7fd2c45682 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Thu, 23 Dec 2021 16:44:12 +0900 Subject: [PATCH 14/33] Implemented root viewcontroller. --- .../NohanaImagePickerController.swift | 9 +- NohanaImagePicker/RootViewController.swift | 185 ++++++++++++++++-- 2 files changed, 181 insertions(+), 13 deletions(-) diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index 569aef0..9a3e8f1 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -51,7 +51,12 @@ open class NohanaImagePickerController: UIViewController { } open var config: Config = Config() open var canPickDateSection: Bool = false - + open var titleTextAttributes: [NSAttributedString.Key: Any] = { + return [ + .foregroundColor: UIColor.black, + .font: UIFont.systemFont(ofSize: 17, weight: .semibold) + ] + }() lazy var assetBundle: Bundle = { let bundle = Bundle(for: type(of: self)) if let path = bundle.path(forResource: "NohanaImagePicker", ofType: "bundle") { @@ -62,7 +67,7 @@ open class NohanaImagePickerController: UIViewController { let pickedAssetList: PickedAssetList let mediaType: MediaType let enableExpandingPhotoAnimation: Bool - fileprivate let assetCollectionSubtypes: [PHAssetCollectionSubtype] + let assetCollectionSubtypes: [PHAssetCollectionSubtype] public init() { assetCollectionSubtypes = [ diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index ebb8e8c..81fc95f 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -19,6 +19,14 @@ import UIKit class RootViewController: UIViewController { private let nohanaImagePickerController: NohanaImagePickerController + private let titleView: UIButton = { + let button = UIButton(type: .system) + let image = UIImage(systemName: "chevron.down", withConfiguration: UIImage.SymbolConfiguration(pointSize: 9, weight: .semibold)) + button.setImage(image, for: .normal) + return button + }() + private var currentChildViewController: UIViewController? + private var albumList: PhotoKitAlbumList! init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController) { self.nohanaImagePickerController = nohanaImagePickerController @@ -31,20 +39,147 @@ class RootViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - - // Do any additional setup after loading the view. + + // titleView + titleView.addTarget(self, action: #selector(didTapTitleView), for: .touchUpInside) + navigationItem.titleView = titleView + + // toolbar + navigationController?.setToolbarHidden(nohanaImagePickerController.toolbarHidden, animated: false) + setUpToolbarItems() + + // Notification + addPickPhotoKitAssetNotificationObservers() + + showRecentPhotos() } - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + setToolbarTitle(nohanaImagePickerController) + } + + // MARK: Private + private func updateTitle(title: String) { + let attributedTitle = NSAttributedString(string: title, attributes: nohanaImagePickerController.titleTextAttributes) + titleView.setAttributedTitle(attributedTitle, for: .normal) + titleView.sizeToFit() + navigationController?.navigationBar.setNeedsLayout() + if let titleLabel = titleView.titleLabel, let imageView = titleView.imageView { + let titleLabelWidth = titleLabel.frame.width + let imageWidth = imageView.frame.width + let space: CGFloat = 2.0 + self.titleView.imageEdgeInsets = UIEdgeInsets(top: 0, left: titleLabelWidth + space, bottom: 0, right: -titleLabelWidth - space) + self.titleView.titleEdgeInsets = UIEdgeInsets(top: 0, left: -imageWidth - space, bottom: 0, right: imageWidth + space) + } + } + + @objc private func didTapTitleView() { + showAlbumList() + transformAnimation() + } + + private func showAlbumList() { + let storyboard = UIStoryboard(name: "AlbumList", bundle: nohanaImagePickerController.assetBundle) + guard let navigationController = storyboard.instantiateInitialViewController() as? UINavigationController else { + fatalError("navigationController init failed.") + } + guard let albumListViewController = navigationController.topViewController as? AlbumListViewController else { + fatalError("albumListViewController is not topViewController.") + } + albumListViewController.photoKitAlbumList = PhotoKitAlbumList(assetCollectionTypes: [.smartAlbum, .album], + assetCollectionSubtypes: nohanaImagePickerController.assetCollectionSubtypes, + mediaType: nohanaImagePickerController.mediaType, + shouldShowEmptyAlbum: nohanaImagePickerController.shouldShowMoment, + ascending: !nohanaImagePickerController.canPickDateSection, + handler: { [weak albumListViewController] in + DispatchQueue.main.async { + albumListViewController?.isLoading = false + albumListViewController?.tableView.reloadData() + } + }) + albumListViewController.nohanaImagePickerController = nohanaImagePickerController + albumListViewController.delegate = self + navigationController.presentationController?.delegate = self + present(navigationController, animated: true, completion: nil) + } + + private func showRecentPhotos() { + albumList = PhotoKitAlbumList( + assetCollectionTypes: [.smartAlbum, .album], + assetCollectionSubtypes: nohanaImagePickerController.assetCollectionSubtypes, + mediaType: nohanaImagePickerController.mediaType, + shouldShowEmptyAlbum: nohanaImagePickerController.shouldShowEmptyAlbum, + ascending: !nohanaImagePickerController.canPickDateSection, + handler: { [weak self] in + guard let self = self else { return } + DispatchQueue.main.async { + let album = self.albumList[0] + self.switchChildViewController(nil, toViewController: self.fetchAssetListViewController(album: album)) + self.updateTitle(title: album.title) + } + }) + } + + private func fetchMomentViewController() -> UIViewController { + guard let momentViewController = UIStoryboard(name: "Moment", bundle: nohanaImagePickerController.assetBundle).instantiateInitialViewController(creator: { corder in + MomentViewController(coder: corder, nohanaImagePickerController: self.nohanaImagePickerController) + }) else { + fatalError("Invalid ViewController") + } + return momentViewController + } + + private func fetchAssetListViewController(album: PhotoKitAssetList) -> UIViewController { + if nohanaImagePickerController.canPickDateSection { + guard let assetListViewController = UIStoryboard(name: "AssetListSelectableDateSection", bundle: nohanaImagePickerController.assetBundle).instantiateInitialViewController(creator: { corder in + AssetListSelectableDateSectionController(coder: corder, nohanaImagePickerController: self.nohanaImagePickerController, photoKitAssetList: album) + }) else { + fatalError("Invalid ViewController") + } + return assetListViewController + } else { + guard let assetListViewController = UIStoryboard(name: "AssetList", bundle: nohanaImagePickerController.assetBundle).instantiateInitialViewController(creator: { corder in + AssetListViewController(coder: corder, nohanaImagePickerController: self.nohanaImagePickerController, photoKitAssetList: album) + }) else { + fatalError("Invalid ViewController") + } + return assetListViewController + } + } + + private func switchChildViewController(_ oldViewController: UIViewController?, toViewController newViewController: UIViewController) { + oldViewController?.willMove(toParent: nil) + newViewController.view.translatesAutoresizingMaskIntoConstraints = false + addChild(newViewController) + view.addSubview(newViewController.view) + + NSLayoutConstraint.activate([ + newViewController.view.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor), + newViewController.view.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor), + newViewController.view.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor), + newViewController.view.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor), + ]) + newViewController.view.layoutIfNeeded() + + oldViewController?.view.removeFromSuperview() + oldViewController?.removeFromParent() + newViewController.didMove(toParent: self) + } + + private func transformAnimation() { + guard let imageView = titleView.imageView else { return } + UIView.animate(withDuration: 0.3, delay: 0.0, options: [.curveEaseInOut], animations: { + if imageView.transform.isIdentity { + let angle = 180 * CGFloat.pi / 180 + imageView.transform = CGAffineTransform(rotationAngle: angle) + } else { + let angle = -360 * CGFloat.pi / 180 + imageView.transform = CGAffineTransform(rotationAngle: angle) + imageView.transform = .identity + } + }) } - */ // MARK: - IBAction @IBAction func didTapDone(_ sender: AnyObject) { @@ -55,5 +190,33 @@ class RootViewController: UIViewController { @IBAction func didTapClose(_ sender: AnyObject) { dismiss(animated: true) } +} +extension RootViewController: AlbumListViewControllerDelegate { + func didSelectMoment() { + switchChildViewController(currentChildViewController, toViewController: fetchMomentViewController()) + let title = NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") + updateTitle(title: title) + setToolbarTitle(nohanaImagePickerController) + } + + func didSelectAlbum(album: PhotoKitAssetList) { + switchChildViewController(currentChildViewController, toViewController: fetchAssetListViewController(album: album)) + updateTitle(title: album.title) + setToolbarTitle(nohanaImagePickerController) + } + + func didDissmissViewController(viewController: AlbumListViewController) { + transformAnimation() + } +} + +extension RootViewController: UIAdaptivePresentationControllerDelegate { + func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool { + return true + } + + func presentationControllerDidDismiss(_ presentationController: UIPresentationController) { + transformAnimation() + } } From ea6a0f306152123e0d3c895a3d22183a951e8221 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Thu, 23 Dec 2021 16:54:52 +0900 Subject: [PATCH 15/33] Removed toolbar form albumlist. --- NohanaImagePicker/AlbumList.storyboard | 7 ------- NohanaImagePicker/AlbumListViewController.swift | 2 -- 2 files changed, 9 deletions(-) diff --git a/NohanaImagePicker/AlbumList.storyboard b/NohanaImagePicker/AlbumList.storyboard index a3838ab..07614ba 100644 --- a/NohanaImagePicker/AlbumList.storyboard +++ b/NohanaImagePicker/AlbumList.storyboard @@ -115,13 +115,6 @@ - - - - - - - diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index f736d96..f6531cd 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -50,8 +50,6 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity if let nohanaImagePickerController = nohanaImagePickerController { view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("albumlist.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") - setUpToolbarItems() - navigationController?.setToolbarHidden(nohanaImagePickerController.toolbarHidden, animated: false) } setUpEmptyIndicator() setUpActivityIndicator() From d4d60d9ea01785008b2e262f6114ac07305fd0b3 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Fri, 17 Dec 2021 16:55:13 +0900 Subject: [PATCH 16/33] Removed disclosureIndicator. --- NohanaImagePicker/AlbumList.storyboard | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/NohanaImagePicker/AlbumList.storyboard b/NohanaImagePicker/AlbumList.storyboard index 07614ba..d38a27a 100644 --- a/NohanaImagePicker/AlbumList.storyboard +++ b/NohanaImagePicker/AlbumList.storyboard @@ -16,11 +16,11 @@ - + - + @@ -31,7 +31,7 @@ - + - + diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index f6531cd..47bf38f 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -190,9 +190,10 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity // MARK: - IBAction - @IBAction func didPushCancel(_ sender: AnyObject) { - if let nohanaImagePickerController = nohanaImagePickerController { - nohanaImagePickerController.delegate?.nohanaImagePickerDidCancel(nohanaImagePickerController) + @IBAction func didTapClose(_ sender: AnyObject) { + dismiss(animated: true) { [weak self] in + guard let self = self else { return } + self.delegate?.didDissmissViewController(viewController: self) } } From 0c13e73d40ccc46232f823a8af1f67f18065bce2 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Mon, 20 Dec 2021 14:48:10 +0900 Subject: [PATCH 18/33] Fixed navigationbar appearance. --- .../AlbumListViewController.swift | 19 +++++++++++++++++++ .../NohanaImagePicker.storyboard | 2 +- .../NohanaImagePickerController.swift | 8 ++++++++ NohanaImagePicker/RootViewController.swift | 6 ++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index 47bf38f..c491d67 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -50,6 +50,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity if let nohanaImagePickerController = nohanaImagePickerController { view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("albumlist.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") + navigationItem.leftBarButtonItem?.tintColor = nohanaImagePickerController.config.color.navigationBarForeground } setUpEmptyIndicator() setUpActivityIndicator() @@ -275,6 +276,24 @@ extension UIViewController { titleLabel.sizeToFit() } } + + // MARK: UINavigationBarAppearance + func navigationBarAppearance(_ nohanaImagePickerController: NohanaImagePickerController) -> UINavigationBarAppearance { + let appearance = UINavigationBarAppearance() + appearance.configureWithOpaqueBackground() + appearance.backgroundColor = nohanaImagePickerController.config.color.navigationBarBackground + appearance.titleTextAttributes = [ + .foregroundColor: nohanaImagePickerController.config.color.navigationBarForeground, + .font: UIFont.systemFont(ofSize: 17, weight: .semibold) + ] + let donebuttonAppearance = UIBarButtonItemAppearance() + donebuttonAppearance.normal.titleTextAttributes = [ + .foregroundColor: nohanaImagePickerController.config.color.navigationBarForeground, + .font: UIFont.systemFont(ofSize: 17, weight: .semibold) + ] + appearance.doneButtonAppearance = donebuttonAppearance + return appearance + } // MARK: - Notification diff --git a/NohanaImagePicker/NohanaImagePicker.storyboard b/NohanaImagePicker/NohanaImagePicker.storyboard index 4fb2bde..9cd34b2 100644 --- a/NohanaImagePicker/NohanaImagePicker.storyboard +++ b/NohanaImagePicker/NohanaImagePicker.storyboard @@ -27,7 +27,7 @@ - + diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index 9a3e8f1..ecb7922 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -118,6 +118,12 @@ open class NohanaImagePickerController: UIViewController { return UINavigationController(rootViewController: rootViewController) } }() + + let appearance = navigationBarAppearance(self) + navigationController.navigationBar.standardAppearance = appearance + navigationController.navigationBar.scrollEdgeAppearance = appearance + navigationController.navigationBar.compactAppearance = appearance + addChild(navigationController) view.addSubview(navigationController.view) NSLayoutConstraint.activate([ @@ -149,6 +155,8 @@ extension NohanaImagePickerController { public var background: UIColor? public var empty: UIColor? public var separator: UIColor? + public var navigationBarBackground: UIColor = .white + public var navigationBarForeground: UIColor = .black } public var color = Color() diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index 81fc95f..5f1004d 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -41,8 +41,10 @@ class RootViewController: UIViewController { super.viewDidLoad() // titleView + titleView.tintColor = nohanaImagePickerController.config.color.navigationBarForeground titleView.addTarget(self, action: #selector(didTapTitleView), for: .touchUpInside) navigationItem.titleView = titleView + navigationItem.leftBarButtonItem?.tintColor = nohanaImagePickerController.config.color.navigationBarForeground // toolbar navigationController?.setToolbarHidden(nohanaImagePickerController.toolbarHidden, animated: false) @@ -101,6 +103,10 @@ class RootViewController: UIViewController { albumListViewController.nohanaImagePickerController = nohanaImagePickerController albumListViewController.delegate = self navigationController.presentationController?.delegate = self + let appearance = navigationBarAppearance(nohanaImagePickerController) + navigationController.navigationBar.standardAppearance = appearance + navigationController.navigationBar.scrollEdgeAppearance = appearance + navigationController.navigationBar.compactAppearance = appearance present(navigationController, animated: true, completion: nil) } From 8f497b4c71392ff9b6faab28c28bc1e04f144ea7 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Mon, 20 Dec 2021 16:44:36 +0900 Subject: [PATCH 19/33] Fixed toolbar appearance. --- .../AlbumListViewController.swift | 7 +++++++ .../NohanaImagePickerController.swift | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index c491d67..909b4eb 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -277,6 +277,13 @@ extension UIViewController { } } + func toolBarAppearance(_ nohanaImagePickerController: NohanaImagePickerController) -> UIToolbarAppearance { + let appearance = UIToolbarAppearance() + appearance.configureWithDefaultBackground() + appearance.backgroundColor = nohanaImagePickerController.config.color.navigationBarBackground + return appearance + } + // MARK: UINavigationBarAppearance func navigationBarAppearance(_ nohanaImagePickerController: NohanaImagePickerController) -> UINavigationBarAppearance { let appearance = UINavigationBarAppearance() diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index ecb7922..9239d51 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -119,11 +119,20 @@ open class NohanaImagePickerController: UIViewController { } }() - let appearance = navigationBarAppearance(self) - navigationController.navigationBar.standardAppearance = appearance - navigationController.navigationBar.scrollEdgeAppearance = appearance - navigationController.navigationBar.compactAppearance = appearance - + let navigationBarAppearance = navigationBarAppearance(self) + navigationController.navigationBar.standardAppearance = navigationBarAppearance + navigationController.navigationBar.scrollEdgeAppearance = navigationBarAppearance + navigationController.navigationBar.compactAppearance = navigationBarAppearance + navigationController.navigationBar.tintColor = config.color.navigationBarForeground + + let toobarAppearance = toolBarAppearance(self) + navigationController.toolbar.standardAppearance = toobarAppearance + if #available(iOS 15.0, *) { + navigationController.toolbar.scrollEdgeAppearance = toobarAppearance + } + navigationController.toolbar.compactAppearance = toobarAppearance + navigationController.toolbar.tintColor = config.color.navigationBarForeground + addChild(navigationController) view.addSubview(navigationController.view) NSLayoutConstraint.activate([ From 70a99d9972f494c9efe7bf0e944ead2f4f126171 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Thu, 23 Dec 2021 17:13:42 +0900 Subject: [PATCH 20/33] Remove unnecessary code. --- .../AssetDetailListViewController.swift | 4 ---- .../AssetListSelectableDateSectionController.swift | 13 +------------ NohanaImagePicker/AssetListViewController.swift | 12 +----------- NohanaImagePicker/MomentViewController.swift | 13 +------------ 4 files changed, 3 insertions(+), 39 deletions(-) diff --git a/NohanaImagePicker/AssetDetailListViewController.swift b/NohanaImagePicker/AssetDetailListViewController.swift index bd71062..e1f0d66 100644 --- a/NohanaImagePicker/AssetDetailListViewController.swift +++ b/NohanaImagePicker/AssetDetailListViewController.swift @@ -58,10 +58,6 @@ class AssetDetailListViewController: AssetListViewController, DetailListViewCont } } - override func updateTitle() { - self.title = "" - } - func didChangeAssetDetailPage(_ indexPath: IndexPath) { let asset = photoKitAssetList[indexPath.item] pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index b0c570d..ebacd64 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -46,7 +46,6 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white - updateTitle() setUpToolbarItems() addPickPhotoKitAssetNotificationObservers() setUpActivityIndicator() @@ -63,10 +62,6 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo setToolbarTitle(nohanaImagePickerController) collectionView?.reloadData() } - - func updateTitle() { - title = photoKitAssetList.title - } func scrollCollectionView(to indexPath: IndexPath) { let count: Int? = dateSectionList.count @@ -237,13 +232,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo assetListDetailViewController.currentIndexPath = IndexPath(item: assetListDetailCurrentRow, section: 0) } - // MARK: - IBAction - - @IBAction func didPushDone(_ sender: AnyObject) { - let pickedPhotoKitAssets = nohanaImagePickerController.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset } - nohanaImagePickerController.delegate?.nohanaImagePicker(nohanaImagePickerController, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets) - } - + // MARK: - IBSegueAction @IBSegueAction func makeDetailList(_ coder: NSCoder) -> AssetDetailListViewController? { AssetDetailListViewController(coder: coder, nohanaImagePickerController: nohanaImagePickerController, photoKitAssetList: photoKitAssetList) } diff --git a/NohanaImagePicker/AssetListViewController.swift b/NohanaImagePicker/AssetListViewController.swift index ff8bb51..df4665d 100644 --- a/NohanaImagePicker/AssetListViewController.swift +++ b/NohanaImagePicker/AssetListViewController.swift @@ -35,7 +35,6 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white - updateTitle() setUpToolbarItems() addPickPhotoKitAssetNotificationObservers() } @@ -77,10 +76,6 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg var isFirstAppearance = true - func updateTitle() { - title = photoKitAssetList.title - } - func scrollCollectionView(to indexPath: IndexPath) { guard photoKitAssetList.count > 0 else { return @@ -200,12 +195,7 @@ class AssetListViewController: UICollectionViewController, UICollectionViewDeleg assetListDetailViewController.currentIndexPath = selectedIndexPath } - // MARK: - IBAction - @IBAction func didPushDone(_ sender: AnyObject) { - let pickedPhotoKitAssets = nohanaImagePickerController.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset } - nohanaImagePickerController.delegate?.nohanaImagePicker(nohanaImagePickerController, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets ) - } - + // MARK: - IBSegueAction @IBSegueAction func makeDetailList(_ coder: NSCoder) -> AssetDetailListViewController? { return AssetDetailListViewController(coder: coder, nohanaImagePickerController: nohanaImagePickerController, photoKitAssetList: photoKitAssetList) } diff --git a/NohanaImagePicker/MomentViewController.swift b/NohanaImagePicker/MomentViewController.swift index 22b5467..6ec3424 100644 --- a/NohanaImagePicker/MomentViewController.swift +++ b/NohanaImagePicker/MomentViewController.swift @@ -45,7 +45,6 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white - updateTitle() setUpToolbarItems() addPickPhotoKitAssetNotificationObservers() setUpActivityIndicator() @@ -67,10 +66,6 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe scrollCollectionViewToInitialPosition() } - func updateTitle() { - title = NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") - } - func scrollCollectionView(to indexPath: IndexPath) { let count: Int? = momentInfoSectionList.count guard count != nil && count! > 0 else { @@ -240,13 +235,7 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe momentDetailListViewController.currentIndexPath = selectedIndexPath } - // MARK: - IBAction - - @IBAction func didPushDone(_ sender: AnyObject) { - let pickedPhotoKitAssets = nohanaImagePickerController.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset } - nohanaImagePickerController.delegate?.nohanaImagePicker(nohanaImagePickerController, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets) - } - + // MARK: - IBSegueAction @IBSegueAction func makeMomentDetail(_ coder: NSCoder) -> MomentDetailListViewController? { return MomentDetailListViewController(coder: coder, nohanaImagePickerController: nohanaImagePickerController) } From 7fd2f9d93b9dd76767823242bb27b0faee7d23e9 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Mon, 20 Dec 2021 15:51:31 +0900 Subject: [PATCH 21/33] Fixed title. --- 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, 4 insertions(+), 4 deletions(-) diff --git a/NohanaImagePicker/de.lproj/NohanaImagePicker.strings b/NohanaImagePicker/de.lproj/NohanaImagePicker.strings index 0347625..c24dae1 100644 --- a/NohanaImagePicker/de.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/de.lproj/NohanaImagePicker.strings @@ -14,7 +14,7 @@ * limitations under the License. */ -"albumlist.title" = "Fotos"; +"albumlist.title" = "Fotos auswählen"; "albumlist.empty.message" = "Keine Fotos"; "albumlist.empty.description" = "Nimm Fotos mit der Kamera App auf."; "albumlist.moment.title" = "Moment"; diff --git a/NohanaImagePicker/en.lproj/NohanaImagePicker.strings b/NohanaImagePicker/en.lproj/NohanaImagePicker.strings index d986642..2d3d601 100644 --- a/NohanaImagePicker/en.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/en.lproj/NohanaImagePicker.strings @@ -14,7 +14,7 @@ * limitations under the License. */ -"albumlist.title" = "Photos"; +"albumlist.title" = "Select Photos"; "albumlist.empty.message" = "No Photos"; "albumlist.empty.description" = "Take some photos with Camera app."; "albumlist.moment.title" = "Moment"; diff --git a/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings b/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings index fa8ac94..ef56da8 100644 --- a/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings @@ -14,7 +14,7 @@ * limitations under the License. */ -"albumlist.title" = "アルバム"; +"albumlist.title" = "アルバムを選択"; "albumlist.empty.message" = "アルバムに\n写真がありません"; "albumlist.empty.description" = "カメラで写真を撮影しましょう"; "albumlist.moment.title" = "日付から選択"; diff --git a/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings b/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings index a36bb98..50351b0 100644 --- a/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings @@ -14,7 +14,7 @@ * limitations under the License. */ -"albumlist.title" = "Фотографии"; +"albumlist.title" = "Выберите фотографии"; "albumlist.empty.message" = "Нет фотографий"; "albumlist.empty.description" = "Получить фото с камеры"; "albumlist.moment.title" = "Моменты"; From cbea2d39e4be54f0cccd21f287d575a3aea0a017 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Thu, 23 Dec 2021 17:17:42 +0900 Subject: [PATCH 22/33] Fixed button style. --- NohanaImagePicker/AlbumList.storyboard | 2 +- NohanaImagePicker/NohanaImagePicker.storyboard | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NohanaImagePicker/AlbumList.storyboard b/NohanaImagePicker/AlbumList.storyboard index ba6231b..9564423 100644 --- a/NohanaImagePicker/AlbumList.storyboard +++ b/NohanaImagePicker/AlbumList.storyboard @@ -86,7 +86,7 @@ - + diff --git a/NohanaImagePicker/NohanaImagePicker.storyboard b/NohanaImagePicker/NohanaImagePicker.storyboard index 9cd34b2..47edb99 100644 --- a/NohanaImagePicker/NohanaImagePicker.storyboard +++ b/NohanaImagePicker/NohanaImagePicker.storyboard @@ -22,7 +22,7 @@ - + From 15baab23cddd93a306c71b458ba255f752b101f4 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Mon, 20 Dec 2021 17:52:04 +0900 Subject: [PATCH 23/33] Fixed build with xcode12. --- NohanaImagePicker/NohanaImagePickerController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index 9239d51..76ea7cf 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -127,9 +127,11 @@ open class NohanaImagePickerController: UIViewController { let toobarAppearance = toolBarAppearance(self) navigationController.toolbar.standardAppearance = toobarAppearance +#if swift(>=5.5) if #available(iOS 15.0, *) { navigationController.toolbar.scrollEdgeAppearance = toobarAppearance } +#endif navigationController.toolbar.compactAppearance = toobarAppearance navigationController.toolbar.tintColor = config.color.navigationBarForeground From 50106167425beab46b5b07cd5a340583fa20a0b7 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Fri, 24 Dec 2021 10:53:18 +0900 Subject: [PATCH 24/33] Fixed init with album list. --- NohanaImagePicker/AlbumList.storyboard | 26 +---------- .../AlbumListViewController.swift | 43 ++++++++----------- NohanaImagePicker/RootViewController.swift | 12 +++--- 3 files changed, 25 insertions(+), 56 deletions(-) diff --git a/NohanaImagePicker/AlbumList.storyboard b/NohanaImagePicker/AlbumList.storyboard index 9564423..ff5fa04 100644 --- a/NohanaImagePicker/AlbumList.storyboard +++ b/NohanaImagePicker/AlbumList.storyboard @@ -1,5 +1,5 @@ - + @@ -99,30 +99,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index 909b4eb..038e6f1 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -41,17 +41,24 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity } } - weak var nohanaImagePickerController: NohanaImagePickerController? + let nohanaImagePickerController: NohanaImagePickerController var photoKitAlbumList: PhotoKitAlbumList! weak var delegate: AlbumListViewControllerDelegate? + + init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController) { + self.nohanaImagePickerController = nohanaImagePickerController + super.init(coder: coder) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } override func viewDidLoad() { super.viewDidLoad() - if let nohanaImagePickerController = nohanaImagePickerController { - view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white - title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("albumlist.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") - navigationItem.leftBarButtonItem?.tintColor = nohanaImagePickerController.config.color.navigationBarForeground - } + view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white + title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("albumlist.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") + navigationItem.leftBarButtonItem?.tintColor = nohanaImagePickerController.config.color.navigationBarForeground setUpEmptyIndicator() setUpActivityIndicator() } @@ -62,9 +69,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - if let nohanaImagePickerController = nohanaImagePickerController { - setToolbarTitle(nohanaImagePickerController) - } + setToolbarTitle(nohanaImagePickerController) if let indexPathForSelectedRow = tableView.indexPathForSelectedRow { tableView.deselectRow(at: indexPathForSelectedRow, animated: true) } @@ -81,9 +86,6 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity guard let sectionType = AlbumListViewControllerSectionType(rawValue: indexPath.section) else { fatalError("Invalid section") } - guard let nohanaImagePickerController = nohanaImagePickerController else { - return - } switch sectionType { case .moment: delegate?.didSelectMoment() @@ -134,11 +136,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity switch sectionType { case .moment: - if let nohanaImagePickerController = nohanaImagePickerController { - return nohanaImagePickerController.shouldShowMoment ? 1 : 0 - } - return 0 - + return nohanaImagePickerController.shouldShowMoment ? 1 : 0 case .albums: return photoKitAlbumList.count } @@ -154,10 +152,8 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity guard let cell = tableView.dequeueReusableCell(withIdentifier: "MomentAlbumCell") as? MomentCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"MomentAlbumCell\")") } - if let nohanaImagePickerController = nohanaImagePickerController { - cell.config = nohanaImagePickerController.config - cell.titleLabel?.text = nohanaImagePickerController.config.strings.albumListMomentTitle ?? NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") - } + cell.config = nohanaImagePickerController.config + cell.titleLabel?.text = nohanaImagePickerController.config.strings.albumListMomentTitle ?? NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") return cell case .albums: guard let cell = tableView.dequeueReusableCell(withIdentifier: "AlbumCell") as? AlbumCell else { @@ -172,7 +168,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity ) let albumCount = albumList.count if albumCount > 0 { - let lastAsset = nohanaImagePickerController?.canPickDateSection ?? false ? albumList[0] : albumList[albumCount - 1] + let lastAsset = nohanaImagePickerController.canPickDateSection ? albumList[0] : albumList[albumCount - 1] lastAsset.image(targetSize: imageSize, handler: { (imageData) -> Void in DispatchQueue.main.async(execute: { () -> Void in if let imageData = imageData { @@ -204,9 +200,6 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity func setUpEmptyIndicator() { let frame = CGRect(origin: CGPoint.zero, size: Size.screenRectWithoutAppBar(self).size) - guard let nohanaImagePickerController = nohanaImagePickerController else { - return - } emptyIndicator = AlbumListEmptyIndicator( message: nohanaImagePickerController.config.strings.albumListEmptyMessage ?? NSLocalizedString("albumlist.empty.message", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""), description: nohanaImagePickerController.config.strings.albumListEmptyDescription ?? NSLocalizedString("albumlist.empty.description", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""), diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index 5f1004d..88b5a11 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -83,12 +83,13 @@ class RootViewController: UIViewController { private func showAlbumList() { let storyboard = UIStoryboard(name: "AlbumList", bundle: nohanaImagePickerController.assetBundle) - guard let navigationController = storyboard.instantiateInitialViewController() as? UINavigationController else { - fatalError("navigationController init failed.") - } - guard let albumListViewController = navigationController.topViewController as? AlbumListViewController else { - fatalError("albumListViewController is not topViewController.") + guard let albumListViewController = storyboard.instantiateInitialViewController(creator: { corder in + AlbumListViewController(coder: corder, nohanaImagePickerController: self.nohanaImagePickerController) + }) else { + fatalError("albumListViewController init failed.") } + let navigationController = UINavigationController(rootViewController: albumListViewController) + albumListViewController.photoKitAlbumList = PhotoKitAlbumList(assetCollectionTypes: [.smartAlbum, .album], assetCollectionSubtypes: nohanaImagePickerController.assetCollectionSubtypes, mediaType: nohanaImagePickerController.mediaType, @@ -100,7 +101,6 @@ class RootViewController: UIViewController { albumListViewController?.tableView.reloadData() } }) - albumListViewController.nohanaImagePickerController = nohanaImagePickerController albumListViewController.delegate = self navigationController.presentationController?.delegate = self let appearance = navigationBarAppearance(nohanaImagePickerController) From 49958f4b1c9389506b90f1c83ed50a2952d115c6 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Fri, 24 Dec 2021 11:10:25 +0900 Subject: [PATCH 25/33] Migrated UIViewcontroller extension. --- NohanaImagePicker.xcodeproj/project.pbxproj | 12 ++- .../AlbumListViewController.swift | 85 --------------- NohanaImagePicker/UIViewController+Ex.swift | 102 ++++++++++++++++++ 3 files changed, 110 insertions(+), 89 deletions(-) create mode 100644 NohanaImagePicker/UIViewController+Ex.swift diff --git a/NohanaImagePicker.xcodeproj/project.pbxproj b/NohanaImagePicker.xcodeproj/project.pbxproj index ed95390..b78f0ee 100644 --- a/NohanaImagePicker.xcodeproj/project.pbxproj +++ b/NohanaImagePicker.xcodeproj/project.pbxproj @@ -8,12 +8,13 @@ /* 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 */; }; - 6AD1607F2770B23D00A8B066 /* UIApplication+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.swift */; }; + 6A434AE72775631C009526D3 /* UIViewController+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A434AE62775631C009526D3 /* UIViewController+Ex.swift */; }; 6A8047FF276C3D77000F3B28 /* AlbumList.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A8047FE276C3D77000F3B28 /* AlbumList.storyboard */; }; 6A804801276C3E80000F3B28 /* Moment.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A804800276C3E80000F3B28 /* Moment.storyboard */; }; 6A804803276C3F01000F3B28 /* AssetList.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A804802276C3F01000F3B28 /* AssetList.storyboard */; }; + 6ACE6617276051F6008AA84D /* ImagePreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ACE6616276051F6008AA84D /* ImagePreviewViewController.swift */; }; 6AD1607C27700F0C00A8B066 /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1607B27700F0C00A8B066 /* RootViewController.swift */; }; + 6AD1607F2770B23D00A8B066 /* UIApplication+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.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 */; }; @@ -88,12 +89,13 @@ 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 = ""; }; - 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Ex.swift"; sourceTree = ""; }; + 6A434AE62775631C009526D3 /* UIViewController+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Ex.swift"; sourceTree = ""; }; 6A8047FE276C3D77000F3B28 /* AlbumList.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AlbumList.storyboard; sourceTree = ""; }; 6A804800276C3E80000F3B28 /* Moment.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Moment.storyboard; sourceTree = ""; }; 6A804802276C3F01000F3B28 /* AssetList.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AssetList.storyboard; sourceTree = ""; }; + 6ACE6616276051F6008AA84D /* ImagePreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePreviewViewController.swift; sourceTree = ""; }; 6AD1607B27700F0C00A8B066 /* RootViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewController.swift; sourceTree = ""; }; + 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Ex.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 = ""; }; @@ -174,6 +176,7 @@ isa = PBXGroup; children = ( 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.swift */, + 6A434AE62775631C009526D3 /* UIViewController+Ex.swift */, ); name = Extension; sourceTree = ""; @@ -453,6 +456,7 @@ buildActionMask = 2147483647; files = ( F1E5DE8226A58386004B9EDE /* MomentInfoSectionCreater.swift in Sources */, + 6A434AE72775631C009526D3 /* UIViewController+Ex.swift in Sources */, F2DF3B171C6C868E00C1C0E4 /* AssetCell.swift in Sources */, F26775E81C7073CD002E786C /* Size.swift in Sources */, F26775DE1C701FA7002E786C /* ItemList.swift in Sources */, diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index 038e6f1..0b915dd 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -231,88 +231,3 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity return isLoading } } - -extension UIViewController { - - // MARK: - Toolbar - - func setUpToolbarItems() { - let leftSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) - let rightSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) - - let label = UILabel() - label.textColor = .black - label.textAlignment = .center - label.font = .systemFont(ofSize: 17) - let labelItem = UIBarButtonItem(customView: label) - self.toolbarItems = [leftSpace, labelItem, rightSpace] - } - - func setToolbarTitle(_ nohanaImagePickerController: NohanaImagePickerController) { - let count: Int? = toolbarItems?.count - guard count != nil && count! >= 2 else { - return - } - guard let labelItem = toolbarItems?[1], let titleLabel = labelItem.customView as? UILabel else { - return - } - if nohanaImagePickerController.maximumNumberOfSelection == 0 { - let title = String(format: nohanaImagePickerController.config.strings.toolbarTitleNoLimit ?? NSLocalizedString("toolbar.title.nolimit", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""), - nohanaImagePickerController.pickedAssetList.count) - titleLabel.text = title - titleLabel.sizeToFit() - } else { - let title = String(format: nohanaImagePickerController.config.strings.toolbarTitleHasLimit ?? NSLocalizedString("toolbar.title.haslimit", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""), - nohanaImagePickerController.pickedAssetList.count, - nohanaImagePickerController.maximumNumberOfSelection) - titleLabel.text = title - titleLabel.sizeToFit() - } - } - - func toolBarAppearance(_ nohanaImagePickerController: NohanaImagePickerController) -> UIToolbarAppearance { - let appearance = UIToolbarAppearance() - appearance.configureWithDefaultBackground() - appearance.backgroundColor = nohanaImagePickerController.config.color.navigationBarBackground - return appearance - } - - // MARK: UINavigationBarAppearance - func navigationBarAppearance(_ nohanaImagePickerController: NohanaImagePickerController) -> UINavigationBarAppearance { - let appearance = UINavigationBarAppearance() - appearance.configureWithOpaqueBackground() - appearance.backgroundColor = nohanaImagePickerController.config.color.navigationBarBackground - appearance.titleTextAttributes = [ - .foregroundColor: nohanaImagePickerController.config.color.navigationBarForeground, - .font: UIFont.systemFont(ofSize: 17, weight: .semibold) - ] - let donebuttonAppearance = UIBarButtonItemAppearance() - donebuttonAppearance.normal.titleTextAttributes = [ - .foregroundColor: nohanaImagePickerController.config.color.navigationBarForeground, - .font: UIFont.systemFont(ofSize: 17, weight: .semibold) - ] - appearance.doneButtonAppearance = donebuttonAppearance - return appearance - } - - // MARK: - Notification - - func addPickPhotoKitAssetNotificationObservers() { - NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didPickPhotoKitAsset(_:)), name: NotificationInfo.Asset.PhotoKit.didPick, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didDropPhotoKitAsset(_:)), name: NotificationInfo.Asset.PhotoKit.didDrop, object: nil) - } - - @objc func didPickPhotoKitAsset(_ notification: Notification) { - guard let picker = notification.object as? NohanaImagePickerController else { - return - } - setToolbarTitle(picker) - } - - @objc func didDropPhotoKitAsset(_ notification: Notification) { - guard let picker = notification.object as? NohanaImagePickerController else { - return - } - setToolbarTitle(picker) - } -} diff --git a/NohanaImagePicker/UIViewController+Ex.swift b/NohanaImagePicker/UIViewController+Ex.swift new file mode 100644 index 0000000..bfab9d0 --- /dev/null +++ b/NohanaImagePicker/UIViewController+Ex.swift @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2016 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 + +extension UIViewController { + + // MARK: - Toolbar + + func setUpToolbarItems() { + let leftSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) + let rightSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) + + let label = UILabel() + label.textColor = .black + label.textAlignment = .center + label.font = .systemFont(ofSize: 17) + let labelItem = UIBarButtonItem(customView: label) + self.toolbarItems = [leftSpace, labelItem, rightSpace] + } + + func setToolbarTitle(_ nohanaImagePickerController: NohanaImagePickerController) { + let count: Int? = toolbarItems?.count + guard count != nil && count! >= 2 else { + return + } + guard let labelItem = toolbarItems?[1], let titleLabel = labelItem.customView as? UILabel else { + return + } + if nohanaImagePickerController.maximumNumberOfSelection == 0 { + let title = String(format: nohanaImagePickerController.config.strings.toolbarTitleNoLimit ?? NSLocalizedString("toolbar.title.nolimit", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""), + nohanaImagePickerController.pickedAssetList.count) + titleLabel.text = title + titleLabel.sizeToFit() + } else { + let title = String(format: nohanaImagePickerController.config.strings.toolbarTitleHasLimit ?? NSLocalizedString("toolbar.title.haslimit", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""), + nohanaImagePickerController.pickedAssetList.count, + nohanaImagePickerController.maximumNumberOfSelection) + titleLabel.text = title + titleLabel.sizeToFit() + } + } + + func toolBarAppearance(_ nohanaImagePickerController: NohanaImagePickerController) -> UIToolbarAppearance { + let appearance = UIToolbarAppearance() + appearance.configureWithDefaultBackground() + appearance.backgroundColor = nohanaImagePickerController.config.color.navigationBarBackground + return appearance + } + + // MARK: UINavigationBarAppearance + func navigationBarAppearance(_ nohanaImagePickerController: NohanaImagePickerController) -> UINavigationBarAppearance { + let appearance = UINavigationBarAppearance() + appearance.configureWithOpaqueBackground() + appearance.backgroundColor = nohanaImagePickerController.config.color.navigationBarBackground + appearance.titleTextAttributes = [ + .foregroundColor: nohanaImagePickerController.config.color.navigationBarForeground, + .font: UIFont.systemFont(ofSize: 17, weight: .semibold) + ] + let donebuttonAppearance = UIBarButtonItemAppearance() + donebuttonAppearance.normal.titleTextAttributes = [ + .foregroundColor: nohanaImagePickerController.config.color.navigationBarForeground, + .font: UIFont.systemFont(ofSize: 17, weight: .semibold) + ] + appearance.doneButtonAppearance = donebuttonAppearance + return appearance + } + + // MARK: - Notification + + func addPickPhotoKitAssetNotificationObservers() { + NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didPickPhotoKitAsset(_:)), name: NotificationInfo.Asset.PhotoKit.didPick, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didDropPhotoKitAsset(_:)), name: NotificationInfo.Asset.PhotoKit.didDrop, object: nil) + } + + @objc func didPickPhotoKitAsset(_ notification: Notification) { + guard let picker = notification.object as? NohanaImagePickerController else { + return + } + setToolbarTitle(picker) + } + + @objc func didDropPhotoKitAsset(_ notification: Notification) { + guard let picker = notification.object as? NohanaImagePickerController else { + return + } + setToolbarTitle(picker) + } +} From 990499c2aeff46961de618556df0ce20d1b9508f Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Fri, 24 Dec 2021 11:16:36 +0900 Subject: [PATCH 26/33] Fixed done button attributes. --- NohanaImagePicker/RootViewController.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index 88b5a11..a8ffc6c 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -59,6 +59,13 @@ class RootViewController: UIViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) setToolbarTitle(nohanaImagePickerController) + + // FIXME: The settings of UIBarButtonItemAppearance may not be reflected. + // Probably, this problem occurs when the settings are set to reflect the entire application. + navigationItem.rightBarButtonItem?.setTitleTextAttributes([ + .foregroundColor: nohanaImagePickerController.config.color.navigationBarForeground, + .font: UIFont.systemFont(ofSize: 17, weight: .semibold) + ], for: .normal) } // MARK: Private From 2c3d320bce501e94ce8416b423f7dc74c25f20aa Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Fri, 24 Dec 2021 14:12:55 +0900 Subject: [PATCH 27/33] Fixed init with moment detail. --- .../MomentDetailListViewController.swift | 22 ++++++++----------- NohanaImagePicker/MomentViewController.swift | 16 ++++---------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/NohanaImagePicker/MomentDetailListViewController.swift b/NohanaImagePicker/MomentDetailListViewController.swift index f7a8637..9ceae51 100644 --- a/NohanaImagePicker/MomentDetailListViewController.swift +++ b/NohanaImagePicker/MomentDetailListViewController.swift @@ -18,7 +18,7 @@ import UIKit final class MomentDetailListViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, DetailListViewControllerProtocol { - var currentIndexPath: IndexPath = IndexPath() { + var currentIndexPath: IndexPath { willSet { if currentIndexPath != newValue { didChangeAssetDetailPage(newValue) @@ -33,11 +33,13 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec } let nohanaImagePickerController: NohanaImagePickerController - var momentInfoSection: MomentInfoSection? + let momentInfoSection: MomentInfoSection var isFirstAppearance = true - init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController) { + init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController, momentInfoSection: MomentInfoSection, currentIndexPath: IndexPath) { self.nohanaImagePickerController = nohanaImagePickerController + self.momentInfoSection = momentInfoSection + self.currentIndexPath = currentIndexPath super.init(coder: coder) } @@ -98,9 +100,6 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec } func didChangeAssetDetailPage(_ indexPath: IndexPath) { - guard let momentInfoSection = momentInfoSection else { - return - } let asset = PhotoKitAsset(asset: momentInfoSection.assetResult[indexPath.item]) pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset) pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset)) @@ -108,7 +107,7 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec } func scrollCollectionView(to indexPath: IndexPath) { - guard let count = momentInfoSection?.assetResult.count, count > 0 else { + guard momentInfoSection.assetResult.count > 0 else { return } DispatchQueue.main.async { @@ -129,19 +128,17 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec // MARK: - UICollectionViewDataSource override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return momentInfoSection?.assetResult.count ?? 0 + return momentInfoSection.assetResult.count } // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - if let momentInfoSection = momentInfoSection { - nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: momentInfoSection.assetResult[indexPath.item]) - } + nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: momentInfoSection.assetResult[indexPath.item]) } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetDetailCell", for: indexPath) as? AssetDetailCell, let momentInfoSection = momentInfoSection else { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetDetailCell", for: indexPath) as? AssetDetailCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetDetailCell\")") } cell.scrollView.zoomScale = 1 @@ -191,7 +188,6 @@ final class MomentDetailListViewController: UICollectionViewController, UICollec // MARK: - IBAction @IBAction func didPushPickButton(_ sender: UIButton) { - guard let momentInfoSection = momentInfoSection else { return } let asset = PhotoKitAsset(asset: momentInfoSection.assetResult[currentIndexPath.item]) if pickButton.isSelected { if nohanaImagePickerController.pickedAssetList.drop(asset: asset) { diff --git a/NohanaImagePicker/MomentViewController.swift b/NohanaImagePicker/MomentViewController.swift index 6ec3424..e53c74a 100644 --- a/NohanaImagePicker/MomentViewController.swift +++ b/NohanaImagePicker/MomentViewController.swift @@ -224,19 +224,11 @@ final class MomentViewController: UICollectionViewController, UICollectionViewDe } } - // MARK: - Storyboard - - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - guard let selectedIndexPath = collectionView?.indexPathsForSelectedItems?.first else { - return - } - let momentDetailListViewController = segue.destination as! MomentDetailListViewController - momentDetailListViewController.momentInfoSection = momentInfoSectionList[selectedIndexPath.section] - momentDetailListViewController.currentIndexPath = selectedIndexPath - } - // MARK: - IBSegueAction @IBSegueAction func makeMomentDetail(_ coder: NSCoder) -> MomentDetailListViewController? { - return MomentDetailListViewController(coder: coder, nohanaImagePickerController: nohanaImagePickerController) + guard let selectedIndexPath = collectionView?.indexPathsForSelectedItems?.first else { + return nil + } + return MomentDetailListViewController(coder: coder, nohanaImagePickerController: nohanaImagePickerController, momentInfoSection: momentInfoSectionList[selectedIndexPath.section], currentIndexPath: selectedIndexPath) } } From 6421087c989f40f8a498ef80628353f160e844dd Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Tue, 28 Dec 2021 12:09:31 +0900 Subject: [PATCH 28/33] Fixed call delegate function. --- NohanaImagePicker/RootViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index a8ffc6c..1637693 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -201,7 +201,7 @@ class RootViewController: UIViewController { } @IBAction func didTapClose(_ sender: AnyObject) { - dismiss(animated: true) + nohanaImagePickerController.delegate?.nohanaImagePickerDidCancel(nohanaImagePickerController) } } From bc04b5eed1825a4dcdaf6cd0e9c9477390c98979 Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Tue, 28 Dec 2021 12:22:50 +0900 Subject: [PATCH 29/33] Remove unnecessary code. --- NohanaImagePicker/NohanaImagePickerController.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index 76ea7cf..fc191df 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -154,10 +154,6 @@ open class NohanaImagePickerController: UIViewController { open func dropAsset(_ asset: Asset) { _ = pickedAssetList.drop(asset: asset) } - - open override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - print(#function) - } } extension NohanaImagePickerController { From 48f0f5f9f3ab6c456d10991deab62b706134dbbf Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Tue, 4 Jan 2022 17:29:35 +0900 Subject: [PATCH 30/33] Modified animation timing. --- .../AlbumListViewController.swift | 20 +++++++------------ NohanaImagePicker/RootViewController.swift | 12 +++++++++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index 0b915dd..1a4bc59 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -20,7 +20,7 @@ import Photos protocol AlbumListViewControllerDelegate: AnyObject { func didSelectMoment() func didSelectAlbum(album: PhotoKitAssetList) - func didDissmissViewController(viewController: AlbumListViewController) + func willDissmissViewController(viewController: AlbumListViewController) } class AlbumListViewController: UITableViewController, EmptyIndicatable, ActivityIndicatable { @@ -90,17 +90,13 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity case .moment: delegate?.didSelectMoment() nohanaImagePickerController.delegate?.nohanaImagePickerDidSelectMoment?(nohanaImagePickerController) - dismiss(animated: true) { [weak self] in - guard let self = self else { return } - self.delegate?.didDissmissViewController(viewController: self) - } + delegate?.willDissmissViewController(viewController: self) + dismiss(animated: true, completion: nil) case .albums: delegate?.didSelectAlbum(album: photoKitAlbumList[indexPath.row]) nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAssetList: photoKitAlbumList[indexPath.row].assetList) - dismiss(animated: true) { [weak self] in - guard let self = self else { return } - self.delegate?.didDissmissViewController(viewController: self) - } + delegate?.willDissmissViewController(viewController: self) + dismiss(animated: true, completion: nil) } } @@ -188,10 +184,8 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity // MARK: - IBAction @IBAction func didTapClose(_ sender: AnyObject) { - dismiss(animated: true) { [weak self] in - guard let self = self else { return } - self.delegate?.didDissmissViewController(viewController: self) - } + delegate?.willDissmissViewController(viewController: self) + dismiss(animated: true, completion: nil) } // MARK: - EmptyIndicatable diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index 1637693..d356d78 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -219,7 +219,7 @@ extension RootViewController: AlbumListViewControllerDelegate { setToolbarTitle(nohanaImagePickerController) } - func didDissmissViewController(viewController: AlbumListViewController) { + func willDissmissViewController(viewController: AlbumListViewController) { transformAnimation() } } @@ -229,7 +229,15 @@ extension RootViewController: UIAdaptivePresentationControllerDelegate { return true } - func presentationControllerDidDismiss(_ presentationController: UIPresentationController) { + func presentationControllerWillDismiss(_ presentationController: UIPresentationController) { transformAnimation() + transitionCoordinator?.animate(alongsideTransition: { context in + //Dismissal is animating. Could be finishing or canceling the dismissal + }, completion: { [weak self] context in + if context.isCancelled { + // cancelled dismiss + self?.transformAnimation() + } + }) } } From 3c2096a5727fdbe7f36ce10d4a71862689c00b9e Mon Sep 17 00:00:00 2001 From: "atsushi.yoshimoto" Date: Tue, 4 Jan 2022 18:03:32 +0900 Subject: [PATCH 31/33] Fixed typo in function name. --- NohanaImagePicker/AlbumListViewController.swift | 8 ++++---- NohanaImagePicker/RootViewController.swift | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index 1a4bc59..57ccd50 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -20,7 +20,7 @@ import Photos protocol AlbumListViewControllerDelegate: AnyObject { func didSelectMoment() func didSelectAlbum(album: PhotoKitAssetList) - func willDissmissViewController(viewController: AlbumListViewController) + func willDismissViewController(viewController: AlbumListViewController) } class AlbumListViewController: UITableViewController, EmptyIndicatable, ActivityIndicatable { @@ -90,12 +90,12 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity case .moment: delegate?.didSelectMoment() nohanaImagePickerController.delegate?.nohanaImagePickerDidSelectMoment?(nohanaImagePickerController) - delegate?.willDissmissViewController(viewController: self) + delegate?.willDismissViewController(viewController: self) dismiss(animated: true, completion: nil) case .albums: delegate?.didSelectAlbum(album: photoKitAlbumList[indexPath.row]) nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAssetList: photoKitAlbumList[indexPath.row].assetList) - delegate?.willDissmissViewController(viewController: self) + delegate?.willDismissViewController(viewController: self) dismiss(animated: true, completion: nil) } } @@ -184,7 +184,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity // MARK: - IBAction @IBAction func didTapClose(_ sender: AnyObject) { - delegate?.willDissmissViewController(viewController: self) + delegate?.willDismissViewController(viewController: self) dismiss(animated: true, completion: nil) } diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index d356d78..2b40d2f 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -219,7 +219,7 @@ extension RootViewController: AlbumListViewControllerDelegate { setToolbarTitle(nohanaImagePickerController) } - func willDissmissViewController(viewController: AlbumListViewController) { + func willDismissViewController(viewController: AlbumListViewController) { transformAnimation() } } From 51bf93d6ecca117573497fbb2d7984d0c7f4c242 Mon Sep 17 00:00:00 2001 From: "naoto.suzuki" Date: Wed, 19 Jan 2022 11:11:44 +0900 Subject: [PATCH 32/33] Added alert. --- NohanaImagePicker/NohanaImagePickerController.swift | 1 + NohanaImagePicker/RootViewController.swift | 12 ++++++++++-- NohanaImagePicker/de.lproj/NohanaImagePicker.strings | 1 + NohanaImagePicker/en.lproj/NohanaImagePicker.strings | 1 + NohanaImagePicker/ja.lproj/NohanaImagePicker.strings | 1 + NohanaImagePicker/ru.lproj/NohanaImagePicker.strings | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index fc191df..e12246e 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -180,6 +180,7 @@ extension NohanaImagePickerController { public var albumListMomentTitle: String? public var albumListEmptyMessage: String? public var albumListEmptyDescription: String? + public var albumListEmptyAlertButtonOK: String? public var toolbarTitleNoLimit: String? public var toolbarTitleHasLimit: String? } diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index 2b40d2f..74858ea 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -126,8 +126,16 @@ class RootViewController: UIViewController { ascending: !nohanaImagePickerController.canPickDateSection, handler: { [weak self] in guard let self = self else { return } - DispatchQueue.main.async { - let album = self.albumList[0] + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + guard let album = self.albumList.first else { + let title = self.nohanaImagePickerController.config.strings.albumListEmptyMessage ?? NSLocalizedString("albumlist.empty.message", tableName: "NohanaImagePicker", bundle: self.nohanaImagePickerController.assetBundle, comment: "") + let ok = self.nohanaImagePickerController.config.strings.albumListEmptyAlertButtonOK ?? NSLocalizedString("albumlist.empty.alert.button.ok", tableName: "NohanaImagePicker", bundle: self.nohanaImagePickerController.assetBundle, comment: "") + let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: ok, style: .cancel, handler: nil)) + self.present(alert, animated: true, completion: nil) + return + } self.switchChildViewController(nil, toViewController: self.fetchAssetListViewController(album: album)) self.updateTitle(title: album.title) } diff --git a/NohanaImagePicker/de.lproj/NohanaImagePicker.strings b/NohanaImagePicker/de.lproj/NohanaImagePicker.strings index c24dae1..8b8b529 100644 --- a/NohanaImagePicker/de.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/de.lproj/NohanaImagePicker.strings @@ -17,6 +17,7 @@ "albumlist.title" = "Fotos auswählen"; "albumlist.empty.message" = "Keine Fotos"; "albumlist.empty.description" = "Nimm Fotos mit der Kamera App auf."; +"albumlist.empty.alert.button.ok" = "OK"; "albumlist.moment.title" = "Moment"; "toolbar.title.nolimit" = "Ausgewählte Fotos: %ld"; "toolbar.title.haslimit" = "Ausgewählte Fotos: %ld / %ld"; diff --git a/NohanaImagePicker/en.lproj/NohanaImagePicker.strings b/NohanaImagePicker/en.lproj/NohanaImagePicker.strings index 2d3d601..8b4dbe4 100644 --- a/NohanaImagePicker/en.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/en.lproj/NohanaImagePicker.strings @@ -17,6 +17,7 @@ "albumlist.title" = "Select Photos"; "albumlist.empty.message" = "No Photos"; "albumlist.empty.description" = "Take some photos with Camera app."; +"albumlist.empty.alert.button.ok" = "OK"; "albumlist.moment.title" = "Moment"; "toolbar.title.nolimit" = "Selected Items: %ld"; "toolbar.title.haslimit" = "Selected Items: %ld / %ld"; diff --git a/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings b/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings index ef56da8..0595dde 100644 --- a/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/ja.lproj/NohanaImagePicker.strings @@ -17,6 +17,7 @@ "albumlist.title" = "アルバムを選択"; "albumlist.empty.message" = "アルバムに\n写真がありません"; "albumlist.empty.description" = "カメラで写真を撮影しましょう"; +"albumlist.empty.alert.button.ok" = "OK"; "albumlist.moment.title" = "日付から選択"; "toolbar.title.nolimit" = "%ld枚選択中"; "toolbar.title.haslimit" = "%ld枚選択中(最大%ld枚)"; diff --git a/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings b/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings index 50351b0..1b6036d 100644 --- a/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings +++ b/NohanaImagePicker/ru.lproj/NohanaImagePicker.strings @@ -17,6 +17,7 @@ "albumlist.title" = "Выберите фотографии"; "albumlist.empty.message" = "Нет фотографий"; "albumlist.empty.description" = "Получить фото с камеры"; +"albumlist.empty.alert.button.ok" = "ла́дно"; "albumlist.moment.title" = "Моменты"; "toolbar.title.nolimit" = "Выбрано: %ld"; "toolbar.title.haslimit" = "Выбрано: %ld / %ld"; From 8220dff606594aea7b124332d2d6099b23bb93d2 Mon Sep 17 00:00:00 2001 From: "naoto.suzuki" Date: Wed, 19 Jan 2022 13:35:44 +0900 Subject: [PATCH 33/33] Modified README. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 777a588..db36c18 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ picker.canPickAsset = { (asset:Asset) -> Bool in ## Requirements -- Swift 2.2 later -- iOS 8.0 later +- Swift 5.0 later +- iOS 13.0 later ## Installation