Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import Common

extension UIInteraction: EventQueueItemPayload {
extension TouchInteraction: EventQueueItemPayload {
public func cost() -> Int {
300
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct TouchSample: Sendable {
}
}

typealias UIInteractionYield = @Sendable (UIInteraction) -> Void
typealias UIInteractionYield = @Sendable (TouchInteraction) -> Void

final class TouchCaptureCoordinator {
private let source: UIEventSource
Expand Down
8 changes: 4 additions & 4 deletions Sources/Observability/UIInteractions/TouchIntepreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class TouchIntepreter {
target: touchSample.target)
tracks[touchSample.id] = track

let downInteraction = UIInteraction(id: incrementingId,
let downInteraction = TouchInteraction(id: incrementingId,
kind: .touchDown(touchSample.location),
timestamp: touchSample.timestamp + uptimeDifference,
target: touchSample.target)
Expand Down Expand Up @@ -67,7 +67,7 @@ final class TouchIntepreter {
}

case .ended, .cancelled:
let upInteraction = UIInteraction(id: incrementingId,
let upInteraction = TouchInteraction(id: incrementingId,
kind: .touchUp(touchSample.location),
timestamp: touchSample.timestamp + uptimeDifference,
target: touchSample.target)
Expand All @@ -80,7 +80,7 @@ final class TouchIntepreter {
func flushMovements(touchSample: TouchSample, uptimeDifference: TimeInterval, yield: UIInteractionYield) {
guard var track = tracks[touchSample.id], track.points.isNotEmpty else { return }

let moveInteraction = UIInteraction(id: incrementingId,
let moveInteraction = TouchInteraction(id: incrementingId,
kind: .touchPath(points: track.points),
timestamp: touchSample.timestamp + uptimeDifference,
target: touchSample.target)
Expand All @@ -92,7 +92,7 @@ final class TouchIntepreter {
func flushTrack(touchSample: TouchSample, uptimeDifference: TimeInterval, yield: UIInteractionYield) {
guard let track = tracks.removeValue(forKey: touchSample.id), track.points.isNotEmpty else { return }

let moveInteraction = UIInteraction(id: incrementingId,
let moveInteraction = TouchInteraction(id: incrementingId,
kind: .touchPath(points: track.points),
timestamp: touchSample.timestamp + uptimeDifference,
target: touchSample.target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public struct TouchPoint: Sendable {
public let timestamp: TimeInterval
}

public enum UIInteractionKind: Sendable {
public enum TouchKind: Sendable {
case touchDown(CGPoint)
case touchUp(CGPoint)
case swipe(from: CGPoint, to: CGPoint, swipeDirection: SwipeDirection)
Expand All @@ -20,9 +20,9 @@ public enum UIInteractionKind: Sendable {
}
}

public struct UIInteraction: Sendable {
public struct TouchInteraction: Sendable {
public let id: Int
public let kind: UIInteractionKind
public let kind: TouchKind
public let timestamp: TimeInterval
public let target: TouchTarget?
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Observability/UIInteractions/UIEventSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public protocol UIEventSource: AnyObject {
}

public protocol UIEventBus: Sendable {
func publish(_ event: UIInteraction)
func publish(_ event: TouchInteraction)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct UIInteractionSpan {
let name: String
}

extension UIInteraction {
extension TouchInteraction {
func span() -> UIInteractionSpan? {
guard kind.isTapLike else { return nil }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Foundation
#if canImport(UIKit)
import UIKit
#endif
import Common
import Observability

Expand Down Expand Up @@ -62,14 +65,14 @@ actor SessionReplayEventGenerator {
appendFullSnapshotEvents(exportImage, timestamp, &events)
}

case let interaction as UIInteraction:
case let interaction as TouchInteraction:
appendTouchInteraction(interaction: interaction, events: &events)
default:
() //
}
}

fileprivate func appendTouchInteraction(interaction: UIInteraction, events: inout [Event]) {
fileprivate func appendTouchInteraction(interaction: TouchInteraction, events: inout [Event]) {
if let touchEventData: EventDataProtocol = switch interaction.kind {
case .touchDown(let point):
EventData(source: .mouseInteraction,
Expand Down Expand Up @@ -109,7 +112,7 @@ actor SessionReplayEventGenerator {
}
}

func clickEvent(interaction: UIInteraction) -> Event? {
func clickEvent(interaction: TouchInteraction) -> Event? {
guard case .touchDown = interaction.kind else { return nil }

let viewName = interaction.target?.className
Expand Down Expand Up @@ -145,13 +148,18 @@ actor SessionReplayEventGenerator {
}

func viewPortEvent(exportImage: ExportImage, timestamp: TimeInterval) -> Event {
#if os(iOS)
let currentOrientation = UIDevice.current.orientation.isLandscape ? 1 : 0
#else
let currentOrientation = 0
#endif
let payload = ViewportPayload(width: exportImage.originalWidth,
height: exportImage.originalHeight,
availWidth: exportImage.originalWidth,
availHeight: exportImage.originalHeight,
colorDepth: 30,
pixelDepth: 30,
orientation: Int.random(in: 0...1))
orientation: currentOrientation)
let eventData = CustomEventData(tag: .viewport, payload: payload)
let event = Event(type: .Custom,
data: AnyEventData(eventData),
Expand Down