-
Notifications
You must be signed in to change notification settings - Fork 12
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
[CHNL-16564] update script and message handling #261
base: master
Are you sure you want to change the base?
Conversation
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.
Some minor questions but looks good to me
/// Scripts to be injected into the ``WKWebView`` when the website loads. | ||
var loadScripts: [String: WKUserScript]? { get } | ||
/// Scripts & message handlers to be injected into the ``WKWebView`` when the website loads. | ||
var loadScripts: Set<WKUserScript>? { get } |
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.
Do we need this since @evan-masseau mentioned that he doesn't think we may end up injecting scripts on the native side?
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.
yes, I'd like to leave it for 2 reasons:
- It gives us flexibility to easily inject scripts if/when we want to. Evan said on Friday that he suspects we may want/need to do that in the future
- It's optional, so if we decide we're not going to inject any scripts we can simply set that value to
nil
.
The way I built this, the KlaviyoWebViewController
is flexible and can be reused when injected with different ViewModels, as long as the VMs conform to the KlaviyoWebViewModeling
protocol. So we can, for example:
- instantiate one
KlaviyoWebViewController
using a viewModelWebsiteWithInjectedScriptsViewModel
- instantiate another
KlaviyoWebViewController
using a viewModelWebsiteWithoutInjectedScriptsViewModel
@@ -11,23 +11,34 @@ import Foundation | |||
import WebKit | |||
|
|||
class JSTestWebViewModel: KlaviyoWebViewModeling { |
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.
Is this the view model that we'd use to present a Klaviyo form?
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.
No, this is just for dev/testing purposes right now. Whatever we put into production for handling a Klaviyo form will be a different VM that confirms to KlaviyoWebViewModeling
. That protocol will mandate that we implement all properties and methods that the KlaviyoWebViewController
depends on
Description
This PR makes some updates to the KlaviyoWebViewModeling protocol, all conforming ViewModels, and the KlaviyoWebViewController. We will need these changes in order to handle the javascript messages that the in-app forms emit.
With this PR, I'm decoupling the javascript that gets injected into the WKWebView from the message handlers that get injected. This will allow us, in a future PR, to tell the WKWebView to listen for messages from the
KlaviyoNativeBridge
, even though we aren't injecting a script with the same name.Check List
Manual Test Plan