Skip to content

Commit a5aa088

Browse files
committed
update embedded view
1 parent df0cd14 commit a5aa088

3 files changed

Lines changed: 77 additions & 86 deletions

File tree

Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,6 @@
7474
ReferencedContainer = "container:Example.xcodeproj">
7575
</BuildableReference>
7676
</BuildableProductRunnable>
77-
<EnvironmentVariables>
78-
<EnvironmentVariable
79-
key = "MPARTICLE_KEY"
80-
value = "us2-ea563c42b9151b4c96543cc89834258e"
81-
isEnabled = "YES">
82-
</EnvironmentVariable>
83-
<EnvironmentVariable
84-
key = "MPARTICLE_SECRET"
85-
value = "754VnSU5kU80JOGPQIHlu_ymNL5NA0GkEb1DIdz1Oa8dDfsPP2M9jsZOw3SMpRc6"
86-
isEnabled = "YES">
87-
</EnvironmentVariable>
88-
</EnvironmentVariables>
8977
</LaunchAction>
9078
<ProfileAction
9179
buildConfiguration = "Release"

Example/Example/HomeViewController.swift

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

22
import UIKit
3+
import Rokt_Widget
4+
import mParticle_Apple_SDK
35

46
class HomeViewController: UIViewController {
57

@@ -25,7 +27,6 @@ class HomeViewController: UIViewController {
2527
private lazy var stackView: UIStackView = {
2628
let stackView = UIStackView()
2729
stackView.axis = .vertical
28-
stackView.spacing = 8
2930
stackView.translatesAutoresizingMaskIntoConstraints = false
3031
stackView.distribution = .fill
3132
return stackView
@@ -62,40 +63,107 @@ class HomeViewController: UIViewController {
6263

6364
private let captionLabel: UILabel = {
6465
let label = UILabel()
65-
label.text = "® Rokt 2024 — All rights reserved"
66+
label.text = "® Rokt 2025 — All rights reserved"
6667
label.font = .systemFont(ofSize: 12, weight: .regular)
6768
label.textColor = .textColor
6869
label.textAlignment = .center
6970
label.numberOfLines = 0
71+
label.translatesAutoresizingMaskIntoConstraints = false
7072
return label
7173
}()
7274

75+
private let spacer: UIView = {
76+
let view = UIView()
77+
view.setContentHuggingPriority(.defaultLow, for: .vertical)
78+
view.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
79+
return view
80+
}()
81+
82+
private lazy var roktEmbeddedView: RoktEmbeddedView = RoktEmbeddedView()
83+
84+
private lazy var loadingIndicator: UIActivityIndicatorView = {
85+
let indicator = UIActivityIndicatorView(style: .medium)
86+
indicator.hidesWhenStopped = true
87+
indicator.isHidden = true
88+
indicator.translatesAutoresizingMaskIntoConstraints = false
89+
90+
view.addSubview(indicator)
91+
NSLayoutConstraint.activate([
92+
indicator.centerXAnchor.constraint(equalTo: view.centerXAnchor),
93+
indicator.centerYAnchor.constraint(equalTo: view.centerYAnchor)
94+
])
95+
return indicator
96+
}()
97+
7398
override func viewWillAppear(_ animated: Bool) {
7499
super.viewWillAppear(animated)
75100
view.backgroundColor = .white
76101
view.addSubview(stackView)
102+
view.addSubview(captionLabel)
77103

78104
[
79105
imageView,
80106
titleLabel,
81-
UIView(),
107+
spacer,
82108
displayButton,
83-
UIView(),
84-
captionLabel
109+
roktEmbeddedView
85110
].forEach { stackView.addArrangedSubview($0) }
86111

87112
NSLayoutConstraint.activate([
88113
stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: Constants.padding),
89114
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: Constants.padding),
90115
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -Constants.padding),
91-
stackView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -Constants.padding),
116+
stackView.bottomAnchor.constraint(lessThanOrEqualTo: captionLabel.topAnchor),
117+
118+
captionLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: Constants.padding),
119+
captionLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -Constants.padding),
120+
captionLabel.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
92121

93-
displayButton.centerYAnchor.constraint(equalTo: view.centerYAnchor),
94-
displayButton.heightAnchor.constraint(equalToConstant: Constants.buttonHeight),
122+
displayButton.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: Constants.padding),
95123
])
96124
}
97125

98126
@objc private func buttonTapped() {
99-
present(SampleViewController(), animated: true)
127+
let attributes = [
128+
"email": "j.smith@example.com",
129+
"firstname": "Jenny",
130+
"lastname": "Smith",
131+
"mobile": "(555)867-5309",
132+
"postcode": "90210",
133+
"country": "US"
134+
]
135+
136+
MParticle
137+
.sharedInstance()
138+
.rokt
139+
.selectPlacements(
140+
"RoktEmbeddedExperience",
141+
attributes: attributes,
142+
placements: ["RoktEmbedded1": roktEmbeddedView],
143+
onLoad: {
144+
// Optional callback for when the Rokt placement loads
145+
},
146+
onUnLoad: { [weak self] in
147+
// Optional callback for when the Rokt placement unloads
148+
self?.hideButton(false)
149+
},
150+
onShouldShowLoadingIndicator: { [weak self] in
151+
// Optional callback to show a loading indicator
152+
self?.loadingIndicator.startAnimating()
153+
},
154+
onShouldHideLoadingIndicator: { [weak self] in
155+
self?.loadingIndicator.stopAnimating()
156+
},
157+
onEmbeddedSizeChange: { selectedPlacement, widgetHeight in
158+
// Optional callback to get selectedPlacement and height required by the placement every time the height of the placement changes
159+
}
160+
)
161+
hideButton(true)
162+
}
163+
164+
private func hideButton(_ hide: Bool) {
165+
roktEmbeddedView.isHidden = !hide
166+
displayButton.isHidden = hide
167+
spacer.isHidden = hide
100168
}
101169
}

Example/Example/SampleViewController.swift

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)