Skip to content

Commit

Permalink
Fix sending pixel when dismissing keyboard on NTP (#3709)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
dus7 authored Dec 10, 2024
1 parent 759aedb commit d43e29d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ class MainViewController: UIViewController {


var keyboardShowing = false
private var didSendGestureDismissPixel: Bool = false

@objc
private func keyboardDidShow() {
Expand All @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion DuckDuckGo/NewTabPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct NewTabPageView: View {
.simultaneousGesture(
DragGesture()
.onChanged({ value in
if value.translation.height > 0 {
if value.translation.height != 0 {
viewModel.beginDragging()
}
})
Expand Down Expand Up @@ -154,6 +154,8 @@ private extension NewTabPageView {
EmptyView()
}
}
// Prevent recreating geomery reader when keyboard is shown/hidden.
.ignoresSafeArea(.keyboard)
}

@ViewBuilder
Expand Down
4 changes: 3 additions & 1 deletion DuckDuckGo/SimpleNewTabPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
Expand Down Expand Up @@ -85,6 +85,8 @@ private extension SimpleNewTabPageView {
}
.withScrollKeyboardDismiss()
}
// Prevent recreating geomery reader when keyboard is shown/hidden.
.ignoresSafeArea(.keyboard)
}

@ViewBuilder
Expand Down

0 comments on commit d43e29d

Please sign in to comment.