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 tweaks #471

Merged
merged 6 commits into from
Mar 17, 2022
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
3 changes: 2 additions & 1 deletion DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,11 @@ struct UserText {
static let homePageProtectionSummaryInfo = NSLocalizedString("home.page.protection.summary.info", value: "No recent activity", comment: "")
static func homePageProtectionSummaryMessage(numberOfTrackersBlocked: Int) -> String {
let localized = NSLocalizedString("home.page.protection.summary.info",
value: "%@ tracking attempts blocked in past 7 days",
value: "%@ tracking attempts blocked",
comment: "")
return String(format: localized, NumberFormatter.localizedString(from: NSNumber(value: numberOfTrackersBlocked), number: .decimal))
}
static let homePageProtectionDurationInfo = NSLocalizedString("home.page.protection.duration", value: "PAST 7 DAYS", comment: "Past 7 days in uppercase.")

static let homePageEmptyStateItemTitle = NSLocalizedString("home.page.empty.state.item.title", value: "Recently visited sites appear here", comment: "")
static let homePageEmptyStateItemMessage = NSLocalizedString("home.page.empty.state.item.message", value: "Keep browsing to see how many trackers were blocked", comment: "")
Expand Down
75 changes: 40 additions & 35 deletions DuckDuckGo/Home Page/View/FavoritesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,17 @@ struct Favorites: View {

var body: some View {

let addButton =
ZStack(alignment: .top) {
RoundedRectangle(cornerRadius: 12)
.stroke(Color("HomeFavoritesGhostColor"), style: StrokeStyle(lineWidth: 1.5))
.frame(width: 64, height: 64)

VStack(spacing: 5) {
HoverButton(size: 64, imageName: "Add", imageSize: 22, cornerRadius: 12) {
model.addNew()
}
.frame(width: 64, height: 64)

Text(UserText.addFavorite)
.font(.system(size: 10))
.multilineTextAlignment(.center)
.lineLimit(2)
.truncationMode(.middle)
.font(.system(size: 10))
.frame(height: 32, alignment: .top)
}
}.frame(width: 64)
let addButton = ZStack(alignment: .top) {
FavoriteTemplate(title: UserText.addFavorite, domain: nil)
ZStack {
Image("Add")
.resizable()
.frame(width: 22, height: 22)
}.frame(width: 64, height: 64)
}
.link {
model.addNew()
}

let ghostButton = VStack {
RoundedRectangle(cornerRadius: 12)
Expand Down Expand Up @@ -93,43 +83,58 @@ struct Favorites: View {

}

struct Favorite: View {

@EnvironmentObject var model: HomePage.Models.FavoritesModel
struct FavoriteTemplate: View {

let bookmark: Bookmark
let title: String
let domain: String?

@State var isHovering = false

var body: some View {

VStack(spacing: 5) {

ZStack(alignment: .center) {

RoundedRectangle(cornerRadius: 12)
.foregroundColor(isHovering ? Color("HomeFavoritesHoverColor") : Color("HomeFavoritesBackgroundColor"))

FaviconView(domain: bookmark.url.host ?? "")
.frame(width: 32, height: 32)
.padding(9)

if let domain = domain {
FaviconView(domain: domain)
.frame(width: 32, height: 32)
.padding(9)
}
}
.frame(width: 64, height: 64)
.clipped()

Text(bookmark.title)
Text(title)
.multilineTextAlignment(.center)
.lineLimit(2)
.font(.system(size: 10))
.font(.system(size: 11))
.frame(height: 32, alignment: .top)

}
.frame(width: 64)
.frame(maxWidth: 64)
.link(onHoverChanged: {
isHovering = $0
}) {
.onHover { isHovering in
self.isHovering = isHovering
}
}

}

struct Favorite: View {

@EnvironmentObject var model: HomePage.Models.FavoritesModel

let bookmark: Bookmark

@State var isHovering = false

var body: some View {

FavoriteTemplate(title: bookmark.title, domain: bookmark.url.host)
.link {
model.open(bookmark)
}.contextMenu(ContextMenu(menuItems: {
Button(UserText.openInNewTab, action: { model.openInNewTab(bookmark) })
Expand Down
30 changes: 18 additions & 12 deletions DuckDuckGo/Home Page/View/RecentlyVisitedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,31 @@ struct RecentlyVisitedTitle: View {
@Binding var isExpanded: Bool

var body: some View {
HStack(alignment: .center, spacing: 12) {
HStack(alignment: .top, spacing: 12) {
Image("HomeShield")
.resizable()
.frame(width: 32, height: 32)
.frame(width: 22, height: 22)
.onTapGesture(count: 2) {
model.showPagesOnHover.toggle()
}
.padding(.leading, isExpanded ? 5 : 0)

Group {
if model.recentSites.count > 0 {
Text(UserText.homePageProtectionSummaryMessage(numberOfTrackersBlocked: model.numberOfTrackersBlocked))
} else {
Text(UserText.homePageProtectionSummaryInfo)
}
VStack(alignment: isExpanded ? .leading : .center, spacing: 6) {
Text(UserText.homePageProtectionSummaryMessage(numberOfTrackersBlocked: model.numberOfTrackersBlocked))
.font(.system(size: 17, weight: .bold, design: .default))
.foregroundColor(Color("HomeFeedTitleColor"))

Text(UserText.homePageProtectionDurationInfo)
.font(.system(size: 13, weight: .medium, design: .default))
.foregroundColor(Color("HomeFeedItemTimeTextColor"))
}
.multilineTextAlignment(.center)
.lineLimit(2)
.font(.system(size: 17, weight: .bold, design: .default))
.foregroundColor(Color("HomeFeedTitleColor"))
.visibility(model.recentSites.count > 0 ? .visible : .gone)
.padding(.leading, 4)

Text(UserText.homePageProtectionSummaryInfo)
.font(.system(size: 17, weight: .bold, design: .default))
.foregroundColor(Color("HomeFeedTitleColor"))
.visibility(model.recentSites.count > 0 ? .gone : .visible)

Spacer()
.visibility(isExpanded ? .visible : .gone)
Expand Down
21 changes: 13 additions & 8 deletions DuckDuckGo/Main/View/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,26 @@ final class MainViewController: NSViewController {
}

private func resizeNavigationBarForHomePage(_ homePage: Bool, animated: Bool) {
let nonHomePageHeight: CGFloat = view.window?.isPopUpWindow == true ? 42 : 48
NSAnimationContext.runAnimationGroup { context in
context.duration = 0.1

let height = animated ? addressBarHeightConstraint.animator() : addressBarHeightConstraint
height?.constant = homePage ? 56 : nonHomePageHeight
let nonHomePageHeight: CGFloat = view.window?.isPopUpWindow == true ? 42 : 48

let divider = animated ? self.divider.animator() : self.divider
divider?.alphaValue = homePage ? 0 : 1.0
let height = animated ? addressBarHeightConstraint.animator() : addressBarHeightConstraint
height?.constant = homePage ? 56 : nonHomePageHeight

navigationBarViewController.resizeAddressBarForHomePage(homePage, animated: animated)
let divider = animated ? self.divider.animator() : self.divider
divider?.alphaValue = homePage ? 0 : 1.0

navigationBarViewController.resizeAddressBarForHomePage(homePage, animated: animated)
}
}

var lastTabContent: Tab.TabContent?
private func subscribeToTabContent() {
tabCollectionViewModel.selectedTabViewModel?.tab.$content.receive(on: DispatchQueue.main).sink(receiveValue: { [weak self] content in
// Animations disabled for time being (maybe forever)
self?.resizeNavigationBarForHomePage(content == .homePage, animated: false)
self?.resizeNavigationBarForHomePage(content == .homePage, animated: content == .homePage && self?.lastTabContent != .homePage)
self?.lastTabContent = content
}).store(in: &self.navigationalCancellables)
}

Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/NavigationBar/View/NavigationBar.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="8Ha-or-PB2">
<rect key="frame" x="0.0" y="3" width="44" height="44"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="jSz-y8-vaJ"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="HomePageLogo" id="O0O-qm-kNp"/>
</imageView>
<containerView translatesAutoresizingMaskIntoConstraints="NO" id="Wba-nA-FYj">
Expand Down Expand Up @@ -292,6 +295,7 @@
<outlet property="downloadsButton" destination="G8p-di-fq4" id="oxD-pc-8hn"/>
<outlet property="goBackButton" destination="kky-0N-Cfd" id="RA9-yE-URS"/>
<outlet property="goForwardButton" destination="mdE-u0-Ei5" id="7wT-nX-Avr"/>
<outlet property="logoWidthConstraint" destination="jSz-y8-vaJ" id="BbD-cr-Hyv"/>
<outlet property="navigationButtons" destination="eEh-kf-smR" id="XC4-bo-89V"/>
<outlet property="optionsButton" destination="iIF-Ky-unr" id="vvZ-mm-idv"/>
<outlet property="passwordManagementButton" destination="1nW-I1-nut" id="wDs-oE-b7d"/>
Expand Down
24 changes: 22 additions & 2 deletions DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ final class NavigationBarViewController: NSViewController {
@IBOutlet var addressBarTopConstraint: NSLayoutConstraint!
@IBOutlet var addressBarBottomConstraint: NSLayoutConstraint!
@IBOutlet var buttonsTopConstraint: NSLayoutConstraint!
@IBOutlet var logoWidthConstraint: NSLayoutConstraint!

lazy var downloadsProgressView: CircularProgressView = {
let bounds = downloadsButton.bounds
Expand Down Expand Up @@ -374,7 +375,10 @@ final class NavigationBarViewController: NSViewController {
})
}

var daxFadeInAnimation: DispatchWorkItem?
func resizeAddressBarForHomePage(_ homePage: Bool, animated: Bool) {
daxFadeInAnimation?.cancel()

let verticalPadding: CGFloat = view.window?.isPopUpWindow == true ? 0 : 6

let barTop = animated ? addressBarTopConstraint.animator() : addressBarTopConstraint
Expand All @@ -383,8 +387,24 @@ final class NavigationBarViewController: NSViewController {
let bottom = animated ? addressBarBottomConstraint.animator() : addressBarBottomConstraint
bottom?.constant = homePage ? 0 : verticalPadding

let logo = animated ? daxLogo.animator() : daxLogo
logo?.isHidden = !homePage
let logoWidth = animated ? logoWidthConstraint.animator() : logoWidthConstraint
logoWidth?.constant = homePage ? 44 : 0

daxLogo.alphaValue = homePage ? 0 : 1 // initial value to animate from

if animated {
let fadeIn = DispatchWorkItem { [weak self] in
NSAnimationContext.runAnimationGroup { ctx in
ctx.duration = 0.2
self?.daxLogo.animator().alphaValue = homePage ? 1 : 0
}
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: fadeIn)
self.daxFadeInAnimation = fadeIn
} else {
daxLogo.alphaValue = homePage ? 1 : 0
}

}

private func subscribeToDownloads() {
Expand Down