Skip to content

Commit 7a20be9

Browse files
authored
Allow customizing the order of views and the image size (#52)
* Allow customizing the order of views and the image size * Fix tests
1 parent 4dae6cf commit 7a20be9

File tree

9 files changed

+69
-33
lines changed

9 files changed

+69
-33
lines changed

Sources/UINotification.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public protocol UINotificationStyle {
3333

3434
/// The chevron image which is shown when a notification has an action attached.
3535
var chevronImage: UIImage? { get }
36+
37+
/// The size to use for the thumbnail view.
38+
var thumbnailSize: CGSize { get }
3639
}
3740

3841
/// Handles changes in UINotification

Sources/UINotificationStyles/UINotificationSystemStyle.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public struct UINotificationSystemStyle: UINotificationStyle {
1919
public var maxWidth: CGFloat?
2020
public var interactive: Bool = true
2121
public var chevronImage: UIImage?
22+
public var thumbnailSize: CGSize = .init(width: 31, height: 31)
2223

2324
public init() { }
2425
}

Sources/UINotificationView.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ open class UINotificationView: UIView {
1919
/// Will be set by the presenter. Is used to animate the notification view with a pan gesture.
2020
var topConstraint: NSLayoutConstraint?
2121

22+
var imageViewWidthConstraint: NSLayoutConstraint?
23+
var imageViewHeightConstraint: NSLayoutConstraint?
24+
2225
/// The limit of translation before we will dismiss the notification.
2326
internal let translationDismissLimit: CGFloat = -15
2427

@@ -36,8 +39,13 @@ open class UINotificationView: UIView {
3639
return stackView
3740
}()
3841

42+
/// Override this to change the order of subviews. For example, to show the subtitle above the title.
43+
open var arrangedSubviews: [UIView] {
44+
return [self.titleLabel, self.subtitleLabel]
45+
}
46+
3947
open private(set) lazy var titlesStackView: UIStackView = {
40-
let stackView = UIStackView(arrangedSubviews: [self.titleLabel, self.subtitleLabel])
48+
let stackView = UIStackView(arrangedSubviews: arrangedSubviews)
4149
stackView.axis = .vertical
4250
stackView.spacing = 0
4351
stackView.translatesAutoresizingMaskIntoConstraints = false
@@ -110,7 +118,7 @@ open class UINotificationView: UIView {
110118
translatesAutoresizingMaskIntoConstraints = false
111119
isUserInteractionEnabled = true
112120

113-
layoutMargins = UIEdgeInsets(top: 4, left: 0, bottom: 4, right: 0)
121+
layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
114122

115123
addArrangedSubviewsForContainerStackView()
116124
addSubview(containerStackView)
@@ -132,6 +140,8 @@ open class UINotificationView: UIView {
132140

133141
imageView.image = notification.content.image
134142
imageView.isHidden = notification.content.image == nil
143+
imageViewWidthConstraint?.constant = notification.style.thumbnailSize.width
144+
imageViewHeightConstraint?.constant = notification.style.thumbnailSize.height
135145

136146
backgroundColor = notification.style.backgroundColor
137147

@@ -154,6 +164,9 @@ open class UINotificationView: UIView {
154164
/// Called when all constraints should be setup for the notification. Can be overwritten to set your own constraints.
155165
/// When setting your own constraints, you should not be calling super.
156166
open func setupConstraints() {
167+
imageViewWidthConstraint = imageView.widthAnchor.constraint(equalToConstant: 31)
168+
imageViewHeightConstraint = imageView.heightAnchor.constraint(equalToConstant: 31)
169+
157170
let constraints = [
158171
containerStackView.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor, constant: 18),
159172
containerStackView.rightAnchor.constraint(equalTo: layoutMarginsGuide.rightAnchor, constant: -18),
@@ -162,8 +175,8 @@ open class UINotificationView: UIView {
162175

163176
chevronImageView.widthAnchor.constraint(equalToConstant: chevronImageView.image?.size.width ?? 0),
164177

165-
imageView.widthAnchor.constraint(equalToConstant: 31),
166-
imageView.heightAnchor.constraint(equalToConstant: 31)
178+
imageViewWidthConstraint!,
179+
imageViewHeightConstraint!
167180
]
168181

169182
button?.setContentHuggingPriority(.defaultHigh, for: .horizontal)

UINotifications.xcodeproj/project.pbxproj

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
isa = PBXProject;
258258
attributes = {
259259
LastSwiftUpdateCheck = 0920;
260-
LastUpgradeCheck = 1010;
260+
LastUpgradeCheck = 1230;
261261
ORGANIZATIONNAME = WeTransfer;
262262
TargetAttributes = {
263263
502C139F206E5F230082CE37 = {
@@ -400,6 +400,7 @@
400400
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
401401
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
402402
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
403+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
403404
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
404405
CLANG_WARN_STRICT_PROTOTYPES = YES;
405406
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -426,7 +427,7 @@
426427
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
427428
GCC_WARN_UNUSED_FUNCTION = YES;
428429
GCC_WARN_UNUSED_VARIABLE = YES;
429-
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
430+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
430431
MTL_ENABLE_DEBUG_INFO = YES;
431432
ONLY_ACTIVE_ARCH = YES;
432433
SDKROOT = iphoneos;
@@ -462,6 +463,7 @@
462463
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
463464
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
464465
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
466+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
465467
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
466468
CLANG_WARN_STRICT_PROTOTYPES = YES;
467469
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -482,7 +484,7 @@
482484
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
483485
GCC_WARN_UNUSED_FUNCTION = YES;
484486
GCC_WARN_UNUSED_VARIABLE = YES;
485-
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
487+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
486488
MTL_ENABLE_DEBUG_INFO = NO;
487489
SDKROOT = iphoneos;
488490
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
@@ -504,7 +506,7 @@
504506
DYLIB_INSTALL_NAME_BASE = "@rpath";
505507
INFOPLIST_FILE = UINotifications/Info.plist;
506508
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
507-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
509+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
508510
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
509511
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotifications;
510512
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -526,7 +528,7 @@
526528
DYLIB_INSTALL_NAME_BASE = "@rpath";
527529
INFOPLIST_FILE = UINotifications/Info.plist;
528530
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
529-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
531+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
530532
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
531533
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotifications;
532534
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -594,6 +596,7 @@
594596
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
595597
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
596598
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
599+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
597600
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
598601
CLANG_WARN_STRICT_PROTOTYPES = YES;
599602
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -620,7 +623,7 @@
620623
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
621624
GCC_WARN_UNUSED_FUNCTION = YES;
622625
GCC_WARN_UNUSED_VARIABLE = YES;
623-
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
626+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
624627
MTL_ENABLE_DEBUG_INFO = YES;
625628
ONLY_ACTIVE_ARCH = YES;
626629
SDKROOT = iphoneos;
@@ -643,7 +646,7 @@
643646
DYLIB_INSTALL_NAME_BASE = "@rpath";
644647
INFOPLIST_FILE = UINotifications/Info.plist;
645648
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
646-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
649+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
647650
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
648651
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotifications;
649652
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

UINotifications.xcodeproj/xcshareddata/xcschemes/UINotifications.xcscheme

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1230"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,8 +26,17 @@
2626
buildConfiguration = "Test"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
codeCoverageEnabled = "YES"
30-
shouldUseLaunchSchemeArgsEnv = "YES">
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES">
31+
<MacroExpansion>
32+
<BuildableReference
33+
BuildableIdentifier = "primary"
34+
BlueprintIdentifier = "502C139F206E5F230082CE37"
35+
BuildableName = "UINotifications.framework"
36+
BlueprintName = "UINotifications"
37+
ReferencedContainer = "container:UINotifications.xcodeproj">
38+
</BuildableReference>
39+
</MacroExpansion>
3140
<Testables>
3241
<TestableReference
3342
skipped = "NO"
@@ -41,17 +50,6 @@
4150
</BuildableReference>
4251
</TestableReference>
4352
</Testables>
44-
<MacroExpansion>
45-
<BuildableReference
46-
BuildableIdentifier = "primary"
47-
BlueprintIdentifier = "502C139F206E5F230082CE37"
48-
BuildableName = "UINotifications.framework"
49-
BlueprintName = "UINotifications"
50-
ReferencedContainer = "container:UINotifications.xcodeproj">
51-
</BuildableReference>
52-
</MacroExpansion>
53-
<AdditionalOptions>
54-
</AdditionalOptions>
5553
</TestAction>
5654
<LaunchAction
5755
buildConfiguration = "Debug"
@@ -72,8 +70,6 @@
7270
ReferencedContainer = "container:UINotifications.xcodeproj">
7371
</BuildableReference>
7472
</MacroExpansion>
75-
<AdditionalOptions>
76-
</AdditionalOptions>
7773
</LaunchAction>
7874
<ProfileAction
7975
buildConfiguration = "Release"

UINotifications.xcodeproj/xcshareddata/xcschemes/UINotificationsTests.xcscheme

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1230"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -23,8 +23,6 @@
2323
</BuildableReference>
2424
</TestableReference>
2525
</Testables>
26-
<AdditionalOptions>
27-
</AdditionalOptions>
2826
</TestAction>
2927
<LaunchAction
3028
buildConfiguration = "Debug"
@@ -36,8 +34,6 @@
3634
debugDocumentVersioning = "YES"
3735
debugServiceExtension = "internal"
3836
allowLocationSimulation = "YES">
39-
<AdditionalOptions>
40-
</AdditionalOptions>
4137
</LaunchAction>
4238
<ProfileAction
4339
buildConfiguration = "Release"

UINotificationsTests/UINotificationDefaultElementsTests.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import XCTest
1212
final class UINotificationDefaultElementsTests: UINotificationTestCase {
1313

1414
struct CustomStyle: UINotificationStyle {
15+
var thumbnailSize: CGSize
1516
var titleFont: UIFont = UIFont.systemFont(ofSize: 13, weight: .semibold)
1617
var subtitleFont: UIFont = UIFont.systemFont(ofSize: 13, weight: .semibold)
1718
var titleTextColor: UIColor = UIColor.black
@@ -27,9 +28,10 @@ final class UINotificationDefaultElementsTests: UINotificationTestCase {
2728
let customHeight: CGFloat?
2829
let maxWidth: CGFloat?
2930

30-
init(customHeight: CGFloat? = nil, maxWidth: CGFloat? = nil) {
31+
init(customHeight: CGFloat? = nil, maxWidth: CGFloat? = nil, thumbnailSize: CGSize = CGSize(width: 20, height: 20)) {
3132
self.customHeight = customHeight
3233
self.maxWidth = maxWidth
34+
self.thumbnailSize = thumbnailSize
3335
}
3436
}
3537

@@ -76,6 +78,19 @@ final class UINotificationDefaultElementsTests: UINotificationTestCase {
7678

7779
waitFor(notificationCenter.currentPresenter?.presentationContext.notificationView.frame.size.height == customHeight, timeout: 5.0, description: "Custom height should be applied to the view")
7880
}
81+
82+
/// When passing a notification style with a custom thumbnail size, this should be applied to the presented view.
83+
func testCustomNotificationThumbnailSize() {
84+
let notificationCenter = UINotificationCenter()
85+
notificationCenter.isDuplicateQueueingAllowed = true
86+
notificationCenter.presenterType = MockPresenter.self
87+
let customSize = CGSize(width: 25, height: 25)
88+
let notification = UINotification(content: UINotificationContent(title: "test"), style: CustomStyle(thumbnailSize: customSize))
89+
90+
notificationCenter.show(notification: notification)
91+
92+
waitFor(notificationCenter.currentPresenter?.presentationContext.notificationView.imageView.frame.size == customSize, timeout: 5.0, description: "Custom height should be applied to the view")
93+
}
7994

8095
/// When passing a notification style with a max width, this should be applied to the presented view.
8196
func testNotificationViewMaxWidth() {

UINotificationsTests/UINotificationDefaultViewTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ final class UINotificationViewTests: UINotificationTestCase {
102102
}
103103

104104
private struct LargeChevronStyle: UINotificationStyle {
105+
var thumbnailSize: CGSize = CGSize(width: 20, height: 20)
105106
var titleFont: UIFont = UIFont.systemFont(ofSize: 13, weight: .semibold)
106107
var subtitleFont: UIFont = UIFont.systemFont(ofSize: 13, weight: .semibold)
107108
var titleTextColor: UIColor = UIColor.black

0 commit comments

Comments
 (0)