-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: display inline messages fetched after View constructed #720
Changes from all commits
f0c5d97
1c38f27
f96607f
22b4183
8b62311
c89822c
9f25d06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,21 +33,19 @@ class DashboardViewController: BaseViewController { | |
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
// In a future PR, we will remove the asyncAfter(). this is only for testing in sample apps because when app opens, the local queue is empty. so wait to check messages until first fetch is done. | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 5) { [self] in | ||
inlineInAppViewCreatedInStoryboard.elementId = "dashboard-announcement" | ||
|
||
// We want to test that Inline Views can be used by customers who prefer to use code to make the UI. | ||
// Construct a new instance of the View, add it to the ViewController, then set constraints to make it visible. | ||
let newInlineViewUsingUIAsCode = InAppMessageView(elementId: "dashboard-announcement-code") | ||
// Because the Dashboard screen contains a lot of Views and it's designed using Storyboard, we are | ||
// adding this inline View into the UI by adding to a StackView. This allows us to dyanamically add to the Dashboard screen without complexity or breaking any of the constraints set in Storyboard. | ||
buttonStackView.addArrangedSubview(newInlineViewUsingUIAsCode) | ||
|
||
// Customers are responsible for setting the width of the View. | ||
newInlineViewUsingUIAsCode.translatesAutoresizingMaskIntoConstraints = false | ||
newInlineViewUsingUIAsCode.widthAnchor.constraint(equalTo: buttonStackView.widthAnchor).isActive = true | ||
} | ||
// For inline Views added with Storyboard, set the elementId to finish setup of the View and begin showing messages. | ||
inlineInAppViewCreatedInStoryboard.elementId = "dashboard-announcement" | ||
|
||
// We want to test that Inline Views can be used by customers who prefer to use code to make the UI. | ||
// Construct a new instance of the View, add it to the ViewController, then set constraints to make it visible. | ||
let newInlineViewUsingUIAsCode = InAppMessageView(elementId: "dashboard-announcement-code") | ||
// Because the Dashboard screen contains a lot of Views and it's designed using Storyboard, we are | ||
// adding this inline View into the UI by adding to a StackView. This allows us to dyanamically add to the Dashboard screen without complexity or breaking any of the constraints set in Storyboard. | ||
buttonStackView.addArrangedSubview(newInlineViewUsingUIAsCode) | ||
|
||
// Customers are responsible for setting the width of the View. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i might have missed it but whats the default behaviour if customers dont? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default behavior is that the view does not add any width constraint. We assume that the developer set one for us. As far as what will happen if you don't set a width, that would depend on your app's UI code. AutoLayout can be unpredictable as every layout is different in how it behaves. I think this requirement is reasonable when working with AutoLayout in UIKit. Especially when working with Storyboard, you're used to setting all of the constraints of all of the Views in your app. Think of it like in Android, you can set a default width to let's say match parent. But really, it's reasonable to assume that you're going to set a width on your View when you add it to your app, especially when using XML layouts and getting lint warnings for not setting a width on a View. Compose might be different as we may have default parameters set for width. SwiftUI could probably behavior similarly to Compose in that way. Happy to talk about this in more depth if you have more questions. |
||
newInlineViewUsingUIAsCode.translatesAutoresizingMaskIntoConstraints = false | ||
newInlineViewUsingUIAsCode.widthAnchor.constraint(equalTo: buttonStackView.widthAnchor).isActive = true | ||
|
||
configureDashboardRouter() | ||
addNotifierObserver() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import CioInternalCommon | ||
import Foundation | ||
|
||
/* | ||
EventBus events that are specific to the in-app SDK. | ||
*/ | ||
|
||
/// When in-app SDK has fetched in-app messages from the server. | ||
public struct InAppMessagesFetchedEvent: EventRepresentable { | ||
public let storageId: String | ||
public let params: [String: String] | ||
public let timestamp: Date | ||
|
||
public init(storageId: String = UUID().uuidString, timestamp: Date = Date(), params: [String: String] = [:]) { | ||
self.storageId = storageId | ||
self.timestamp = timestamp | ||
self.params = params | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,10 +117,6 @@ public class Gist: GistInstance, GistDelegate { | |
delegate?.action(message: message, currentRoute: currentRoute, action: action, name: name) | ||
} | ||
|
||
public func embedMessage(message: Message, elementId: String) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is a public function of Gist, but it's not part of our advertised public API. So removing it should not be considered a breaking change to our SDK. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we still need to provide customers with a way to add messages locally, we might need to check with in-app squad about this. We could probably give a method on top of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this feature isn't on the project roadmap, I'll hold off on creating a ticket or todo. If you think it's important, please pitch it to the team, perhaps in the project Slack channel. |
||
delegate?.embedMessage(message: message, elementId: elementId) | ||
} | ||
|
||
func logMessageView(message: Message) { | ||
// This function body reports metrics and makes sure that messages are not shown 2+ times. | ||
// For inline messages, we have not yet implemented either of these features. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just removed the
DispatchQueue.main.asyncAfter(deadline: .now() + 5) { [self]
and formatted the code.This delay is no longer needed after this commit since View will display messages that are fetched after the UI is in the foreground.