Skip to content

Commit

Permalink
Updates to NTP Search Box (#3450)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1208612667210680/f

Description:
This change changes focus on New Tab Page to always be on the top address bar,
and also disables NTP settings onboarding popover for users not in the experiment.
  • Loading branch information
ayoy authored Oct 24, 2024
1 parent b566301 commit f72a6a9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
15 changes: 14 additions & 1 deletion DuckDuckGo/HomePage/Model/HomePageAddressBarModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,20 @@ extension HomePage.Models {
}
}
}
@Published var value: AddressBarTextField.Value = .text("", userTyped: false)
@Published var value: AddressBarTextField.Value = .text("", userTyped: false) {
didSet {
if shouldDisplayInitialPlaceholder && !value.string.isEmpty {
shouldDisplayInitialPlaceholder = false
}
}
}

/**
* This property is a workaround for placeholder not being displayed on the address bar in SwiftUI until focused.
*
* It's cleared after first edit on the field.
*/
@Published var shouldDisplayInitialPlaceholder = true

var addressBarTextField: AddressBarTextField? {
guard shouldShowAddressBar else {
Expand Down
24 changes: 20 additions & 4 deletions DuckDuckGo/HomePage/View/AddressBarTextFieldView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ struct BigSearchBox: View {
let isCompact: Bool
let supportsFixedColorScheme: Bool

@EnvironmentObject var addressBarModel: HomePage.Models.AddressBarModel
@Environment(\.colorScheme) private var colorScheme

init(isCompact: Bool, supportsFixedColorScheme: Bool = true) {
self.isCompact = isCompact
self.supportsFixedColorScheme = supportsFixedColorScheme
Expand Down Expand Up @@ -106,9 +109,22 @@ struct BigSearchBox: View {

@ViewBuilder
func searchField() -> some View {
AddressBarTextFieldView(supportsFixedColorScheme: supportsFixedColorScheme)
.frame(height: Const.searchBoxHeight)
.shadow(color: .black.opacity(0.2), radius: 4, x: 0, y: 3)
.shadow(color: .black.opacity(0.15), radius: 0, x: 0, y: 0)
ZStack {
AddressBarTextFieldView(supportsFixedColorScheme: supportsFixedColorScheme)
.shadow(color: .black.opacity(0.2), radius: 4, x: 0, y: 3)
.shadow(color: .black.opacity(0.15), radius: 0, x: 0, y: 0)
if #available(macOS 12.0, *), addressBarModel.shouldDisplayInitialPlaceholder {
HStack {
Text(UserText.addressBarPlaceholder)
.foregroundColor(Color(nsColor: NSColor.placeholderTextColor))
.background(Color.homePageAddressBarBackground)
.font(.system(size: 15))
.padding(.leading, 38)
.animation(.none, value: colorScheme) // don't animate color scheme change because NSTextField doesn't
Spacer()
}
}
}
.frame(height: Const.searchBoxHeight)
}
}
3 changes: 1 addition & 2 deletions DuckDuckGo/HomePage/View/HomePageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ final class HomePageViewController: NSViewController {
override func viewDidAppear() {
super.viewDidAppear()
refreshModels()
addressBarModel.addressBarTextField?.makeMeFirstResponder()

showSettingsOnboardingIfNeeded()
}
Expand Down Expand Up @@ -276,7 +275,7 @@ final class HomePageViewController: NSViewController {
}

private func showSettingsOnboardingIfNeeded() {
if !settingsVisibilityModel.didShowSettingsOnboarding {
if addressBarModel.shouldShowAddressBar && !settingsVisibilityModel.didShowSettingsOnboarding {
// async dispatch in order to get the final value for self.view.bounds
DispatchQueue.main.async {
guard let superview = self.view.superview else {
Expand Down
9 changes: 1 addition & 8 deletions DuckDuckGo/MainWindow/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,7 @@ final class MainViewController: NSViewController {
let tabContent = tabContent ?? selectedTabViewModel.tab.content

if case .newtab = tabContent {
let homeAddressBarTextField = browserTabViewController.homePageViewController?.addressBarModel?.addressBarTextField
let isHomeAddressBarVisible = browserTabViewController.homePageViewController?.appearancePreferences.isSearchBarVisible == true
if isHomeAddressBarVisible, let homeAddressBarTextField {
homeAddressBarTextField.makeMeFirstResponder()
} else {
navigationBarViewController.addressBarViewController?.addressBarTextField.makeMeFirstResponder()
}

navigationBarViewController.addressBarViewController?.addressBarTextField.makeMeFirstResponder()
} else {
// ignore published tab switch: BrowserTabViewController
// adjusts first responder itself
Expand Down

0 comments on commit f72a6a9

Please sign in to comment.