From d43e29d71b4cd174db2740be3649f289fc70974d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20=C5=9Apiewak?= Date: Tue, 10 Dec 2024 16:48:19 +0100 Subject: [PATCH] Fix sending pixel when dismissing keyboard on NTP (#3709) Task/Issue URL: https://app.asana.com/0/1206226850447395/1208763673835126/f Tech Design URL: CC: **Description**: Fixed a few issues with sending pixel while dismissing keyboard with a swipe gesture: 1. Prevented sending pixel twice with a long gesture. 2. Fixed `isDragging` to set when swiping upwards. 3. Prevented stuttering of view while doing the scroll gesture with keyboard present. **Steps to test this PR**: Observe a **single** `m.addressbar.focus.dismiss.gesture` being sent while on a NTP with favorites and: 1. Dismissing keyboard by scrolling up 1. Dismissing keyboard by scrolling down 1. Dismissing keyboard by scrolling continuously up and down **Definition of Done (Internal Only)**: * [ ] Does this PR satisfy our [Definition of Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)? --- ###### Internal references: [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943) --- DuckDuckGo/MainViewController.swift | 5 ++++- DuckDuckGo/NewTabPageView.swift | 4 +++- DuckDuckGo/SimpleNewTabPageView.swift | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/DuckDuckGo/MainViewController.swift b/DuckDuckGo/MainViewController.swift index 565f096fd9..d142c865e7 100644 --- a/DuckDuckGo/MainViewController.swift +++ b/DuckDuckGo/MainViewController.swift @@ -525,6 +525,7 @@ class MainViewController: UIViewController { var keyboardShowing = false + private var didSendGestureDismissPixel: Bool = false @objc private func keyboardDidShow() { @@ -533,14 +534,16 @@ class MainViewController: UIViewController { @objc private func keyboardWillHide() { - if newTabPageViewController?.isDragging == true, keyboardShowing { + if !didSendGestureDismissPixel, newTabPageViewController?.isDragging == true, keyboardShowing { Pixel.fire(pixel: .addressBarGestureDismiss) + didSendGestureDismissPixel = true } } @objc private func keyboardDidHide() { keyboardShowing = false + didSendGestureDismissPixel = false } private func registerForPageRefreshPatterns() { diff --git a/DuckDuckGo/NewTabPageView.swift b/DuckDuckGo/NewTabPageView.swift index 219ddd9c27..0add43c1c9 100644 --- a/DuckDuckGo/NewTabPageView.swift +++ b/DuckDuckGo/NewTabPageView.swift @@ -76,7 +76,7 @@ struct NewTabPageView: View { .simultaneousGesture( DragGesture() .onChanged({ value in - if value.translation.height > 0 { + if value.translation.height != 0 { viewModel.beginDragging() } }) @@ -154,6 +154,8 @@ private extension NewTabPageView { EmptyView() } } + // Prevent recreating geomery reader when keyboard is shown/hidden. + .ignoresSafeArea(.keyboard) } @ViewBuilder diff --git a/DuckDuckGo/SimpleNewTabPageView.swift b/DuckDuckGo/SimpleNewTabPageView.swift index a228686ef5..a4fae0632b 100644 --- a/DuckDuckGo/SimpleNewTabPageView.swift +++ b/DuckDuckGo/SimpleNewTabPageView.swift @@ -49,7 +49,7 @@ struct SimpleNewTabPageView: View { .simultaneousGesture( DragGesture() .onChanged({ value in - if value.translation.height > 0 { + if value.translation.height != 0.0 { viewModel.beginDragging() } }) @@ -85,6 +85,8 @@ private extension SimpleNewTabPageView { } .withScrollKeyboardDismiss() } + // Prevent recreating geomery reader when keyboard is shown/hidden. + .ignoresSafeArea(.keyboard) } @ViewBuilder