-
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: get WebView for inline message and add to Inline View to display #717
Conversation
Sample app builds 📱Below you will find the list of the latest versions of the sample apps. It's recommended to always download the latest builds of the sample apps to accurately test the pull request.
|
f506cd0
to
cc11137
Compare
930f336
to
7498c5d
Compare
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.
This is the main logic of this PR. MessageManager
contains a lot of code that's common between inline and modal messages. ModalMessageManager
contains code I pulled out of MessageManager
that's only used for modal messages.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature-inline-inapp #717 +/- ##
=======================================================
Coverage ? 58.25%
=======================================================
Files ? 142
Lines ? 3953
Branches ? 0
=======================================================
Hits ? 2303
Misses ? 1650
Partials ? 0 ☔ View full report in Codecov by Sentry. |
7498c5d
to
3c6243d
Compare
cc11137
to
4a32afa
Compare
if route == currentMessage.messageId, !messageLoaded { | ||
messageLoaded = true | ||
if isMessageEmbed { | ||
delegate?.messageShown(message: currentMessage) | ||
} else { | ||
if UIApplication.shared.applicationState == .active { | ||
loadModalMessage() | ||
} else { | ||
Gist.shared.removeMessageManager(instanceId: currentMessage.instanceId) | ||
} | ||
} | ||
} |
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.
This is code that should only be called for modal messages. So I moved this block into the Modal manager subclass.
if let modalViewManager = modalViewManager { | ||
modalViewManager.dismissModalView { [weak self] in | ||
guard let self = self else { return } | ||
self.delegate?.messageDismissed(message: self.currentMessage) | ||
completionHandler?() | ||
} | ||
} |
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.
This is code that should only be called for modal messages. So I moved this block into the Modal manager subclass.
@@ -65,5 +71,36 @@ public class InAppMessageView: UIView { | |||
// } | |||
} | |||
|
|||
private func displayInAppMessage(_ message: Message) {} | |||
private func displayInAppMessage(_ message: Message) { |
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.
This function's body is the logic that creates a WebView and renders the in-app message in the WebView. Most of this logic comes from InlineMessageManager
. So all we need to do in the inline View is create a InlineMessageManager
instance and setup the WebView for displaying in this View.
SDK binary size reports 📊SDK binary size of this PR
SDK binary size diff report between this PR and the main branch
|
3c6243d
to
2635ed8
Compare
ebabee3
to
4d63f69
Compare
class InlineMessageManager: MessageManager {} | ||
|
||
/** | ||
Class that implements the business logic for a modal message being displayed. | ||
*/ | ||
class ModalMessageManager: MessageManager { |
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.
Why are we using inheritance here?
I understand there is common logic, but we can extract the common logic in its own utility type, and use it in two different implementations.
Inheritance obscures the side effect of doing a single change and can be hard to trace at times
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.
See my latest update.
completionHandler?() | ||
} | ||
} | ||
// expect subclass implements this. |
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.
I am honestly not big fan of subclassing when there are different approaches that makes the code easier to follow.
MessageManager can simply be a protocol with two different implementations if needed. The actual implementations can use similar utility functions for the common logic.
Inheritance is a very strong relation and unless absolutely a must, we can almost always find simpler approaches
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.
See my latest update.
2635ed8
to
a7c9c1f
Compare
5458040
to
5581d89
Compare
I just pushed a change based on review suggestions. I kept I modified the There could be a better design pattern over this approach, but I think it will require more refactoring to the existing Modal in-app message code in the SDK. |
Part of: https://linear.app/customerio/issue/MBL-310/create-a-uikit-uiview-that-displays-an-inline-in-app-message-sent-from Create a WebView to display inline in-app message and display in the Inline UIView. To do this, we can re-use a lot of the same logic that Modal messages use to create WebViews and display them. Testing: There are some automated tests added in this commit. Reviewer notes: This commit will not show an in-app message if you were to add it to a sample app. Autolayout constraints need to be added to have Views resize and that will come in a future commit. commit-id:025c7bf5
5581d89
to
f0c5d97
Compare
Part of: https://linear.app/customerio/issue/MBL-310/create-a-uikit-uiview-that-displays-an-inline-in-app-message-sent-from
Create a WebView to display inline in-app message and display in the Inline UIView. To do this, we can re-use a lot of the same logic that Modal messages use to create WebViews and display them.
Testing:
There are some automated tests added in this commit.
Reviewer notes:
This commit will not show an in-app message if you were to add it to a sample app. Autolayout constraints need to be added to have Views resize and that will come in a future commit.
Stack: