Skip to content

Commit

Permalink
Open keyboard on New Tab Page based on Settings (#3187)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/72649045549333/1207840822110802/f
Tech Design URL:
CC:

**Description**:

When opening New Tab Page keyboard needs to open according to setting in
General → Keyboard → New Tab.
  • Loading branch information
dus7 authored Aug 6, 2024
1 parent cca5220 commit 3dc474f
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 26 deletions.
4 changes: 0 additions & 4 deletions DuckDuckGo/HomeCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ class HomeCollectionView: UICollectionView {
menuController.showMenu(from: self, rect: menuView.frame)
}

func omniBarCancelPressed() {
renderers.omniBarCancelPressed()
}

func openedAsNewTab(allowingKeyboard: Bool) {
renderers.openedAsNewTab(allowingKeyboard: allowingKeyboard)
}
Expand Down
4 changes: 0 additions & 4 deletions DuckDuckGo/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,6 @@ class HomeViewController: UIViewController, NewTabPage {
collectionView.reloadData()
}

func omniBarCancelPressed() {
collectionView.omniBarCancelPressed()
}

func openedAsNewTab(allowingKeyboard: Bool) {
collectionView.openedAsNewTab(allowingKeyboard: allowingKeyboard)
if !variantManager.isSupported(feature: .newOnboardingIntro) {
Expand Down
8 changes: 0 additions & 8 deletions DuckDuckGo/HomeViewSectionRenderers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ protocol HomeViewSectionRenderer: AnyObject {

func remove(from controller: HomeViewController)

func omniBarCancelPressed()

func openedAsNewTab(allowingKeyboard: Bool)

func launchNewSearch()
Expand Down Expand Up @@ -136,12 +134,6 @@ class HomeViewSectionRenderers: NSObject,
return renderers[section]
}

func omniBarCancelPressed() {
renderers.forEach { renderer in
renderer.omniBarCancelPressed()
}
}

func openedAsNewTab(allowingKeyboard: Bool) {
renderers.forEach { renderer in
renderer.openedAsNewTab(allowingKeyboard: allowingKeyboard)
Expand Down
2 changes: 0 additions & 2 deletions DuckDuckGo/HomeViewSectionRenderersExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ extension HomeViewSectionRenderer {

func remove(from controller: HomeViewController) { }

func omniBarCancelPressed() { }

func openedAsNewTab(allowingKeyboard: Bool) { }

func menuItemsFor(itemAt: Int) -> [UIMenuItem]? {
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ class MainViewController: UIViewController {

controller.delegate = self
controller.shortcutsDelegate = self
controller.chromeDelegate = self

newTabPageViewController = controller
addToContentContainer(controller: controller)
Expand Down Expand Up @@ -1866,7 +1867,6 @@ extension MainViewController: OmniBarDelegate {
dismissOmniBar()
omniBar.cancel()
hideSuggestionTray()
homeController?.omniBarCancelPressed()
self.showMenuHighlighterIfNeeded()
}

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/NavigationSearchHomeViewSectionRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class NavigationSearchHomeViewSectionRenderer: HomeViewSectionRenderer {
func openedAsNewTab(allowingKeyboard: Bool) {
guard allowingKeyboard && KeyboardSettings().onNewTab else { return }
// The omnibar is inside a collection view so this needs to chance to do its thing
// which might also be async. Not great.
// which might also be async. Not great.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.launchNewSearch()
}
Expand Down
1 change: 0 additions & 1 deletion DuckDuckGo/NewTabPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ protocol NewTabPage: UIViewController {

func launchNewSearch()
func openedAsNewTab(allowingKeyboard: Bool)
func omniBarCancelPressed()

func dismiss()

Expand Down
12 changes: 7 additions & 5 deletions DuckDuckGo/NewTabPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,17 @@ final class NewTabPageViewController: UIHostingController<NewTabPageView<Favorit
weak var shortcutsDelegate: NewTabPageControllerShortcutsDelegate?

func launchNewSearch() {

chromeDelegate?.omniBar.becomeFirstResponder()
}

func openedAsNewTab(allowingKeyboard: Bool) {
guard allowingKeyboard && KeyboardSettings().onNewTab else { return }

}

func omniBarCancelPressed() {

// The omnibar is inside a collection view so this needs a chance to do its thing
// which might also be async. Not great.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.launchNewSearch()
}
}

func dismiss() {
Expand Down

0 comments on commit 3dc474f

Please sign in to comment.