Skip to content

Commit 616353c

Browse files
committed
Revert "Add sizing options"
This reverts commit 5b5973b. # Conflicts: # SwiftMessages.xcodeproj/project.pbxproj
1 parent 0d7584e commit 616353c

14 files changed

+263
-405
lines changed

Demo/Demo/ViewControllersViewController.swift

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class SwiftMessagesBottomCardSegue: SwiftMessagesSegue {
4747
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
4848
super.init(identifier: identifier, source: source, destination: destination)
4949
configure(layout: .bottomCard)
50-
messageView.messageSize.width = .relative(0.75, from: .superview)
5150
}
5251
}
5352

SwiftMessages.xcodeproj/project.pbxproj

+4-13
Original file line numberDiff line numberDiff line change
@@ -51,9 +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 */; };
56-
2290958125D9D407002E8111 /* UILayoutPriority+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2290958025D9D407002E8111 /* UILayoutPriority+Extensions.swift */; };
54+
2290944825D88A05002E8111 /* BoundaryInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2290944725D88A05002E8111 /* BoundaryInsets.swift */; };
5755
2298C2051EE47DC900E2DDC1 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2041EE47DC900E2DDC1 /* Weak.swift */; };
5856
2298C2071EE480D000E2DDC1 /* Animator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2061EE480D000E2DDC1 /* Animator.swift */; };
5957
2298C2091EE486E300E2DDC1 /* TopBottomAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2081EE486E300E2DDC1 /* TopBottomAnimation.swift */; };
@@ -140,9 +138,7 @@
140138
228DF5471FAD0805004F8A39 /* infoIconSubtle.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = infoIconSubtle.png; path = Resources/infoIconSubtle.png; sourceTree = "<group>"; };
141139
228DF5481FAD0805004F8A39 /* successIconLight.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = successIconLight.png; path = Resources/successIconLight.png; sourceTree = "<group>"; };
142140
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>"; };
145-
2290958025D9D407002E8111 /* UILayoutPriority+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILayoutPriority+Extensions.swift"; sourceTree = "<group>"; };
141+
2290944725D88A05002E8111 /* BoundaryInsets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoundaryInsets.swift; sourceTree = "<group>"; };
146142
2298C2041EE47DC900E2DDC1 /* Weak.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = "<group>"; };
147143
2298C2061EE480D000E2DDC1 /* Animator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Animator.swift; sourceTree = "<group>"; };
148144
2298C2081EE486E300E2DDC1 /* TopBottomAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TopBottomAnimation.swift; sourceTree = "<group>"; };
@@ -215,8 +211,6 @@
215211
children = (
216212
220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */,
217213
22774B9F20B5EF2A00813732 /* UIEdgeInsets+Extensions.swift */,
218-
2290958025D9D407002E8111 /* UILayoutPriority+Extensions.swift */,
219-
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */,
220214
);
221215
name = Extensions;
222216
sourceTree = "<group>";
@@ -302,12 +296,11 @@
302296
8644955C1D4FAF7C0056EB2A /* WindowViewController.swift */,
303297
867BED201D622793005212E3 /* BackgroundViewable.swift */,
304298
864495551D4F7C390056EB2A /* Identifiable.swift */,
305-
2290944725D88A05002E8111 /* MessageSizeable.swift */,
306-
2290957725D9BC9F002E8111 /* MessageSizing.swift */,
307299
86AAF81D1D5549680031EE32 /* MarginAdjustable.swift */,
308300
22E307FE1E74C5B100E35893 /* AccessibleMessage.swift */,
309301
86AAF82A1D580DD70031EE32 /* Error.swift */,
310302
2298C2061EE480D000E2DDC1 /* Animator.swift */,
303+
2290944725D88A05002E8111 /* BoundaryInsets.swift */,
311304
2298C2041EE47DC900E2DDC1 /* Weak.swift */,
312305
22F27950210CE25900273E7F /* CornerRoundingView.swift */,
313306
225304652293000C00A03ACF /* KeyboardTrackingView.swift */,
@@ -540,7 +533,7 @@
540533
86BBA8FC1D5E03F100FE8F16 /* MessageView.swift in Sources */,
541534
86BBA9061D5E040C00FE8F16 /* Identifiable.swift in Sources */,
542535
22F27951210CE25900273E7F /* CornerRoundingView.swift in Sources */,
543-
2290944825D88A05002E8111 /* MessageSizeable.swift in Sources */,
536+
2290944825D88A05002E8111 /* BoundaryInsets.swift in Sources */,
544537
86BBA9011D5E040600FE8F16 /* PassthroughWindow.swift in Sources */,
545538
2298C2071EE480D000E2DDC1 /* Animator.swift in Sources */,
546539
86BBA9031D5E040600FE8F16 /* UIViewController+Extensions.swift in Sources */,
@@ -564,10 +557,8 @@
564557
2298C2091EE486E300E2DDC1 /* TopBottomAnimation.swift in Sources */,
565558
86589D471D64B6E40041676C /* BaseView.swift in Sources */,
566559
225304622290C76E00A03ACF /* NSLayoutConstraint+Extensions.swift in Sources */,
567-
2290957825D9BC9F002E8111 /* MessageSizing.swift in Sources */,
568560
86BBA9071D5E040C00FE8F16 /* MarginAdjustable.swift in Sources */,
569561
867BED211D622793005212E3 /* BackgroundViewable.swift in Sources */,
570-
2290958125D9D407002E8111 /* UILayoutPriority+Extensions.swift in Sources */,
571562
);
572563
runOnlyForDeploymentPostprocessing = 0;
573564
};

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
4949
public let safeZoneConflicts: SafeZoneConflicts
5050
public let interactiveHide: Bool
5151

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

SwiftMessages/BaseView.swift

+59-48
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, HasBoundaryInsets {
1818

1919
/*
2020
MARK: - IB outlets
@@ -97,28 +97,20 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeab
9797
}
9898
addSubview(backgroundView)
9999
self.backgroundView = backgroundView
100-
NSLayoutConstraint.activate([
101-
backgroundView.centerXAnchor.constraint(equalTo: centerXAnchor)
102-
.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-
])
100+
backgroundView.centerXAnchor.constraint(equalTo: centerXAnchor).with(priority: UILayoutPriority(rawValue: 950)).isActive = true
101+
backgroundView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, constant: insets.top).with(priority: UILayoutPriority(rawValue: 900)).isActive = true
102+
backgroundView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, constant: -insets.bottom).with(priority: UILayoutPriority(rawValue: 900)).isActive = true
103+
backgroundView.heightAnchor.constraint(equalToConstant: 350).with(priority: UILayoutPriority(rawValue: 200)).isActive = true
104+
layoutConstraints = [
105+
backgroundView.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor, constant: insets.left).with(priority: UILayoutPriority(rawValue: 900)),
106+
backgroundView.rightAnchor.constraint(equalTo: layoutMarginsGuide.rightAnchor, constant: -insets.right).with(priority: UILayoutPriority(rawValue: 900)),
107+
]
108+
regularWidthLayoutConstraints = [
109+
backgroundView.leftAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.leftAnchor, constant: insets.left).with(priority: UILayoutPriority(rawValue: 900)),
110+
backgroundView.rightAnchor.constraint(lessThanOrEqualTo: layoutMarginsGuide.rightAnchor, constant: -insets.right).with(priority: UILayoutPriority(rawValue: 900)),
111+
backgroundView.widthAnchor.constraint(lessThanOrEqualToConstant: 500).with(priority: UILayoutPriority(rawValue: 950)),
112+
backgroundView.widthAnchor.constraint(equalToConstant: 500).with(priority: UILayoutPriority(rawValue: 200)),
113+
]
122114
installTapRecognizer()
123115
}
124116

@@ -139,23 +131,20 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeab
139131
}
140132
addSubview(backgroundView)
141133
self.backgroundView = backgroundView
142-
NSLayoutConstraint.activate([
143-
backgroundView.centerXAnchor.constraint(equalTo: centerXAnchor)
144-
.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),
149-
backgroundView.heightAnchor.constraint(equalToConstant: 350)
150-
.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),
158-
])
134+
backgroundView.centerXAnchor.constraint(equalTo: centerXAnchor).with(priority: UILayoutPriority(rawValue: 950)).isActive = true
135+
backgroundView.topAnchor.constraint(equalTo: topAnchor, constant: insets.top).with(priority: UILayoutPriority(rawValue: 1000)).isActive = true
136+
backgroundView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -insets.bottom).with(priority: UILayoutPriority(rawValue: 1000)).isActive = true
137+
backgroundView.heightAnchor.constraint(equalToConstant: 350).with(priority: UILayoutPriority(rawValue: 200)).isActive = true
138+
layoutConstraints = [
139+
backgroundView.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor, constant: insets.left).with(priority: UILayoutPriority(rawValue: 900)),
140+
backgroundView.rightAnchor.constraint(equalTo: layoutMarginsGuide.rightAnchor, constant: -insets.right).with(priority: UILayoutPriority(rawValue: 900)),
141+
]
142+
regularWidthLayoutConstraints = [
143+
backgroundView.leftAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.leftAnchor, constant: insets.left).with(priority: UILayoutPriority(rawValue: 900)),
144+
backgroundView.rightAnchor.constraint(lessThanOrEqualTo: layoutMarginsGuide.rightAnchor, constant: -insets.right).with(priority: UILayoutPriority(rawValue: 900)),
145+
backgroundView.widthAnchor.constraint(lessThanOrEqualToConstant: 500).with(priority: UILayoutPriority(rawValue: 950)),
146+
backgroundView.widthAnchor.constraint(equalToConstant: 500).with(priority: UILayoutPriority(rawValue: 200)),
147+
]
159148
installTapRecognizer()
160149
}
161150

@@ -201,14 +190,6 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeab
201190
return super.point(inside: point, with: event)
202191
}
203192

204-
// MARK: - MessageSizeable
205-
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()
211-
212193
/*
213194
MARK: - MarginAdjustable
214195

@@ -248,6 +229,13 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeab
248229

249230
@IBInspectable open var bounceAnimationOffset: CGFloat = 5
250231

232+
/*
233+
MARK: - HasBoundaryInsets
234+
*/
235+
236+
/// Configure the view's inset from the superview or save area
237+
public var boundaryInsets = BoundaryInsets()
238+
251239
/*
252240
MARK: - Setting the height
253241
*/
@@ -276,6 +264,29 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable, MessageSizeab
276264
}
277265

278266
private var backgroundHeightConstraint: NSLayoutConstraint?
267+
268+
/*
269+
Mark: - Layout
270+
*/
271+
272+
open override func updateConstraints() {
273+
super.updateConstraints()
274+
let on: [NSLayoutConstraint]
275+
let off: [NSLayoutConstraint]
276+
switch traitCollection.horizontalSizeClass {
277+
case .regular:
278+
on = regularWidthLayoutConstraints
279+
off = layoutConstraints
280+
default:
281+
on = layoutConstraints
282+
off = regularWidthLayoutConstraints
283+
}
284+
on.forEach { $0.isActive = true }
285+
off.forEach { $0.isActive = false }
286+
}
287+
288+
private var layoutConstraints: [NSLayoutConstraint] = []
289+
private var regularWidthLayoutConstraints: [NSLayoutConstraint] = []
279290
}
280291

281292
/*

SwiftMessages/BoundaryInsets.swift

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// BoundaryInsets.swift
3+
// SwiftMessages
4+
//
5+
// Created by Timothy Moose on 2/13/21.
6+
// Copyright © 2021 SwiftKick Mobile. All rights reserved.
7+
//
8+
9+
import QuartzCore
10+
11+
public protocol HasBoundaryInsets {
12+
var boundaryInsets: BoundaryInsets { get }
13+
}
14+
15+
/// Insets used for specifying view sizing options in terms of insets from the containing superview or safe area.
16+
public struct BoundaryInsets {
17+
18+
public enum Boundary {
19+
case superview
20+
case safeArea
21+
case margin
22+
}
23+
24+
/// An abstract dimension used for specifying the message view's size
25+
public enum Dimension {
26+
27+
/// Dimensions should be determined automatically
28+
case automatic
29+
30+
/// Dimension should maintain an absolute margin to the given boundary.
31+
case absoluteMargin(CGFloat, with: Boundary)
32+
33+
/// Dimension should maintain a relative margin to the given boundary.
34+
case relativeMargin(CGFloat, with: Boundary)
35+
}
36+
37+
public var top: Dimension = .automatic
38+
public var bottom: Dimension = .automatic
39+
public var leading: Dimension = .automatic
40+
public var trailing: Dimension = .automatic
41+
}

0 commit comments

Comments
 (0)