Skip to content

Commit 93bbbc9

Browse files
authored
Merge pull request #735 from Iterable/finalizing-constraints
[MOB-7679] Updates OOTB constraints
2 parents 821804c + 91ed8da commit 93bbbc9

File tree

3 files changed

+14
-56
lines changed

3 files changed

+14
-56
lines changed

sample-apps/swift-sample-app/swift-sample-app/EmbeddedMessages/EmbeddedMessagesViewController.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class EmbeddedMessagesViewController: UIViewController {
8080
}
8181

8282
func loadCardView(_ embeddedView: IterableEmbeddedView, _ embeddedMessage: IterableEmbeddedMessage) {
83-
embeddedView.iterableEmbeddedViewDelegate = self
8483
embeddedView.primaryBtn.isRoundedSides = true
8584
embeddedView.secondaryBtn.isRoundedSides = true
8685
// We are setting the width of buttons as 140 as per our embedded messages width. You can change as per your need
@@ -93,7 +92,6 @@ class EmbeddedMessagesViewController: UIViewController {
9392
func loadBannerView(_ embeddedMessage: IterableEmbeddedMessage) {
9493
let config = IterableEmbeddedViewConfig(borderCornerRadius: 10)
9594
let embeddedView = IterableEmbeddedView(message: embeddedMessage, viewType: .banner, config: config)
96-
embeddedView.iterableEmbeddedViewDelegate = self
9795
embeddedView.primaryBtn.isRoundedSides = true
9896
embeddedView.secondaryBtn.isRoundedSides = true
9997
// We are setting the width of buttons as 140 as per our embedded messages width. You can change as per your need
@@ -123,24 +121,6 @@ class EmbeddedMessagesViewController: UIViewController {
123121
}
124122
}
125123

126-
extension EmbeddedMessagesViewController: IterableEmbeddedViewDelegate {
127-
func didPressPrimaryButton(button: UIButton, viewTag: Int, message: IterableSDK.IterableEmbeddedMessage?) {
128-
let buttonData = message?.elements?.buttons?.first
129-
let url = buttonData?.action?.data
130-
openUrl(url)
131-
}
132-
133-
func didPressSecondaryButton(button: UIButton, viewTag: Int, message: IterableSDK.IterableEmbeddedMessage?) {
134-
let buttonData = message?.elements?.buttons?[1]
135-
let url = buttonData?.action?.data
136-
openUrl(url)
137-
}
138-
139-
func didPressBanner(banner: IterableSDK.IterableEmbeddedView, viewTag: Int, message: IterableSDK.IterableEmbeddedMessage?) {
140-
openUrl(message?.elements?.defaultAction?.data)
141-
}
142-
}
143-
144124
extension EmbeddedMessagesViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
145125

146126
func collectionView(_ collectionView: UICollectionView,

swift-sdk/Resources/IterableEmbeddedView.xib

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="22154" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_12" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22130"/>
77
<capability name="System colors in document resources" minToolsVersion="11.0"/>
88
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
99
</dependencies>
@@ -48,7 +48,7 @@
4848
<nil key="textColor"/>
4949
<nil key="highlightedColor"/>
5050
</label>
51-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalCompressionResistancePriority="1000" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jZp-8m-qQK">
51+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalCompressionResistancePriority="1000" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jZp-8m-qQK">
5252
<rect key="frame" x="0.0" y="29.333333333333339" width="120.33333333333333" height="40.666666666666657"/>
5353
<string key="text">Description text
5454
Description text</string>

swift-sdk/uicomponents/IterableEmbeddedView.swift

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ public class IterableEmbeddedView:UIView {
200200
])
201201
}
202202

203+
// func loadViewFromNib() -> UIView? {
204+
// let nib = UINib(nibName: "IterableEmbeddedView", bundle: Bundle.module)
205+
// let view = nib.instantiate(withOwner: self, options: nil).first as? UIView
206+
// self.clipsToBounds = false
207+
// return view
208+
// }
209+
203210
func loadViewFromNib() -> UIView? {
204211
var nib: UINib
205212
#if COCOAPODS
@@ -217,6 +224,7 @@ public class IterableEmbeddedView:UIView {
217224
self.clipsToBounds = false
218225
return view
219226
}
227+
220228

221229
public func configure(message: IterableEmbeddedMessage, viewType: IterableEmbeddedViewType, config: IterableEmbeddedViewConfig?) {
222230

@@ -382,41 +390,8 @@ public class IterableEmbeddedView:UIView {
382390
return size.width
383391
}
384392

385-
public func updateButtonConstraints() {
386-
let bothButtonsVisible = !primaryBtn.isHidden && !secondaryBtn.isHidden
387-
388-
if !bothButtonsVisible {
389-
buttonStackView.axis = .horizontal
390-
horizontalButtonStackViewSpacer.isHidden = false
391-
return
392-
}
393-
394-
let doesTextWrapInPrimary = doesTextWrapInButton(primaryBtn)
395-
let doesTextWrapInSecondary = doesTextWrapInButton(secondaryBtn)
396-
397-
let shouldStackVertically = doesTextWrapInPrimary || doesTextWrapInSecondary
398-
399-
buttonStackView.axis = shouldStackVertically ? .vertical : .horizontal
400-
horizontalButtonStackViewSpacer.isHidden = shouldStackVertically
401-
}
402-
403-
private func doesTextWrapInButton(_ button: UIButton) -> Bool {
404-
guard let text = button.titleLabel?.text, let font = button.titleLabel?.font else {
405-
return false
406-
}
407-
408-
let maxSize = CGSize(width: CGFloat.greatestFiniteMagnitude, height: button.bounds.height)
409-
let textRect = text.boundingRect(with: maxSize, options: .usesLineFragmentOrigin, attributes: [.font: font], context: nil)
410-
411-
return textRect.width > button.bounds.width
412-
}
413-
414-
415393
public override func layoutSubviews() {
416394
super.layoutSubviews()
417-
DispatchQueue.main.async {
418-
self.updateButtonConstraints()
419-
}
420395
}
421396
}
422397

@@ -507,6 +482,9 @@ public class IterableEMButton: UIButton {
507482
cornerRadii: CGSize(width: bounds.height / 2, height: bounds.height / 2))
508483
maskLayer.path = path.cgPath
509484
}
485+
486+
titleLabel?.numberOfLines = 1
487+
titleLabel?.lineBreakMode = .byTruncatingTail
510488
}
511489
}
512490

0 commit comments

Comments
 (0)