From 70f72e373b705663019a074f4d58def627b08a31 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 12 Nov 2024 14:00:53 -0500 Subject: [PATCH 01/17] added `PreviewGridViewController` --- .../PreviewGridViewController.swift | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewGridViewController.swift diff --git a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewGridViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewGridViewController.swift new file mode 100644 index 00000000..e184ccd5 --- /dev/null +++ b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewGridViewController.swift @@ -0,0 +1,65 @@ +// +// PreviewGridViewController.swift +// klaviyo-swift-sdk +// +// Created by Andrew Balmer on 10/23/24. +// + +#if DEBUG +import Foundation +import UIKit + +/// A sample grid view with randomly-colored tiles for internal Xcode preview purposes only. +class PreviewGridViewController: UIViewController, UICollectionViewDataSource { + var collectionView: UICollectionView! + + override func viewDidLoad() { + super.viewDidLoad() + + let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.5), heightDimension: .fractionalHeight(1.0)) + let item = NSCollectionLayoutItem(layoutSize: itemSize) + let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalWidth(0.4)) + let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item]) + group.interItemSpacing = .flexible(12) + let section = NSCollectionLayoutSection(group: group) + section.interGroupSpacing = 12 + section.contentInsets = .init(top: 0, leading: 16, bottom: 0, trailing: 16) + + let layout = UICollectionViewCompositionalLayout(section: section) + + collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) + collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell") + collectionView.dataSource = self + + view.addSubview(collectionView) + + // Disable autoresizing mask translation for Auto Layout + collectionView.translatesAutoresizingMaskIntoConstraints = false + + // Set up constraints using safeAreaLayoutGuide + NSLayoutConstraint.activate([ + collectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), + collectionView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor), + collectionView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor), + collectionView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor) + ]) + } + + // MARK: UICollectionViewDataSource + + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + 12 + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) + cell.backgroundColor = UIColor( + red: .random(in: 0...1), + green: .random(in: 0...1), + blue: .random(in: 0...1), + alpha: 1.0) + cell.layer.cornerRadius = 12.0 + return cell + } +} +#endif From 3f6db74fef5710f0cc36aebf21d1350c3b933d76 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 12 Nov 2024 14:22:21 -0500 Subject: [PATCH 02/17] changed preview URL to picsum --- Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift index a2198d08..8835588a 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift +++ b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift @@ -131,7 +131,7 @@ extension KlaviyoWebViewController: WKScriptMessageHandler { #if swift(>=5.9) @available(iOS 17.0, *) #Preview("Klaviyo.com") { - let url = URL(string: "https://www.klaviyo.com")! + let url = URL(string: "https://picsum.photos/200/300")! let viewModel = KlaviyoWebViewModel(url: url) return KlaviyoWebViewController(viewModel: viewModel) } From 3ed5a1a1463b33d34955ff6a43414b969dda80d0 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 12 Nov 2024 14:23:01 -0500 Subject: [PATCH 03/17] added `PreviewTabViewController` --- .../PreviewTabViewController.swift | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewTabViewController.swift diff --git a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewTabViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewTabViewController.swift new file mode 100644 index 00000000..ad667b67 --- /dev/null +++ b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewTabViewController.swift @@ -0,0 +1,36 @@ +// +// PreviewTabViewController.swift +// klaviyo-swift-sdk +// +// Created by Andrew Balmer on 10/23/24. +// + +#if DEBUG +import Foundation +import UIKit + +/// A sample tab view for internal Xcode preview purposes only. +class PreviewTabViewController: UITabBarController { + override func viewDidLoad() { + super.viewDidLoad() + + let firstVC = PreviewGridViewController() + let secondVC = UIViewController() + let thirdVC = UIViewController() + + firstVC.title = "Browse" + + firstVC.tabBarItem = UITabBarItem(title: "Browse", image: UIImage(systemName: "house"), tag: 0) + secondVC.tabBarItem = UITabBarItem(title: "Search", image: UIImage(systemName: "magnifyingglass"), tag: 1) + thirdVC.tabBarItem = UITabBarItem(title: "Profile", image: UIImage(systemName: "person"), tag: 2) + + viewControllers = [ + UINavigationController(rootViewController: firstVC), + UINavigationController(rootViewController: secondVC), + UINavigationController(rootViewController: thirdVC) + ] + + firstVC.navigationController?.navigationBar.prefersLargeTitles = true + } +} +#endif From 8399c97dc6533140ef9b2a6e35e5152fdfaac3d9 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 12 Nov 2024 14:24:23 -0500 Subject: [PATCH 04/17] add parent view for KlaviyoWebViewController previews --- .../KlaviyoWebViewController.swift | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift index 8835588a..e604e1d6 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift +++ b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift @@ -128,11 +128,24 @@ extension KlaviyoWebViewController: WKScriptMessageHandler { // MARK: - Previews +#if DEBUG +func createKlaviyoWebPreview(url: URL) -> UIViewController { + let viewModel = KlaviyoWebViewModel(url: url) + let viewController = KlaviyoWebViewController(viewModel: viewModel) + + // Add a dummy view as a parent to the KlaviyoWebViewController to preview what the + // KlaviyoWebViewController might look like when it's displayed on top of a view in an app. + let parentViewController = PreviewTabViewController() + parentViewController.view.addSubview(viewController.view) + + return parentViewController +} +#endif + #if swift(>=5.9) @available(iOS 17.0, *) #Preview("Klaviyo.com") { let url = URL(string: "https://picsum.photos/200/300")! - let viewModel = KlaviyoWebViewModel(url: url) - return KlaviyoWebViewController(viewModel: viewModel) + return createKlaviyoWebPreview(url: url) } #endif From d1e6360e2e0213f9c41fcaa54d9c87e55162bf32 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 12 Nov 2024 14:26:50 -0500 Subject: [PATCH 05/17] added klaviyo.html revised klaviyo.html --- .../KlaviyoWebView/Resources/HTML/klaviyo.html | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Sources/KlaviyoUI/KlaviyoWebView/Resources/HTML/klaviyo.html diff --git a/Sources/KlaviyoUI/KlaviyoWebView/Resources/HTML/klaviyo.html b/Sources/KlaviyoUI/KlaviyoWebView/Resources/HTML/klaviyo.html new file mode 100644 index 00000000..ad81f699 --- /dev/null +++ b/Sources/KlaviyoUI/KlaviyoWebView/Resources/HTML/klaviyo.html @@ -0,0 +1,10 @@ + + + + + + Mobile App Banner + + + + From d3f8d879e4ca9043bb466b7f4405b9b18432874e Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 12 Nov 2024 14:30:52 -0500 Subject: [PATCH 06/17] added maximum scale to klaviyo.html --- Sources/KlaviyoUI/KlaviyoWebView/Resources/HTML/klaviyo.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/Resources/HTML/klaviyo.html b/Sources/KlaviyoUI/KlaviyoWebView/Resources/HTML/klaviyo.html index ad81f699..1f4afe2d 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/Resources/HTML/klaviyo.html +++ b/Sources/KlaviyoUI/KlaviyoWebView/Resources/HTML/klaviyo.html @@ -2,7 +2,7 @@ - + Mobile App Banner From c7ba062fd5cbfc8b54d021c2675248ed6eacc61d Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 12 Nov 2024 14:27:15 -0500 Subject: [PATCH 07/17] added preview for Klaviyo form --- .../KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift index e604e1d6..6b9aca8b 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift +++ b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift @@ -148,4 +148,10 @@ func createKlaviyoWebPreview(url: URL) -> UIViewController { let url = URL(string: "https://picsum.photos/200/300")! return createKlaviyoWebPreview(url: url) } + +@available(iOS 17.0, *) +#Preview("Klaviyo Form") { + let indexHtmlFileUrl = Bundle.module.url(forResource: "klaviyo", withExtension: "html")! + return createKlaviyoWebPreview(url: indexHtmlFileUrl) +} #endif From 96b7cbc8e0171eb1dd998027f6c2f032db14933e Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 12 Nov 2024 14:27:42 -0500 Subject: [PATCH 08/17] set webview opacity --- Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift index 6b9aca8b..fded2c12 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift +++ b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift @@ -60,6 +60,7 @@ class KlaviyoWebViewController: UIViewController, WKUIDelegate { let webView = WKWebView(frame: .zero, configuration: config) // customize any WKWebView behaviors here // ex: webView.allowsBackForwardNavigationGestures = true + webView.isOpaque = false return webView } From 9d333026202b99a91c078c0ad3b2a66d3f8fdaaa Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 12 Nov 2024 14:28:43 -0500 Subject: [PATCH 09/17] prevent insetting webview to safe area --- Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift index fded2c12..8e8f742e 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift +++ b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift @@ -61,6 +61,8 @@ class KlaviyoWebViewController: UIViewController, WKUIDelegate { // customize any WKWebView behaviors here // ex: webView.allowsBackForwardNavigationGestures = true webView.isOpaque = false + webView.scrollView.contentInsetAdjustmentBehavior = .never + return webView } From ff89473bd6235648cf5a8d6cd5971bff3d67bdbf Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Mon, 18 Nov 2024 12:26:13 -0500 Subject: [PATCH 10/17] added preview --- .../Development Assets/PreviewGridViewController.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewGridViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewGridViewController.swift index e184ccd5..591ed17e 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewGridViewController.swift +++ b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/PreviewGridViewController.swift @@ -62,4 +62,13 @@ class PreviewGridViewController: UIViewController, UICollectionViewDataSource { return cell } } + +// MARK: - Previews + +#if swift(>=5.9) +@available(iOS 17.0, *) +#Preview { + PreviewTabViewController() +} +#endif #endif From 362f16fae13af1e91f1abf1f6a60a804370fa820 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Mon, 18 Nov 2024 13:26:23 -0500 Subject: [PATCH 11/17] added jstest.html and preview moved jstest file --- .../Development Assets/HTML/jstest.html | 137 ++++++++++++++++++ .../KlaviyoWebViewController.swift | 7 + 2 files changed, 144 insertions(+) create mode 100644 Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html diff --git a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html new file mode 100644 index 00000000..18b58927 --- /dev/null +++ b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html @@ -0,0 +1,137 @@ + + + + + + + +
+

Javascript Bridge
Test Page

+
+ +
+
+
Toggle
+
+ Toggle is off + +
+
+ +
+
Buttons
+
+ +
+
+
+ + + + + diff --git a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift index 8e8f742e..cfdb41ff 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift +++ b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift @@ -157,4 +157,11 @@ func createKlaviyoWebPreview(url: URL) -> UIViewController { let indexHtmlFileUrl = Bundle.module.url(forResource: "klaviyo", withExtension: "html")! return createKlaviyoWebPreview(url: indexHtmlFileUrl) } + +@available(iOS 17.0, *) +#Preview("JS Test Page") { + let indexHtmlFileUrl = Bundle.module.url(forResource: "jstest", withExtension: "html")! + let viewModel = KlaviyoWebViewModel(url: indexHtmlFileUrl) + return KlaviyoWebViewController(viewModel: viewModel) +} #endif From 6802df516674ca763301b554d921e6152f2c4b26 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 1 Oct 2024 17:21:50 -0400 Subject: [PATCH 12/17] added toggleHandler.js script --- .../Development Assets/Scripts/toggleHandler.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Sources/KlaviyoUI/KlaviyoWebView/Development Assets/Scripts/toggleHandler.js diff --git a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/Scripts/toggleHandler.js b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/Scripts/toggleHandler.js new file mode 100644 index 00000000..bf61b493 --- /dev/null +++ b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/Scripts/toggleHandler.js @@ -0,0 +1,8 @@ +var _selector = document.querySelector('input[name=myCheckbox]'); +_selector.addEventListener('change', function(event) { + if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.toggleMessageHandler) { + window.webkit.messageHandlers.toggleMessageHandler.postMessage({ + "toggleEnabled": _selector.checked + }); + } +}); From f156f7614c03418cec96e80f0a64624471105f82 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Mon, 18 Nov 2024 14:34:35 -0500 Subject: [PATCH 13/17] added Development Assets to package.swift --- Package.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 57a18cce..a7363b9d 100644 --- a/Package.swift +++ b/Package.swift @@ -61,7 +61,11 @@ let package = Package( name: "KlaviyoUI", dependencies: ["KlaviyoSwift"], path: "Sources/KlaviyoUI", - resources: [.process("KlaviyoWebView/Resources")]), + resources: [ + .process("KlaviyoWebView/Resources"), + .process("KlaviyoWebView/Development Assets/Scripts"), + .process("KlaviyoWebView/Development Assets/HTML") + ]), .testTarget( name: "KlaviyoUITests", dependencies: [ From 18e45f355e0f9a8f2249c1c1d3c557ec261f8b6f Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Mon, 18 Nov 2024 14:35:37 -0500 Subject: [PATCH 14/17] added JSTestWebViewModel --- .../JSTestWebViewModel.swift | 74 +++++++++++++++++++ .../KlaviyoWebViewController.swift | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 Sources/KlaviyoUI/KlaviyoWebView/Development Assets/JSTestWebViewModel.swift diff --git a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/JSTestWebViewModel.swift b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/JSTestWebViewModel.swift new file mode 100644 index 00000000..a52a4f18 --- /dev/null +++ b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/JSTestWebViewModel.swift @@ -0,0 +1,74 @@ +// +// JSTestWebViewModel.swift +// klaviyo-swift-sdk +// +// Created by Andrew Balmer on 11/18/24. +// + +#if DEBUG +import Combine +import Foundation +import WebKit + +class JSTestWebViewModel: KlaviyoWebViewModeling { + let url: URL + let loadScripts: [String: WKUserScript]? + + /// Publishes scripts for the `WKWebView` to execute. + private var continuation: AsyncStream<(script: String, callback: ((Result) -> Void)?)>.Continuation? + lazy var scriptStream: AsyncStream<(script: String, callback: ((Result) -> Void)?)> = AsyncStream { [weak self] continuation in + self?.continuation = continuation + } + + init(url: URL) { + self.url = url + loadScripts = JSTestWebViewModel.initializeLoadScripts() + } + + private static func initializeLoadScripts() -> [String: WKUserScript] { + var scripts: [String: WKUserScript] = [:] + + if let toggleHandlerScript = try? FileIO.getFileContents(path: "toggleHandler", type: "js") { + let script = WKUserScript(source: toggleHandlerScript, injectionTime: .atDocumentEnd, forMainFrameOnly: true) + scripts["toggleMessageHandler"] = script + } + + return scripts + } + + // MARK: handle WKWebView events + + func handleNavigationEvent(_ event: WKNavigationEvent) { + // TODO: handle navigation events + } + + func handleScriptMessage(_ message: WKScriptMessage) { + if message.name == "toggleMessageHandler" { + guard let dict = message.body as? [String: AnyObject] else { + return + } + + guard let toggleEnabled = dict["toggleEnabled"] as? Bool else { + return + } + + print("toggle enabled: \(toggleEnabled)") + + let newStatus = toggleEnabled ? "Toggle is on" : "Toggle is off" + + let script = "document.getElementById('toggle-status').innerText = \"\(newStatus)\"" + + continuation?.yield((script, { result in + switch result { + case let .success(content): + if let successMessage = content as? String { + print("Successfully evaluated Javascript; message: \(successMessage)") + } + case let .failure(failure): + print("Javascript evaluation failed; message: \(failure.localizedDescription)") + } + })) + } + } +} +#endif diff --git a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift index cfdb41ff..46287b4f 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift +++ b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift @@ -161,7 +161,7 @@ func createKlaviyoWebPreview(url: URL) -> UIViewController { @available(iOS 17.0, *) #Preview("JS Test Page") { let indexHtmlFileUrl = Bundle.module.url(forResource: "jstest", withExtension: "html")! - let viewModel = KlaviyoWebViewModel(url: indexHtmlFileUrl) + let viewModel = JSTestWebViewModel(url: indexHtmlFileUrl) return KlaviyoWebViewController(viewModel: viewModel) } #endif From 10d5bd7ed718dcf1791f6174c4215897826736d1 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Wed, 20 Nov 2024 18:19:37 -0500 Subject: [PATCH 15/17] revised test page added background and safe area insets --- .../Development Assets/HTML/jstest.html | 107 +++++++++++++++--- 1 file changed, 89 insertions(+), 18 deletions(-) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html index 18b58927..ad4d551e 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html +++ b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html @@ -1,15 +1,45 @@ - + -
-

Javascript Bridge
Test Page

-
+
+
+

Javascript Bridge
Test Page

+
-
Toggle
@@ -125,6 +162,41 @@

Javascript Bridge
Test Page

+ + +
+
Placeholder Content
+
+ Item 1 +
+
+ Item 2 +
+
+ Item 3 +
+
+ Item 4 +
+
+ Item 5 +
+
+ Item 6 +
+
+ Item 7 +
+
+ Item 8 +
+
+ Item 9 +
+
+ Item 10 +
+
- From cecaf34860ecd9cd5d7171258747f2e60720424a Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Fri, 22 Nov 2024 15:40:39 -0500 Subject: [PATCH 16/17] removed some dummy content --- .../Development Assets/HTML/jstest.html | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html index ad4d551e..ce300756 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html +++ b/Sources/KlaviyoUI/KlaviyoWebView/Development Assets/HTML/jstest.html @@ -172,30 +172,6 @@

Javascript Bridge
Test Page

Item 2
-
- Item 3 -
-
- Item 4 -
-
- Item 5 -
-
- Item 6 -
-
- Item 7 -
-
- Item 8 -
-
- Item 9 -
-
- Item 10 -
From f9805805a5872233ce467973b4475d4133731576 Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Fri, 22 Nov 2024 15:58:19 -0500 Subject: [PATCH 17/17] refactored previews --- .../KlaviyoWebViewController.swift | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift index 46287b4f..f73d4a1c 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift +++ b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebViewController.swift @@ -132,14 +132,24 @@ extension KlaviyoWebViewController: WKScriptMessageHandler { // MARK: - Previews #if DEBUG -func createKlaviyoWebPreview(url: URL) -> UIViewController { - let viewModel = KlaviyoWebViewModel(url: url) +func createKlaviyoWebPreview(viewModel: KlaviyoWebViewModeling) -> UIViewController { let viewController = KlaviyoWebViewController(viewModel: viewModel) // Add a dummy view as a parent to the KlaviyoWebViewController to preview what the // KlaviyoWebViewController might look like when it's displayed on top of a view in an app. let parentViewController = PreviewTabViewController() + + parentViewController.addChild(viewController) parentViewController.view.addSubview(viewController.view) + viewController.didMove(toParent: parentViewController) + + viewController.view.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + viewController.view.topAnchor.constraint(equalTo: parentViewController.view.topAnchor), + viewController.view.bottomAnchor.constraint(equalTo: parentViewController.view.bottomAnchor), + viewController.view.leadingAnchor.constraint(equalTo: parentViewController.view.leadingAnchor), + viewController.view.trailingAnchor.constraint(equalTo: parentViewController.view.trailingAnchor) + ]) return parentViewController } @@ -149,13 +159,15 @@ func createKlaviyoWebPreview(url: URL) -> UIViewController { @available(iOS 17.0, *) #Preview("Klaviyo.com") { let url = URL(string: "https://picsum.photos/200/300")! - return createKlaviyoWebPreview(url: url) + let viewModel = KlaviyoWebViewModel(url: url) + return createKlaviyoWebPreview(viewModel: viewModel) } @available(iOS 17.0, *) #Preview("Klaviyo Form") { let indexHtmlFileUrl = Bundle.module.url(forResource: "klaviyo", withExtension: "html")! - return createKlaviyoWebPreview(url: indexHtmlFileUrl) + let viewModel = KlaviyoWebViewModel(url: indexHtmlFileUrl) + return createKlaviyoWebPreview(viewModel: viewModel) } @available(iOS 17.0, *)