-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create inline UIView that checks if there are inline messages …
…in local queue Part of: https://linear.app/customerio/issue/MBL-310/create-a-uikit-uiview-that-displays-an-inline-in-app-message-sent-from Create a new public UIView that customers can add to their app's UI to display inline Views. This commit does not display messages yet. It only checks if there is an in-app message available to display inline with the equal elementId. Testing: Automated tests added in the commit. Some boilerplate code was added to allow mocking some dependencies and testing functions that were previously not very testable. Reviewer notes: This commit only handles the use case of inline Views being able to display inline messages after a fetch has already completed in the SDK. Future changes will handle when an inline View is visible and a fetch completes. commit-id:60639329
- Loading branch information
1 parent
490593e
commit 2635ed8
Showing
11 changed files
with
752 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import CioInternalCommon | ||
import Foundation | ||
import UIKit | ||
|
||
/** | ||
View that can be added to a customer's app UI to display inline in-app messages. | ||
|
||
Usage: | ||
1. Create an instance of this View and add it to the customer's app UI. | ||
``` | ||
// you can construct an instance with code: | ||
let inAppMessageView = InAppMessageView(elementId: "elementId") | ||
view.addSubView(inAppMessageView) | ||
|
||
// Or, if you use Storyboards: | ||
@IBOutlet weak var inAppMessageView: InAppMessageView! | ||
inAppMessageView.elementId = "elementId" | ||
``` | ||
2. Position and set size of the View in app's UI. The View will adjust it's height automatically, but all other constraints are the responsibilty of app developer. You can set a height constraint if you want autolayout warnings to go away but know that the View will ignore this set height. | ||
*/ | ||
public class InAppMessageView: UIView { | ||
private var localMessageQueue: MessageQueueManager { | ||
DIGraphShared.shared.messageQueueManager | ||
} | ||
|
||
// Can set in the constructor or can set later (like if you use Storyboards) | ||
public var elementId: String? { | ||
didSet { | ||
checkIfMessageAvailableToDisplay() | ||
} | ||
} | ||
|
||
public init(elementId: String) { | ||
super.init(frame: .zero) | ||
self.elementId = elementId | ||
|
||
// Setup the View and display a message, if one available. Since an elementId has been set. | ||
setupView() | ||
checkIfMessageAvailableToDisplay() | ||
} | ||
|
||
// This is called when the View is created from a Storyboard. | ||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
|
||
setupView() | ||
// An element id will not be set yet. No need to check for messages to display. | ||
} | ||
|
||
private func setupView() {} | ||
|
||
private func checkIfMessageAvailableToDisplay() { | ||
// 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 | ||
guard let elementId = elementId else { | ||
return | ||
} | ||
|
||
let queueOfMessagesForGivenElementId = localMessageQueue.getInlineMessages(forElementId: elementId) | ||
guard let messageToDisplay = queueOfMessagesForGivenElementId.first else { | ||
return // no messages to display, exit early. In the future we will dismiss the View. | ||
} | ||
|
||
displayInAppMessage(messageToDisplay) | ||
// } | ||
} | ||
|
||
private func displayInAppMessage(_ message: Message) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.