Skip to content

Commit 3883abc

Browse files
committed
Expand scope of new sizing API
1 parent 5b5973b commit 3883abc

16 files changed

+1019
-470
lines changed

Demo/Demo/Base.lproj/Main.storyboard

+273-125
Large diffs are not rendered by default.

Demo/Demo/ViewControllersViewController.swift

+71-7
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,112 @@ class SwiftMessagesTopSegue: SwiftMessagesSegue {
1919
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
2020
super.init(identifier: identifier, source: source, destination: destination)
2121
configure(layout: .topMessage)
22+
messageView.layout.size.height = .absolute(300)
2223
}
2324
}
2425

25-
class SwiftMessagesTopCardSegue: SwiftMessagesSegue {
26+
class SwiftMessagesBottomSegue: SwiftMessagesSegue {
2627
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
2728
super.init(identifier: identifier, source: source, destination: destination)
28-
configure(layout: .topCard)
29+
configure(layout: .bottomMessage)
30+
messageView.layout.size.height = .absolute(300)
2931
}
3032
}
3133

32-
class SwiftMessagesTopTabSegue: SwiftMessagesSegue {
34+
class SwiftMessagesLeadingSegue: SwiftMessagesSegue {
3335
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
3436
super.init(identifier: identifier, source: source, destination: destination)
35-
configure(layout: .topTab)
37+
configure(layout: .leadingMessage)
38+
messageView.layout.size.width = .absolute(300)
3639
}
3740
}
3841

39-
class SwiftMessagesBottomSegue: SwiftMessagesSegue {
42+
class SwiftMessagesTrailingSegue: SwiftMessagesSegue {
4043
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
4144
super.init(identifier: identifier, source: source, destination: destination)
42-
configure(layout: .bottomMessage)
45+
configure(layout: .trailingMessage)
46+
messageView.layout.size.width = .absolute(300)
47+
}
48+
}
49+
50+
class SwiftMessagesTopCardSegue: SwiftMessagesSegue {
51+
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
52+
super.init(identifier: identifier, source: source, destination: destination)
53+
configure(layout: .topCard)
54+
messageView.layout.size.height = .absolute(300)
4355
}
4456
}
4557

4658
class SwiftMessagesBottomCardSegue: SwiftMessagesSegue {
4759
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
4860
super.init(identifier: identifier, source: source, destination: destination)
4961
configure(layout: .bottomCard)
50-
messageView.messageSize.width = .relative(0.75, from: .superview)
62+
messageView.layout.size.height = .absolute(300)
63+
}
64+
}
65+
66+
class SwiftMessagesLeadingCardSegue: SwiftMessagesSegue {
67+
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
68+
super.init(identifier: identifier, source: source, destination: destination)
69+
configure(layout: .leadingCard)
70+
messageView.layout.size.width = .absolute(300)
71+
}
72+
}
73+
74+
class SwiftMessagesTrailingCardSegue: SwiftMessagesSegue {
75+
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
76+
super.init(identifier: identifier, source: source, destination: destination)
77+
configure(layout: .trailingCard)
78+
messageView.layout.size.width = .absolute(300)
79+
}
80+
}
81+
82+
class SwiftMessagesTopTabSegue: SwiftMessagesSegue {
83+
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
84+
super.init(identifier: identifier, source: source, destination: destination)
85+
configure(layout: .topTab)
86+
messageView.layout.size.height = .absolute(300)
5187
}
5288
}
5389

5490
class SwiftMessagesBottomTabSegue: SwiftMessagesSegue {
5591
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
5692
super.init(identifier: identifier, source: source, destination: destination)
5793
configure(layout: .bottomTab)
94+
messageView.layout.size.height = .absolute(300)
95+
}
96+
}
97+
98+
class SwiftMessagesLeadingTabSegue: SwiftMessagesSegue {
99+
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
100+
super.init(identifier: identifier, source: source, destination: destination)
101+
configure(layout: .leadingTab)
102+
messageView.layout.size.width = .absolute(300)
103+
}
104+
}
105+
106+
class SwiftMessagesTrailingTabSegue: SwiftMessagesSegue {
107+
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
108+
super.init(identifier: identifier, source: source, destination: destination)
109+
configure(layout: .trailingTab)
110+
messageView.layout.size.width = .absolute(300)
58111
}
59112
}
60113

61114
class SwiftMessagesCenteredSegue: SwiftMessagesSegue {
62115
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
63116
super.init(identifier: identifier, source: source, destination: destination)
64117
configure(layout: .centered)
118+
messageView.layout.size.height = .absolute(300)
119+
}
120+
}
121+
122+
class SwiftMessagesOffCenteredSegue: SwiftMessagesSegue {
123+
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
124+
super.init(identifier: identifier, source: source, destination: destination)
125+
configure(layout: .centered)
126+
messageView.layout.insets.top = .absolute(0, from: .safeArea)
127+
messageView.layout.center.x = .relative(0.33, in: .safeArea)
128+
messageView.layout.size.height = .absolute(300)
65129
}
66130
}

SwiftMessages.xcodeproj/project.pbxproj

+4-8
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
228DF5681FAD0806004F8A39 /* infoIconSubtle.png in Resources */ = {isa = PBXBuildFile; fileRef = 228DF5471FAD0805004F8A39 /* infoIconSubtle.png */; };
5252
228DF5691FAD0806004F8A39 /* successIconLight.png in Resources */ = {isa = PBXBuildFile; fileRef = 228DF5481FAD0805004F8A39 /* successIconLight.png */; };
5353
228DF56A1FAD0806004F8A39 /* infoIconSubtle@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 228DF5491FAD0805004F8A39 /* infoIconSubtle@3x.png */; };
54-
2290944825D88A05002E8111 /* MessageSizeable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2290944725D88A05002E8111 /* MessageSizeable.swift */; };
55-
2290957825D9BC9F002E8111 /* MessageSizing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2290957725D9BC9F002E8111 /* MessageSizing.swift */; };
54+
2290944825D88A05002E8111 /* Layout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2290944725D88A05002E8111 /* Layout.swift */; };
5655
2290958125D9D407002E8111 /* UILayoutPriority+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2290958025D9D407002E8111 /* UILayoutPriority+Extensions.swift */; };
5756
2298C2051EE47DC900E2DDC1 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2041EE47DC900E2DDC1 /* Weak.swift */; };
5857
2298C2071EE480D000E2DDC1 /* Animator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2061EE480D000E2DDC1 /* Animator.swift */; };
@@ -140,8 +139,7 @@
140139
228DF5471FAD0805004F8A39 /* infoIconSubtle.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = infoIconSubtle.png; path = Resources/infoIconSubtle.png; sourceTree = "<group>"; };
141140
228DF5481FAD0805004F8A39 /* successIconLight.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = successIconLight.png; path = Resources/successIconLight.png; sourceTree = "<group>"; };
142141
228DF5491FAD0805004F8A39 /* infoIconSubtle@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "infoIconSubtle@3x.png"; path = "Resources/infoIconSubtle@3x.png"; sourceTree = "<group>"; };
143-
2290944725D88A05002E8111 /* MessageSizeable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSizeable.swift; sourceTree = "<group>"; };
144-
2290957725D9BC9F002E8111 /* MessageSizing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSizing.swift; sourceTree = "<group>"; };
142+
2290944725D88A05002E8111 /* Layout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Layout.swift; sourceTree = "<group>"; };
145143
2290958025D9D407002E8111 /* UILayoutPriority+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILayoutPriority+Extensions.swift"; sourceTree = "<group>"; };
146144
2298C2041EE47DC900E2DDC1 /* Weak.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = "<group>"; };
147145
2298C2061EE480D000E2DDC1 /* Animator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Animator.swift; sourceTree = "<group>"; };
@@ -301,8 +299,7 @@
301299
8644955C1D4FAF7C0056EB2A /* WindowViewController.swift */,
302300
867BED201D622793005212E3 /* BackgroundViewable.swift */,
303301
864495551D4F7C390056EB2A /* Identifiable.swift */,
304-
2290944725D88A05002E8111 /* MessageSizeable.swift */,
305-
2290957725D9BC9F002E8111 /* MessageSizing.swift */,
302+
2290944725D88A05002E8111 /* Layout.swift */,
306303
86AAF81D1D5549680031EE32 /* MarginAdjustable.swift */,
307304
22E307FE1E74C5B100E35893 /* AccessibleMessage.swift */,
308305
86AAF82A1D580DD70031EE32 /* Error.swift */,
@@ -539,7 +536,7 @@
539536
86BBA8FC1D5E03F100FE8F16 /* MessageView.swift in Sources */,
540537
86BBA9061D5E040C00FE8F16 /* Identifiable.swift in Sources */,
541538
22F27951210CE25900273E7F /* CornerRoundingView.swift in Sources */,
542-
2290944825D88A05002E8111 /* MessageSizeable.swift in Sources */,
539+
2290944825D88A05002E8111 /* Layout.swift in Sources */,
543540
86BBA9011D5E040600FE8F16 /* PassthroughWindow.swift in Sources */,
544541
2298C2071EE480D000E2DDC1 /* Animator.swift in Sources */,
545542
86BBA9031D5E040600FE8F16 /* UIViewController+Extensions.swift in Sources */,
@@ -562,7 +559,6 @@
562559
2298C2091EE486E300E2DDC1 /* TopBottomAnimation.swift in Sources */,
563560
86589D471D64B6E40041676C /* BaseView.swift in Sources */,
564561
225304622290C76E00A03ACF /* NSLayoutConstraint+Extensions.swift in Sources */,
565-
2290957825D9BC9F002E8111 /* MessageSizing.swift in Sources */,
566562
86BBA9071D5E040C00FE8F16 /* MarginAdjustable.swift in Sources */,
567563
867BED211D622793005212E3 /* BackgroundViewable.swift in Sources */,
568564
2290958125D9D407002E8111 /* UILayoutPriority+Extensions.swift in Sources */,

SwiftMessages/Animator.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public struct SafeZoneConflicts: OptionSet {
4545

4646
public class AnimationContext {
4747
public let messageView: UIView
48-
public let containerView: UIView & MessageSizing
48+
public let containerView: UIView & LayoutInstalling
4949
public let safeZoneConflicts: SafeZoneConflicts
5050
public let interactiveHide: Bool
5151

5252
internal init(
5353
messageView: UIView,
54-
containerView: UIView & MessageSizing,
54+
containerView: UIView & LayoutInstalling,
5555
safeZoneConflicts: SafeZoneConflicts,
5656
interactiveHide: Bool
5757
) {

SwiftMessages/BaseView.swift

+50-59
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import UIKit
1414
of the optional SwiftMessages protocols and provides some convenience functions
1515
and a configurable tap handler. Message views do not need to inherit from `BaseVew`.
1616
*/
17-
open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeable {
17+
open class BaseView: UIView, BackgroundViewable, MarginAdjustable, LayoutDefining {
1818

1919
/*
2020
MARK: - IB outlets
@@ -63,6 +63,7 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeab
6363
*/
6464

6565
/**
66+
TODO SIZE - update documentation
6667
A convenience function for installing a content view as a subview of `backgroundView`
6768
and pinning the edges to `backgroundView` with the specified `insets`.
6869

@@ -82,6 +83,7 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeab
8283
}
8384

8485
/**
86+
TODO SIZE - update documentation - insets removed
8587
A convenience function for installing a background view and pinning to the layout margins.
8688
This is useful for creating programatic layouts where the background view needs to be
8789
inset from the message view's edges (like a card-style layout).
@@ -90,7 +92,7 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeab
9092
assigned to the `backgroundView` property.
9193
- Parameter insets: The amount to inset the content view from the margins. Default is zero inset.
9294
*/
93-
open func installBackgroundView(_ backgroundView: UIView, insets: UIEdgeInsets = UIEdgeInsets.zero) {
95+
open func installBackgroundView(_ backgroundView: UIView) {
9496
backgroundView.translatesAutoresizingMaskIntoConstraints = false
9597
if backgroundView != self {
9698
backgroundView.removeFromSuperview()
@@ -100,65 +102,57 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeab
100102
NSLayoutConstraint.activate([
101103
backgroundView.centerXAnchor.constraint(equalTo: centerXAnchor)
102104
.with(priority: .belowMessageSizeable),
103-
backgroundView.topAnchor.constraint(
104-
equalTo: layoutMarginsGuide.topAnchor,
105-
constant: insets.top
106-
).with(priority: .belowMessageSizeable),
107-
backgroundView.bottomAnchor.constraint(
108-
equalTo: layoutMarginsGuide.bottomAnchor,
109-
constant: -insets.bottom
110-
).with(priority: .belowMessageSizeable),
111-
backgroundView.heightAnchor.constraint(equalToConstant: 350)
112-
.with(priority: UILayoutPriority(rawValue: 200)),
113-
backgroundView.leftAnchor.constraint(
114-
equalTo: layoutMarginsGuide.leftAnchor,
115-
constant: insets.left
116-
).with(priority: .belowMessageSizeable),
117-
backgroundView.rightAnchor.constraint(
118-
equalTo: layoutMarginsGuide.rightAnchor,
119-
constant: -insets.right
120-
).with(priority: .belowMessageSizeable),
121-
])
122-
installTapRecognizer()
123-
}
124-
125-
/**
126-
A convenience function for installing a background view and pinning to the horizontal
127-
layout margins and to the vertical edges. This is useful for creating programatic layouts where
128-
the background view needs to be inset from the message view's horizontal edges (like a tab-style layout).
129-
130-
- Parameter backgroundView: The view to be installed as a subview and
131-
assigned to the `backgroundView` property.
132-
- Parameter insets: The amount to inset the content view from the horizontal margins and vertical edges.
133-
Default is zero inset.
134-
*/
135-
open func installBackgroundVerticalView(_ backgroundView: UIView, insets: UIEdgeInsets = UIEdgeInsets.zero) {
136-
backgroundView.translatesAutoresizingMaskIntoConstraints = false
137-
if backgroundView != self {
138-
backgroundView.removeFromSuperview()
139-
}
140-
addSubview(backgroundView)
141-
self.backgroundView = backgroundView
142-
NSLayoutConstraint.activate([
143-
backgroundView.centerXAnchor.constraint(equalTo: centerXAnchor)
105+
backgroundView.topAnchor.constraint(equalTo: topAnchor)
106+
.with(priority: .belowMessageSizeable),
107+
backgroundView.bottomAnchor.constraint(equalTo: bottomAnchor)
144108
.with(priority: .belowMessageSizeable),
145-
backgroundView.topAnchor.constraint(equalTo: topAnchor, constant: insets.top)
146-
.with(priority: .required),
147-
backgroundView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -insets.bottom)
148-
.with(priority: .required),
149109
backgroundView.heightAnchor.constraint(equalToConstant: 350)
150110
.with(priority: UILayoutPriority(rawValue: 200)),
151-
backgroundView.leftAnchor.constraint(
152-
equalTo: layoutMarginsGuide.leftAnchor, constant: insets.left
153-
).with(priority: .belowMessageSizeable),
154-
backgroundView.rightAnchor.constraint(
155-
equalTo: layoutMarginsGuide.rightAnchor,
156-
constant: -insets.right
157-
).with(priority: .belowMessageSizeable),
111+
backgroundView.leadingAnchor.constraint(equalTo: leadingAnchor)
112+
.with(priority: .belowMessageSizeable),
113+
backgroundView.trailingAnchor.constraint(equalTo: trailingAnchor)
114+
.with(priority: .belowMessageSizeable),
158115
])
159116
installTapRecognizer()
160117
}
161118

119+
// /**
120+
// A convenience function for installing a background view and pinning to the horizontal
121+
// layout margins and to the vertical edges. This is useful for creating programatic layouts where
122+
// the background view needs to be inset from the message view's horizontal edges (like a tab-style layout).
123+
//
124+
// - Parameter backgroundView: The view to be installed as a subview and
125+
// assigned to the `backgroundView` property.
126+
// - Parameter insets: The amount to inset the content view from the horizontal margins and vertical edges.
127+
// Default is zero inset.
128+
// */
129+
// open func installBackgroundVerticalView(_ backgroundView: UIView, insets: UIEdgeInsets = UIEdgeInsets.zero) {
130+
// backgroundView.translatesAutoresizingMaskIntoConstraints = false
131+
// if backgroundView != self {
132+
// backgroundView.removeFromSuperview()
133+
// }
134+
// addSubview(backgroundView)
135+
// self.backgroundView = backgroundView
136+
// NSLayoutConstraint.activate([
137+
// backgroundView.centerXAnchor.constraint(equalTo: centerXAnchor)
138+
// .with(priority: .belowMessageSizeable),
139+
// backgroundView.topAnchor.constraint(equalTo: topAnchor, constant: insets.top)
140+
// .with(priority: .required),
141+
// backgroundView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -insets.bottom)
142+
// .with(priority: .required),
143+
// backgroundView.heightAnchor.constraint(equalToConstant: 350)
144+
// .with(priority: UILayoutPriority(rawValue: 200)),
145+
// backgroundView.leftAnchor.constraint(
146+
// equalTo: layoutMarginsGuide.leftAnchor, constant: insets.left
147+
// ).with(priority: .belowMessageSizeable),
148+
// backgroundView.rightAnchor.constraint(
149+
// equalTo: layoutMarginsGuide.rightAnchor,
150+
// constant: -insets.right
151+
// ).with(priority: .belowMessageSizeable),
152+
// ])
153+
// installTapRecognizer()
154+
// }
155+
162156
/*
163157
MARK: - Tap handler
164158
*/
@@ -203,11 +197,8 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeab
203197

204198
// MARK: - MessageSizeable
205199

206-
/// Configure the view's size
207-
public var messageSize = MessageSize()
208-
209-
/// Configure the view's insets from the container
210-
public var messageInsets = MessageInsets()
200+
/// Configure the view's layout
201+
public var layout = Layout()
211202

212203
/*
213204
MARK: - MarginAdjustable

SwiftMessages/CornerRoundingView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ open class CornerRoundingView: UIView {
2424
/// rounded. For example, the layout in TabView.xib rounds the bottom corners
2525
/// when displayed from the top and the top corners when displayed from the bottom.
2626
/// When this property is `true`, the `roundedCorners` property will be overwritten
27-
/// by relevant animators (e.g. `TopBottomAnimation`).
27+
/// by relevant animators (e.g. `EdgeAnimation`).
2828
@IBInspectable
2929
open var roundsLeadingCorners: Bool = false
3030

3131
/// Specifies which corners should be rounded. When `roundsLeadingCorners = true`, relevant
32-
/// relevant animators (e.g. `TopBottomAnimation`) will overwrite the value of this property.
32+
/// relevant animators (e.g. `EdgeAnimation`) will overwrite the value of this property.
3333
open var roundedCorners: UIRectCorner = [.allCorners] {
3434
didSet {
3535
updateMaskPath()

0 commit comments

Comments
 (0)