-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix duplicate domain navigation in Jetpack #25880
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,21 +13,17 @@ final class DomainDetailsWebViewController: WebKitViewController { | |
| static let manageAllDomainsPath = "\(domainsPath)/manage/all" | ||
| } | ||
|
|
||
| // MARK: - Properties | ||
|
|
||
| private let domain: String | ||
|
|
||
| private var observation: NSKeyValueObservation? | ||
|
|
||
| // MARK: - Init | ||
|
|
||
| init(domain: String, siteSlug: String, type: DomainType, analyticsSource: String? = nil) { | ||
| self.domain = domain | ||
| let url = Self.wpcomDetailsURL(domain: domain, siteSlug: siteSlug, type: type) | ||
| let configuration = WebViewControllerConfiguration(url: url) | ||
| configuration.customTitle = domain | ||
| configuration.analyticsSource = analyticsSource | ||
| configuration.secureInteraction = true | ||
| if let url { | ||
| configuration.linkBehavior = .urlOnly(url) | ||
| } | ||
| configuration.authenticateWithDefaultAccount() | ||
| super.init(configuration: configuration) | ||
| } | ||
|
|
@@ -40,25 +36,9 @@ final class DomainDetailsWebViewController: WebKitViewController { | |
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| self.observeURL() | ||
| self.trackWebViewShownEvent(url: url) | ||
| } | ||
|
|
||
| // MARK: - Handling URL Changes | ||
|
|
||
| private func observeURL() { | ||
| self.observation = webView.observe(\.url) { [weak self] webView, _ in | ||
| guard let self, let url = webView.url else { | ||
| return | ||
| } | ||
| if !self.shouldAllowNavigation(for: url) { | ||
| // Open URL in device browser then go back to Domain Management page. | ||
| self.open(url) | ||
| self.goBack() | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jkmassel @oguzkocer I believe the question of "why don't the links stay in the in-app web view" came up in the walkthrough. I traced this code a little bit, and I believe it's an intention design choice (see pcdRpT-3PI-p2): this specific "domain details" web page is modified to adapt the mobile app look & feel, which is quite different from the default Calypso look & feel. This adaptation is very likely to be per-page basis, which means links in the domain details will take user to the default Calypso UI which won't look right inside the mobile apps.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That context helps, thank you for tracing it. I read the external-link behavior as a general navigation policy, but if only the domain details page gets the mobile-specific treatment, keeping the linked Calypso pages out of the embedded web view makes sense. |
||
| } | ||
| } | ||
|
|
||
| // MARK: - Navigation | ||
|
|
||
| override func goBack() { | ||
|
|
@@ -84,14 +64,6 @@ final class DomainDetailsWebViewController: WebKitViewController { | |
| WPAnalytics.track(.allDomainsDomainDetailsWebViewShown, properties: properties) | ||
| } | ||
|
|
||
| private func shouldAllowNavigation(for url: URL) -> Bool { | ||
| return url.absoluteString == self.url?.absoluteString | ||
| } | ||
|
|
||
| private func open(_ url: URL) { | ||
| UIApplication.shared.open(url) | ||
| } | ||
|
|
||
| private static func wpcomDetailsURL(domain: String, siteSlug: String, type: DomainType) -> URL? { | ||
| let viewSlug = { | ||
| switch type { | ||
|
|
||
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.
The original PR intentionally went with the "observing URL" approach, because the
linkBehaviorimplementation is not sufficient to support the "open links in Safari" UX. See #21964 (comment)You can re-produce the issue by clicking the "Payment details" button. The existing implementation takes user to Safari which shows the Calypso UI, but this PR shows the web page directly inside the "domain details" in-app web view.
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.
You're right, and thanks for digging up the original discussion and checking the Payment details flow. I used
LinkBehaviorbecause it cleanly separates the automatic redirect behind CMM-2221 from normal.linkActivatednavigation, and theRenewsflow I tested still opened externally. I missed thatPayment detailschanges the URL without aWKNavigationDelegatecallback, which is exactly why this controller used KVO. So this approach would regress the intended behavior.