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-16220] present webview from host app #259

Merged
merged 12 commits into from
Jan 22, 2025

Conversation

ab1470
Copy link
Contributor

@ab1470 ab1470 commented Jan 22, 2025

Description

This PR adds the architecture to a) preload a website, and b) once the site is preloaded, present the website as a modal on top of whatever screen is currently visible.

I have also marked some objects as @_spi(KlaviyoPrivate), because we need to use these objects in the iOS test app without exposing them publicly to consumers of the SKD.

I also added some default implementation for the preloadWebsite and handleNavigationEvent functions to the KlaviyoWebViewModeling protocol.

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 wired up an example in the iOS test app to validate the changes.

Supporting Materials

This video shows the example I wired up in the iOS test app. After tapping the button, the KlavyioWebViewController preloads an "expensive" website (it's loading a very large image). After the preload completes, the image appears as a modal. Notice that I can still navigate through the app while the site is preloading.

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-01-22.at.01.20.49.mp4

@ab1470 ab1470 requested a review from a team as a code owner January 22, 2025 06:23
defer { isLoading = false }

try await viewModel.preloadWebsite(timeout: 8_000_000_000)
topController.present(viewController, animated: true, completion: nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this have changed after 8 seconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially. I can change the timeout to whatever we think would be appropriate. I just didn't want to wait forever for a website that never loads.

Any suggestions for what I should set the timeout to? 15 seconds? 30?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I mean the top view controller could that change before the site is loaded? The eight seconds is maybe fine...i wish we had a good way to track metrics like this from the sdk.

Copy link
Contributor Author

@ab1470 ab1470 Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's okay if the topController changes before the site loads, that's sorta the point of preloading. Notice the video above; I tap the "Show Picsum Overlay" button, which kicks off the preload. While it's preloading, I'm still able to navigate to different tabs (which changes the topController). Then, when the preload finishes, it presents the web view on top of whatever the current topController is

ok good catch. I changed it so that it grabs the topController after the preload finishes and right before presenting.

@@ -5,7 +5,7 @@
// Created by Andrew Balmer on 1/21/25.
//

@testable import KlaviyoUI
@testable @_spi(KlaviyoPrivate) import KlaviyoUI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this for a test if it's public already ( and 'testable')?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it won't compile without both @testable and @_spi


private let (navEventStream, navEventContinuation) = AsyncStream.makeStream(of: WKNavigationEvent.self)
public let (navEventStream, navEventContinuation) = AsyncStream.makeStream(of: WKNavigationEvent.self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a lot of public things in here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this was a tradeoff I made in order to make this change possible. I thought about dropping the KlaviyoWebViewModeling protocol and providing default implementation within the KlaviyoWebViewModel class, then allowing customization through subclassing, but I didn't like that approach because it doesn't force subclassers to implement their own script handlers

@ab1470 ab1470 force-pushed the ab/CHNL-16220/present-webview-from-host-app branch from 0a04b9d to f4186e7 Compare January 22, 2025 17:05
@ab1470 ab1470 merged commit b6a7989 into master Jan 22, 2025
14 checks passed
@ab1470 ab1470 deleted the ab/CHNL-16220/present-webview-from-host-app branch January 22, 2025 19:52
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.

3 participants