Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ab1470
Copy link
Contributor

@ab1470 ab1470 commented Jan 25, 2025

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

  • Are you changing anything with the public API?
  • Have you tested this change on real device?
  • Are your changes backwards compatible with previous SDK Versions?
  • Have you added unit test coverage for your changes?
  • Have you verified that your changes are compatible with all the operating system version this SDK currently supports?

Manual Test Plan

  1. I've tested this using Xcode previews and with the iOS test app

@ab1470 ab1470 requested a review from a team as a code owner January 25, 2025 00:18
Copy link
Contributor

@ajaysubra ajaysubra left a 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 }
Copy link
Contributor

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?

Copy link
Contributor Author

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:

  1. 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
  2. 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 viewModel WebsiteWithInjectedScriptsViewModel
  • instantiate another KlaviyoWebViewController using a viewModel WebsiteWithoutInjectedScriptsViewModel

@@ -11,23 +11,34 @@ import Foundation
import WebKit

class JSTestWebViewModel: KlaviyoWebViewModeling {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants