From 7a20be97a715da5137970b48b1db7464ccd93a2e Mon Sep 17 00:00:00 2001 From: Antoine van der Lee Date: Fri, 19 Feb 2021 10:13:01 +0100 Subject: [PATCH] Allow customizing the order of views and the image size (#52) * Allow customizing the order of views and the image size * Fix tests --- Sources/UINotification.swift | 3 ++ .../UINotificationSystemStyle.swift | 1 + Sources/UINotificationView.swift | 21 +++++++++++--- UINotifications.xcodeproj/project.pbxproj | 17 ++++++----- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++ .../xcschemes/UINotifications.xcscheme | 28 ++++++++----------- .../xcschemes/UINotificationsTests.xcscheme | 6 +--- .../UINotificationDefaultElementsTests.swift | 17 ++++++++++- .../UINotificationDefaultViewTests.swift | 1 + 9 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 UINotifications.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Sources/UINotification.swift b/Sources/UINotification.swift index 31c7088..da29b16 100644 --- a/Sources/UINotification.swift +++ b/Sources/UINotification.swift @@ -33,6 +33,9 @@ public protocol UINotificationStyle { /// The chevron image which is shown when a notification has an action attached. var chevronImage: UIImage? { get } + + /// The size to use for the thumbnail view. + var thumbnailSize: CGSize { get } } /// Handles changes in UINotification diff --git a/Sources/UINotificationStyles/UINotificationSystemStyle.swift b/Sources/UINotificationStyles/UINotificationSystemStyle.swift index fdf366e..62b0bd2 100644 --- a/Sources/UINotificationStyles/UINotificationSystemStyle.swift +++ b/Sources/UINotificationStyles/UINotificationSystemStyle.swift @@ -19,6 +19,7 @@ public struct UINotificationSystemStyle: UINotificationStyle { public var maxWidth: CGFloat? public var interactive: Bool = true public var chevronImage: UIImage? + public var thumbnailSize: CGSize = .init(width: 31, height: 31) public init() { } } diff --git a/Sources/UINotificationView.swift b/Sources/UINotificationView.swift index 8773c17..dc77b04 100644 --- a/Sources/UINotificationView.swift +++ b/Sources/UINotificationView.swift @@ -19,6 +19,9 @@ open class UINotificationView: UIView { /// Will be set by the presenter. Is used to animate the notification view with a pan gesture. var topConstraint: NSLayoutConstraint? + var imageViewWidthConstraint: NSLayoutConstraint? + var imageViewHeightConstraint: NSLayoutConstraint? + /// The limit of translation before we will dismiss the notification. internal let translationDismissLimit: CGFloat = -15 @@ -36,8 +39,13 @@ open class UINotificationView: UIView { return stackView }() + /// Override this to change the order of subviews. For example, to show the subtitle above the title. + open var arrangedSubviews: [UIView] { + return [self.titleLabel, self.subtitleLabel] + } + open private(set) lazy var titlesStackView: UIStackView = { - let stackView = UIStackView(arrangedSubviews: [self.titleLabel, self.subtitleLabel]) + let stackView = UIStackView(arrangedSubviews: arrangedSubviews) stackView.axis = .vertical stackView.spacing = 0 stackView.translatesAutoresizingMaskIntoConstraints = false @@ -110,7 +118,7 @@ open class UINotificationView: UIView { translatesAutoresizingMaskIntoConstraints = false isUserInteractionEnabled = true - layoutMargins = UIEdgeInsets(top: 4, left: 0, bottom: 4, right: 0) + layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) addArrangedSubviewsForContainerStackView() addSubview(containerStackView) @@ -132,6 +140,8 @@ open class UINotificationView: UIView { imageView.image = notification.content.image imageView.isHidden = notification.content.image == nil + imageViewWidthConstraint?.constant = notification.style.thumbnailSize.width + imageViewHeightConstraint?.constant = notification.style.thumbnailSize.height backgroundColor = notification.style.backgroundColor @@ -154,6 +164,9 @@ open class UINotificationView: UIView { /// Called when all constraints should be setup for the notification. Can be overwritten to set your own constraints. /// When setting your own constraints, you should not be calling super. open func setupConstraints() { + imageViewWidthConstraint = imageView.widthAnchor.constraint(equalToConstant: 31) + imageViewHeightConstraint = imageView.heightAnchor.constraint(equalToConstant: 31) + let constraints = [ containerStackView.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor, constant: 18), containerStackView.rightAnchor.constraint(equalTo: layoutMarginsGuide.rightAnchor, constant: -18), @@ -162,8 +175,8 @@ open class UINotificationView: UIView { chevronImageView.widthAnchor.constraint(equalToConstant: chevronImageView.image?.size.width ?? 0), - imageView.widthAnchor.constraint(equalToConstant: 31), - imageView.heightAnchor.constraint(equalToConstant: 31) + imageViewWidthConstraint!, + imageViewHeightConstraint! ] button?.setContentHuggingPriority(.defaultHigh, for: .horizontal) diff --git a/UINotifications.xcodeproj/project.pbxproj b/UINotifications.xcodeproj/project.pbxproj index 9e65036..aff2b42 100644 --- a/UINotifications.xcodeproj/project.pbxproj +++ b/UINotifications.xcodeproj/project.pbxproj @@ -257,7 +257,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 1010; + LastUpgradeCheck = 1230; ORGANIZATIONNAME = WeTransfer; TargetAttributes = { 502C139F206E5F230082CE37 = { @@ -400,6 +400,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; @@ -426,7 +427,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.2; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -462,6 +463,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; @@ -482,7 +484,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.2; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -504,7 +506,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = UINotifications/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotifications; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -526,7 +528,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = UINotifications/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotifications; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -594,6 +596,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; @@ -620,7 +623,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.2; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -643,7 +646,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = UINotifications/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotifications; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; diff --git a/UINotifications.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/UINotifications.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/UINotifications.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/UINotifications.xcodeproj/xcshareddata/xcschemes/UINotifications.xcscheme b/UINotifications.xcodeproj/xcshareddata/xcschemes/UINotifications.xcscheme index 9d5d7e5..83de330 100644 --- a/UINotifications.xcodeproj/xcshareddata/xcschemes/UINotifications.xcscheme +++ b/UINotifications.xcodeproj/xcshareddata/xcschemes/UINotifications.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> + + + + - - - - - - - - - - - -