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

New Tab Page Settings #3140

Merged
merged 19 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@
6F03CB072C32F173004179A8 /* PixelFiring.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F03CB062C32F173004179A8 /* PixelFiring.swift */; };
6F03CB092C32F331004179A8 /* PixelFiringAsync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F03CB082C32F331004179A8 /* PixelFiringAsync.swift */; };
6F0FEF6B2C516D540090CDE4 /* NewTabPageSettingsStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F0FEF6A2C516D540090CDE4 /* NewTabPageSettingsStorage.swift */; };
6F3537A22C4AB97A009F8717 /* NewTabPagePreferencesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F3537A12C4AB97A009F8717 /* NewTabPagePreferencesModel.swift */; };
6F0FEF6D2C52639E0090CDE4 /* ReorderableForEach.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F0FEF6C2C52639E0090CDE4 /* ReorderableForEach.swift */; };
6F35379E2C4AAF2E009F8717 /* NewTabPageSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F35379D2C4AAF2E009F8717 /* NewTabPageSettingsView.swift */; };
6F3537A02C4AAFD2009F8717 /* NewTabPageSettingsSectionItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F35379F2C4AAFD2009F8717 /* NewTabPageSettingsSectionItemView.swift */; };
6F3537A22C4AB97A009F8717 /* NewTabPageSettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F3537A12C4AB97A009F8717 /* NewTabPageSettingsModel.swift */; };
6F3537A42C4AC140009F8717 /* NewTabPageDaxLogoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F3537A32C4AC140009F8717 /* NewTabPageDaxLogoView.swift */; };
6F40D15B2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F40D15A2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift */; };
6F40D15E2C34436500BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F40D15C2C34436200BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift */; };
6F5345AF2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5345AE2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift */; };
Expand All @@ -276,6 +280,7 @@
6F96FF102C2B128500162692 /* NewTabPageCustomizeButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F96FF0F2C2B128500162692 /* NewTabPageCustomizeButtonView.swift */; };
6F9FFE262C579BCD00A238BE /* NewTabPageShortcutsSettingsStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE252C579BCD00A238BE /* NewTabPageShortcutsSettingsStorage.swift */; };
6F9FFE282C579DEA00A238BE /* NewTabPageSectionsSettingsStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE272C579DEA00A238BE /* NewTabPageSectionsSettingsStorage.swift */; };
6F9FFE2A2C57ADB100A238BE /* EditableShortcutsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE292C57ADB100A238BE /* EditableShortcutsView.swift */; };
6F9FFE2D2C57AE8F00A238BE /* NewTabPageShortcutsSettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE2C2C57AE8F00A238BE /* NewTabPageShortcutsSettingsModel.swift */; };
6F9FFE302C57B34800A238BE /* NewTabPageSectionsSettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F9FFE2F2C57B34800A238BE /* NewTabPageSectionsSettingsModel.swift */; };
6FA3438F2C3D3BC300470677 /* Favorite.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FA3438E2C3D3BC300470677 /* Favorite.swift */; };
Expand Down Expand Up @@ -1421,7 +1426,11 @@
6F03CB062C32F173004179A8 /* PixelFiring.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PixelFiring.swift; sourceTree = "<group>"; };
6F03CB082C32F331004179A8 /* PixelFiringAsync.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PixelFiringAsync.swift; sourceTree = "<group>"; };
6F0FEF6A2C516D540090CDE4 /* NewTabPageSettingsStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsStorage.swift; sourceTree = "<group>"; };
6F3537A12C4AB97A009F8717 /* NewTabPagePreferencesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPagePreferencesModel.swift; sourceTree = "<group>"; };
6F0FEF6C2C52639E0090CDE4 /* ReorderableForEach.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReorderableForEach.swift; sourceTree = "<group>"; };
6F35379D2C4AAF2E009F8717 /* NewTabPageSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsView.swift; sourceTree = "<group>"; };
6F35379F2C4AAFD2009F8717 /* NewTabPageSettingsSectionItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsSectionItemView.swift; sourceTree = "<group>"; };
6F3537A12C4AB97A009F8717 /* NewTabPageSettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsModel.swift; sourceTree = "<group>"; };
6F3537A32C4AC140009F8717 /* NewTabPageDaxLogoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageDaxLogoView.swift; sourceTree = "<group>"; };
6F40D15A2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDisplayDailyPixelBucket.swift; sourceTree = "<group>"; };
6F40D15C2C34436200BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDisplayDailyPixelBucketTests.swift; sourceTree = "<group>"; };
6F5345AE2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsPersistentStorage.swift; sourceTree = "<group>"; };
Expand All @@ -1438,6 +1447,7 @@
6F96FF0F2C2B128500162692 /* NewTabPageCustomizeButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageCustomizeButtonView.swift; sourceTree = "<group>"; };
6F9FFE252C579BCD00A238BE /* NewTabPageShortcutsSettingsStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageShortcutsSettingsStorage.swift; sourceTree = "<group>"; };
6F9FFE272C579DEA00A238BE /* NewTabPageSectionsSettingsStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSectionsSettingsStorage.swift; sourceTree = "<group>"; };
6F9FFE292C57ADB100A238BE /* EditableShortcutsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditableShortcutsView.swift; sourceTree = "<group>"; };
6F9FFE2C2C57AE8F00A238BE /* NewTabPageShortcutsSettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageShortcutsSettingsModel.swift; sourceTree = "<group>"; };
6F9FFE2F2C57B34800A238BE /* NewTabPageSectionsSettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSectionsSettingsModel.swift; sourceTree = "<group>"; };
6FA3438E2C3D3BC300470677 /* Favorite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Favorite.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3515,13 +3525,15 @@
name = NewTabPage;
sourceTree = "<group>";
};
6F35379C2C4AAF1C009F8717 /* Preferences */ = {
6F35379C2C4AAF1C009F8717 /* Settings */ = {
isa = PBXGroup;
children = (
6F9FFE2E2C57B14100A238BE /* Model */,
6F9FFE2B2C57AE4200A238BE /* Storage */,
6F35379D2C4AAF2E009F8717 /* NewTabPageSettingsView.swift */,
6F35379F2C4AAFD2009F8717 /* NewTabPageSettingsSectionItemView.swift */,
);
name = Preferences;
name = Settings;
sourceTree = "<group>";
};
6F691CC82C4979DD002E9553 /* Tooltip */ = {
Expand All @@ -3548,7 +3560,7 @@
children = (
6F9FFE2C2C57AE8F00A238BE /* NewTabPageShortcutsSettingsModel.swift */,
6F9FFE2F2C57B34800A238BE /* NewTabPageSectionsSettingsModel.swift */,
6F3537A12C4AB97A009F8717 /* NewTabPagePreferencesModel.swift */,
6F3537A12C4AB97A009F8717 /* NewTabPageSettingsModel.swift */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -3619,12 +3631,14 @@
6FE1273B2C204C0D00EB5724 /* Subviews */ = {
isa = PBXGroup;
children = (
6F35379C2C4AAF1C009F8717 /* Preferences */,
6F35379C2C4AAF1C009F8717 /* Settings */,
6FE127472C20941A00EB5724 /* Shortcuts */,
6FE127412C204DE900EB5724 /* Favorites */,
6F5CC0802C2AFFE400AFC840 /* ToggleExpandButtonView.swift */,
6F96FF0F2C2B128500162692 /* NewTabPageCustomizeButtonView.swift */,
6FB2A67D2C2DAFB4004D20C8 /* NewTabPageGridView.swift */,
6F0FEF6C2C52639E0090CDE4 /* ReorderableForEach.swift */,
6F3537A32C4AC140009F8717 /* NewTabPageDaxLogoView.swift */,
);
name = Subviews;
sourceTree = "<group>";
Expand All @@ -3645,6 +3659,7 @@
isa = PBXGroup;
children = (
6FE1273F2C204D9B00EB5724 /* ShortcutsView.swift */,
6F9FFE292C57ADB100A238BE /* EditableShortcutsView.swift */,
6FE1274A2C20943500EB5724 /* ShortcutItemView.swift */,
6F64AA5C2C4920D200CF4489 /* ShortcutAccessoryView.swift */,
6F64AA582C4818D700CF4489 /* NewTabPageShortcut.swift */,
Expand Down Expand Up @@ -6787,6 +6802,7 @@
31DE43C42C2C60E800F8C51F /* DuckPlayerModalPresenter.swift in Sources */,
37FCAAC029930E26000E420A /* FailedAssertionView.swift in Sources */,
4BBBBA922B03291700D965DA /* VPNWaitlistUserText.swift in Sources */,
6F0FEF6D2C52639E0090CDE4 /* ReorderableForEach.swift in Sources */,
F4E1936625AF722F001D2666 /* HighlightCutOutView.swift in Sources */,
6FB2A67C2C2D9DF0004D20C8 /* FavoritesEmptyStateView.swift in Sources */,
1E162605296840D80004127F /* Triangle.swift in Sources */,
Expand Down Expand Up @@ -6876,6 +6892,7 @@
8C4838B5221C8F7F008A6739 /* GestureToolbarButton.swift in Sources */,
EE276BEA2A77F823009167B6 /* NetworkProtectionRootViewController.swift in Sources */,
310ECFDD282A8BB0005029B3 /* EnableAutofillSettingsTableViewCell.swift in Sources */,
6F9FFE2A2C57ADB100A238BE /* EditableShortcutsView.swift in Sources */,
1E908BF329827C480008C8F3 /* AutoconsentManagement.swift in Sources */,
D6D95CE32B6D9F8800960317 /* AsyncHeadlessWebViewModel.swift in Sources */,
C185ED612BD4329700BAE9DC /* ImportPasswordsStatusHandler.swift in Sources */,
Expand Down Expand Up @@ -6943,7 +6960,7 @@
83BE9BC3215D69C1009844D9 /* AppConfigurationFetch.swift in Sources */,
37CF91622BB474AA00BADCAE /* CrashCollectionOnboardingView.swift in Sources */,
1EEC460627A9499600E75FCB /* DownloadsList.swift in Sources */,
6F3537A22C4AB97A009F8717 /* NewTabPagePreferencesModel.swift in Sources */,
6F3537A22C4AB97A009F8717 /* NewTabPageSettingsModel.swift in Sources */,
9F23B8032C2BCD0000950875 /* DaxDialogStyles.swift in Sources */,
C1641EAF2BC2F5140012607A /* ImportPasswordsViewController.swift in Sources */,
D63FF8982C1B6A45006DE24D /* DuckPlayer.swift in Sources */,
Expand Down Expand Up @@ -7098,6 +7115,7 @@
311BD1AD2836BB3900AEF6C1 /* AutofillItemsEmptyView.swift in Sources */,
C1F341C52A6924000032057B /* EmailAddressPromptView.swift in Sources */,
316931D727BD10BB0095F5ED /* SaveToDownloadsAlert.swift in Sources */,
6F35379E2C4AAF2E009F8717 /* NewTabPageSettingsView.swift in Sources */,
31C70B5B2804C61000FB6AD1 /* SaveAutofillLoginManager.swift in Sources */,
982123502B6D233E00F08C57 /* UserSession.swift in Sources */,
85449EFD23FDA71F00512AAF /* KeyboardSettings.swift in Sources */,
Expand Down Expand Up @@ -7195,6 +7213,7 @@
8505836A219F424500ED4EDB /* UIAlertControllerExtension.swift in Sources */,
C12726F22A5FF8CB00215B02 /* EmailSignupPromptViewController.swift in Sources */,
983EABB8236198F6003948D1 /* DatabaseMigration.swift in Sources */,
6F3537A42C4AC140009F8717 /* NewTabPageDaxLogoView.swift in Sources */,
314C92B827C3DD660042EC96 /* QuickLookPreviewView.swift in Sources */,
6F5345AF2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift in Sources */,
F1AE54E81F0425FC00D9A700 /* AuthenticationViewController.swift in Sources */,
Expand Down Expand Up @@ -7273,6 +7292,7 @@
CBD4F13F279EBFAF00B20FD7 /* HomeMessageViewModel.swift in Sources */,
1E4DCF4A27B6A38000961E25 /* DownloadListRepresentable.swift in Sources */,
1DEAADFB2BA71E9A00E25A97 /* SettingsPrivacyProtectionDescriptionView.swift in Sources */,
6F3537A02C4AAFD2009F8717 /* NewTabPageSettingsSectionItemView.swift in Sources */,
2DC3FC65C6D9DA634426672D /* AutofillNoAuthAvailableView.swift in Sources */,
6F03CAFC2C32C6F6004179A8 /* NewTabPageMessagesModel.swift in Sources */,
);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "Check-16.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "Shortcut-24.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions DuckDuckGo/EditableShortcutsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// EditableShortcutsView.swift
// DuckDuckGo
//
// Copyright © 2024 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 SwiftUI
import UniformTypeIdentifiers

struct EditableShortcutsView: View {

@ObservedObject private(set) var model: NewTabPageShortcutsSettingsModel

var body: some View {
NewTabPageGridView { _ in
ReorderableForEach(model.itemsSettings, id: \.item.id, isReorderingEnabled: true) { setting in
let isEnabled = model.enabledItems.contains(setting.item)
Button {
setting.isEnabled.wrappedValue.toggle()
} label: {
ShortcutItemView(shortcut: setting.item, accessoryType: isEnabled ? .selected : .add)
}
} preview: { setting in
ShortcutIconView(shortcut: setting.item).previewShape()
} onMove: { indices, newOffset in
withAnimation {
model.moveItems(from: indices, to: newOffset)
}
}
}
}
}

private extension View {
func previewShape() -> some View {
contentShape(.dragPreview, RoundedRectangle(cornerRadius: 8))
}
}

extension NewTabPageSettingsModel.NTPSetting<NewTabPageShortcut>: Reorderable, Hashable, Equatable {

var dropItemProvider: NSItemProvider {
NSItemProvider(object: item.id as NSString)
}

var dropType: UTType { .text }

static func == (lhs: Self, rhs: Self) -> Bool {
lhs.item == rhs.item
}

func hash(into hasher: inout Hasher) {
hasher.combine(item.hashValue)
}
}

#Preview {
ScrollView {
EditableShortcutsView(model: NewTabPageShortcutsSettingsModel())
}
.background(Color(designSystemColor: .background))
}
11 changes: 11 additions & 0 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ class MainViewController: UIViewController {
}
}

adjustNewTabPageSafeAreaInsets(for: position)
}

private func adjustNewTabPageSafeAreaInsets(for addressBarPosition: AddressBarPosition) {
switch addressBarPosition {
case .top:
newTabPageViewController?.additionalSafeAreaInsets = .zero
case .bottom:
newTabPageViewController?.additionalSafeAreaInsets = .init(top: 0, left: 0, bottom: 52, right: 0)
}
}

@objc func onShowFullSiteAddressChanged() {
Expand Down Expand Up @@ -742,6 +752,7 @@ class MainViewController: UIViewController {
newTabPageViewController = controller
addToContentContainer(controller: controller)
viewCoordinator.logoContainer.isHidden = true
adjustNewTabPageSafeAreaInsets(for: appSettings.currentAddressBarPosition)
} else {
let controller = HomeViewController.loadFromStoryboard(homePageConfiguration: homePageConfiguration,
model: tabModel,
Expand Down
33 changes: 33 additions & 0 deletions DuckDuckGo/NewTabPageDaxLogoView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// NewTabPageDaxLogoView.swift
// DuckDuckGo
//
// Copyright © 2024 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 SwiftUI

struct NewTabPageDaxLogoView: View {
var body: some View {
VStack {
Image(.home)
Image(.textDuckDuckGo)
}
}
}

#Preview {
NewTabPageDaxLogoView()
}
4 changes: 2 additions & 2 deletions DuckDuckGo/NewTabPageSectionsSettingsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import Foundation

typealias NewTabPageSectionsSettingsModel = NewTabPagePreferencesModel<NewTabPageSection, NewTabPageSectionsSettingsStorage>
typealias NewTabPageSectionsSettingsModel = NewTabPageSettingsModel<NewTabPageSection, NewTabPageSectionsSettingsStorage>

extension NewTabPageSectionsSettingsModel {
convenience init(storage: NewTabPageSectionsSettingsStorage = NewTabPageSectionsSettingsStorage()) {
self.init(preferencesStorage: storage)
self.init(settingsStorage: storage)
}
}
Loading
Loading