-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/Issue URL: https://app.asana.com/0/1206226850447395/1207896254384739/f Tech Design URL: CC: **Description**: See #3159 first. New Tab Page Settings View, allowing to rearrange and toggle visibility of sections and shortcuts. Implementation caveats: Using Grid with drag/drop functionality inside a List allowing native UI for rearranging items is breaking drag/drop in Grid. It was necessary to include way to measure List content height and adjust it's size in order to place Grid below, outside the List content.
- Loading branch information
Showing
23 changed files
with
859 additions
and
118 deletions.
There are no files selected for viewing
This file contains 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
3 changes: 3 additions & 0 deletions
3
...uckGo/Assets.xcassets/DesignSystemIcons/16px/Check-16-alt.imageset/Check-16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions
16
DuckDuckGo/Assets.xcassets/DesignSystemIcons/16px/Check-16-alt.imageset/Contents.json
This file contains 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,16 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Check-16.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true, | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
DuckDuckGo/Assets.xcassets/DesignSystemIcons/24px/Shortcut-24.imageset/Contents.json
This file contains 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,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Shortcut-24.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...kGo/Assets.xcassets/DesignSystemIcons/24px/Shortcut-24.imageset/Shortcut-24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,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)) | ||
} |
This file contains 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 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,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() | ||
} |
This file contains 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.