Skip to content

Commit

Permalink
fix: disable support for swiftui gesture recognizers autocapture
Browse files Browse the repository at this point in the history
  • Loading branch information
PouriaAmini committed Aug 2, 2024
1 parent 54403a5 commit 22d8898
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/Amplitude/Plugins/iOS/UIKitElementInteractions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class UIKitElementInteractions {

@objc static func didEndEditing(_ notification: NSNotification) {
guard let view = notification.object as? UIView else { return }
// Text fields in SwiftUI are identifiable only after the text field is edited.
let elementInteractionEvent = view.eventData.elementInteractionEvent(for: "didEndEditing")
amplitudeInstances.allObjects.forEach {
$0.track(event: elementInteractionEvent)
Expand Down Expand Up @@ -121,6 +122,13 @@ extension UIGestureRecognizer {
amp_setState(state)

guard state == .ended, let view else { return }

// TODO: Reduce SwiftUI noise by filtering out system gesture recognizers.
// Currently, the gesture recognizers with a SwiftUI view are blocked.
let targetClass = NSStringFromClass(type(of: view as AnyObject))
if targetClass.contains("SwiftUI") {
return
}

let gestureAction: String? = switch self {
case is UITapGestureRecognizer: "tap"
Expand Down

0 comments on commit 22d8898

Please sign in to comment.