From 015df0c38c170b6af638298d23d5cfc6ec94bad7 Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Thu, 12 Dec 2024 19:32:57 -0500 Subject: [PATCH] [iOS] Fix request desktop site action in new menu UI This change merges the UIActivity version of "Request Desktop Site"/"Request Mobile Site" to a single identifier that matches the new menu UI's action identifier and then correctly sets it up in the new menu. We specifically set it up as such because the new menu has to treat "Request Desktop Site" & "Request Mobile Site" as a single item since its user customizable --- .../BrowserViewController/BVC+Menu.swift | 24 ++++++++++++++++++- .../BVC+ShareActivity.swift | 8 ++++++- .../BVC+ToolbarDelegate.swift | 1 + .../Frontend/Share/ShareExtensionHelper.swift | 7 +----- .../Sources/BrowserMenu/BrowserMenu.swift | 12 ++++------ 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Menu.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Menu.swift index 74dd1f70fc46..64f25218ab55 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Menu.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Menu.swift @@ -493,6 +493,7 @@ extension BrowserViewController { func presentBrowserMenu( from sourceView: UIView, activities: [UIActivity], + tab: Tab?, pageURL: URL?, webView: WKWebView? ) { @@ -500,7 +501,7 @@ extension BrowserViewController { actions.append(vpnMenuAction) actions.append(contentsOf: destinationMenuActions(for: pageURL)) actions.append(contentsOf: pageActions(for: pageURL, webView: webView)) - let pageActivities: Set = Set( + var pageActivities: Set = Set( activities .compactMap { activity in guard let id = (activity as? MenuActivity)?.id, @@ -519,6 +520,27 @@ extension BrowserViewController { } } ) + if let tab, + let requestDesktopPageActivity = pageActivities.first(where: { $0.id == .requestDesktopSite }) + { + // Remove the UIActivity version and replace it with a manual version. + // The request desktop activity is special in the sense that it is dynamic based on the + // current tab user agent, but we don't use rely on the UIActivity information to populate + // actions in the new menu UI, so this replaces it with how we would compose it manually + pageActivities.remove(requestDesktopPageActivity) + pageActivities.insert( + .init( + id: .requestDesktopSite, + title: tab.isDesktopSite ? Strings.appMenuViewMobileSiteTitleString : nil, + image: tab.isDesktopSite ? "leo.smartphone" : nil, + handler: { @MainActor [unowned self, weak tab] _ in + tab?.switchUserAgent() + self.dismiss(animated: true) + return .none + } + ) + ) + } // Sets up empty actions for any page actions that weren't setup as UIActivity's let remainingPageActivities: [Action] = Action.ID.allPageActivites .subtracting(pageActivities.map(\.id)) diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ShareActivity.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ShareActivity.swift index 225e50e87356..c82f044c2421 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ShareActivity.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ShareActivity.swift @@ -145,9 +145,15 @@ extension BrowserViewController { } // Request Desktop Site Activity + let isDesktopSite = tab?.isDesktopSite ?? false + var requestDesktopSite = BasicMenuActivity.ActivityType.requestDesktopSite + if isDesktopSite { + requestDesktopSite.title = Strings.appMenuViewMobileSiteTitleString + requestDesktopSite.braveSystemImage = "leo.smartphone" + } activities.append( BasicMenuActivity( - activityType: tab?.isDesktopSite == true ? .requestMobileSite : .requestDesktopSite, + activityType: requestDesktopSite, callback: { tab?.switchUserAgent() } diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ToolbarDelegate.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ToolbarDelegate.swift index 65c37d9161dd..158f9d5eef4d 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ToolbarDelegate.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ToolbarDelegate.swift @@ -961,6 +961,7 @@ extension BrowserViewController: ToolbarDelegate { presentBrowserMenu( from: tabToolbar.menuButton, activities: activities, + tab: tabManager.selectedTab, pageURL: selectedTabURL, webView: tabManager.selectedTab?.webView ) diff --git a/ios/brave-ios/Sources/Brave/Frontend/Share/ShareExtensionHelper.swift b/ios/brave-ios/Sources/Brave/Frontend/Share/ShareExtensionHelper.swift index a1474974ca35..b96f375038d7 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Share/ShareExtensionHelper.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Share/ShareExtensionHelper.swift @@ -94,13 +94,8 @@ extension BasicMenuActivity.ActivityType { title: Strings.addToFavorites, braveSystemImage: "leo.widget.generic" ) - static let requestMobileSite: Self = .init( - id: "RequestMobileSite", - title: Strings.appMenuViewMobileSiteTitleString, - braveSystemImage: "leo.smartphone" - ) static let requestDesktopSite: Self = .init( - id: "RequestDesktopSite", + id: "ToggleUserAgent", title: Strings.appMenuViewDesktopSiteTitleString, braveSystemImage: "leo.monitor" ) diff --git a/ios/brave-ios/Sources/BrowserMenu/BrowserMenu.swift b/ios/brave-ios/Sources/BrowserMenu/BrowserMenu.swift index 535d846e0eb6..188e85dcc6b8 100644 --- a/ios/brave-ios/Sources/BrowserMenu/BrowserMenu.swift +++ b/ios/brave-ios/Sources/BrowserMenu/BrowserMenu.swift @@ -132,10 +132,8 @@ public struct BrowserMenu: View { } } .modifier(MenuRowButtonStyleModifier()) - .background( - Color(braveSystemName: .iosBrowserContainerHighlightIos), - in: .rect(cornerRadius: 14, style: .continuous) - ) + .background(Color(braveSystemName: .iosBrowserContainerHighlightIos)) + .clipShape(.rect(cornerRadius: 14, style: .continuous)) .transition(.blurReplace()) } Button { @@ -144,10 +142,8 @@ public struct BrowserMenu: View { Label(Strings.BrowserMenu.allSettingsButtonTitle, braveSystemImage: "leo.settings") } .modifier(MenuRowButtonStyleModifier()) - .background( - Color(braveSystemName: .iosBrowserContainerHighlightIos), - in: .rect(cornerRadius: 14, style: .continuous) - ) + .background(Color(braveSystemName: .iosBrowserContainerHighlightIos)) + .clipShape(.rect(cornerRadius: 14, style: .continuous)) } .padding() }