-
Notifications
You must be signed in to change notification settings - Fork 36
Add different configuration variants for Browsing Menu Sheet #2691
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
Merged
dus7
merged 6 commits into
mariusz/streamline-menu-creation
from
mariusz/sheet-menu-variants
Dec 1, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
251531e
Add floating toolbar capability to Sheet menu
dus7 b3ff9b6
Add functions to build menu entries
dus7 fa65049
Add variant B
dus7 a830dca
Add variant C
dus7 075984d
Add variant D
dus7 ca4f5d5
Fix state initialization
dus7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
iOS/DuckDuckGo/BrowsingMenu/SheetPresentationMenu/BrowsingMenuVariantBBuilder.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| // | ||
| // BrowsingMenuVariantBBuilder.swift | ||
| // DuckDuckGo | ||
| // | ||
| // Copyright © 2025 DuckDuckGo. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
|
|
||
| import Foundation | ||
| import Bookmarks | ||
| import Core | ||
|
|
||
| /// Variant B Builder: Custom structure with specific sections | ||
| final class BrowsingMenuVariantBBuilder: BrowsingMenuVariantBuilder { | ||
| weak var entryBuilder: BrowsingMenuEntryBuilding? | ||
|
|
||
| init(entryBuilder: BrowsingMenuEntryBuilding) { | ||
| self.entryBuilder = entryBuilder | ||
| } | ||
|
|
||
| func buildMenu( | ||
| context: BrowsingMenuContext, | ||
| bookmarksInterface: MenuBookmarksInteracting, | ||
| mobileCustomization: MobileCustomization, | ||
| clearTabsAndData: @escaping () -> Void | ||
| ) -> BrowsingMenuModel? { | ||
|
|
||
| switch context { | ||
| case .newTabPage: | ||
| return buildNewTabPageMenu(mobileCustomization: mobileCustomization, | ||
| clearTabsAndData: clearTabsAndData) | ||
|
|
||
| case .aiChatTab: | ||
| return buildAIChatMenu() | ||
|
|
||
| case .website: | ||
| return buildWebsiteMenu( | ||
| bookmarksInterface: bookmarksInterface, | ||
| mobileCustomization: mobileCustomization, | ||
| clearTabsAndData: clearTabsAndData | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private func buildNewTabPageMenu(mobileCustomization: MobileCustomization, | ||
| clearTabsAndData: @escaping () -> Void) -> BrowsingMenuModel? { | ||
| guard let entryBuilder = entryBuilder else { return nil } | ||
|
|
||
| let headerItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(entryBuilder.makeNewTabEntry()), | ||
| .init(entryBuilder.makeChatEntry(withSmallIcon: false)) | ||
| ].compactMap { $0 } | ||
|
|
||
| let shortcutsItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(entryBuilder.makeOpenBookmarksEntry()), | ||
| .init(entryBuilder.makeAutoFillEntry()), | ||
| .init(entryBuilder.makeDownloadsEntry()) | ||
| ].compactMap { $0 } | ||
|
|
||
| let privacyItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(entryBuilder.makeVPNEntry()), | ||
| .init(entryBuilder.makeClearDataEntry(mobileCustomization: mobileCustomization, clearTabsAndData: clearTabsAndData)) | ||
| ].compactMap { $0 } | ||
|
|
||
| let sections = [ | ||
| BrowsingMenuModel.Section(items: shortcutsItems), | ||
| BrowsingMenuModel.Section(items: privacyItems) | ||
| ] | ||
|
|
||
| let footerItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(entryBuilder.makeSettingsEntry(useSmallIcon: false)) | ||
| ].compactMap { $0 } | ||
|
|
||
| return BrowsingMenuModel( | ||
| headerItems: headerItems, | ||
| sections: sections, | ||
| footerItems: footerItems | ||
| ) | ||
| } | ||
|
|
||
| private func buildWebsiteMenu( | ||
| bookmarksInterface: MenuBookmarksInteracting, | ||
| mobileCustomization: MobileCustomization, | ||
| clearTabsAndData: @escaping () -> Void | ||
| ) -> BrowsingMenuModel? { | ||
| guard let entryBuilder = entryBuilder else { return nil } | ||
|
|
||
| // Header: new tab, duck.ai (conditional) | ||
| let headerItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(entryBuilder.makeNewTabEntry()), | ||
| .init(entryBuilder.makeChatEntry(withSmallIcon: false)) | ||
| ].compactMap { $0 } | ||
|
|
||
| // Sections | ||
| var sections = [BrowsingMenuModel.Section]() | ||
|
|
||
| // Link section | ||
| if let bookmarkEntries = entryBuilder.makeBookmarkEntries(with: bookmarksInterface) { | ||
| let linkItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(bookmarkEntries.bookmark), | ||
| .init(bookmarkEntries.favorite, tag: .favorite), | ||
| .init(entryBuilder.makeShareEntry(useSmallIcon: true)) | ||
| ].compactMap { $0 } | ||
| sections.append(BrowsingMenuModel.Section(items: linkItems)) | ||
| } | ||
|
|
||
| // Tab actions section | ||
| let tabActionItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(entryBuilder.makeFindInPageEntry()), | ||
| .init(entryBuilder.makeZoomEntry()), | ||
| .init(entryBuilder.makeDesktopSiteEntry()) | ||
| ].compactMap { $0 } | ||
|
|
||
| if !tabActionItems.isEmpty { | ||
| sections.append(BrowsingMenuModel.Section(items: tabActionItems)) | ||
| } | ||
|
|
||
| // Shortcuts section | ||
| let shortcutItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(entryBuilder.makeOpenBookmarksEntry()), | ||
| .init(entryBuilder.makeAutoFillEntry()), | ||
| .init(entryBuilder.makeDownloadsEntry()) | ||
| ].compactMap { $0 } | ||
|
|
||
| if !shortcutItems.isEmpty { | ||
| sections.append(BrowsingMenuModel.Section(items: shortcutItems)) | ||
| } | ||
|
|
||
| // Privacy section | ||
| let privacyItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(entryBuilder.makeVPNEntry()), | ||
| .init(entryBuilder.makeUseNewDuckAddressEntry()), | ||
| .init(entryBuilder.makeToggleProtectionEntry()), | ||
| .init(entryBuilder.makeKeepSignInEntry()), | ||
| .init(entryBuilder.makeClearDataEntry(mobileCustomization: mobileCustomization, clearTabsAndData: clearTabsAndData)) | ||
| ].compactMap { $0 } | ||
|
|
||
| if !privacyItems.isEmpty { | ||
| sections.append(BrowsingMenuModel.Section(items: privacyItems)) | ||
| } | ||
|
|
||
| // Other section | ||
| let otherItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(entryBuilder.makeReloadEntry()), | ||
| .init(entryBuilder.makeReportBrokenSiteEntry()), | ||
| .init(entryBuilder.makePrintEntry(withSmallIcon: true)) | ||
| ].compactMap { $0 } | ||
|
|
||
| if !otherItems.isEmpty { | ||
| sections.append(BrowsingMenuModel.Section(items: otherItems)) | ||
| } | ||
|
|
||
| // Footer | ||
| let footerItems: [BrowsingMenuModel.Entry] = [ | ||
| .init(entryBuilder.makeSettingsEntry(useSmallIcon: false)) | ||
| ].compactMap { $0 } | ||
|
|
||
| return BrowsingMenuModel( | ||
| headerItems: headerItems, | ||
| sections: sections, | ||
| footerItems: footerItems | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.