Skip to content

Commit 1242694

Browse files
committed
pass orientation flag
1 parent 5f22984 commit 1242694

File tree

7 files changed

+23
-15
lines changed

7 files changed

+23
-15
lines changed

Sources/Observability/UIInteractions/ObservabilityEvents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import Common
33

4-
extension UIInteraction: EventQueueItemPayload {
4+
extension TouchInteraction: EventQueueItemPayload {
55
public func cost() -> Int {
66
300
77
}

Sources/Observability/UIInteractions/TouchCaptureCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct TouchSample: Sendable {
3131
}
3232
}
3333

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

3636
final class TouchCaptureCoordinator {
3737
private let source: UIEventSource

Sources/Observability/UIInteractions/TouchIntepreter.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class TouchIntepreter {
3535
target: touchSample.target)
3636
tracks[touchSample.id] = track
3737

38-
let downInteraction = UIInteraction(id: incrementingId,
38+
let downInteraction = TouchInteraction(id: incrementingId,
3939
kind: .touchDown(touchSample.location),
4040
timestamp: touchSample.timestamp + uptimeDifference,
4141
target: touchSample.target)
@@ -67,7 +67,7 @@ final class TouchIntepreter {
6767
}
6868

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

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

95-
let moveInteraction = UIInteraction(id: incrementingId,
95+
let moveInteraction = TouchInteraction(id: incrementingId,
9696
kind: .touchPath(points: track.points),
9797
timestamp: touchSample.timestamp + uptimeDifference,
9898
target: touchSample.target)

Sources/Observability/UIInteractions/UIInteraction.swift renamed to Sources/Observability/UIInteractions/TouchInteraction.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public struct TouchPoint: Sendable {
66
public let timestamp: TimeInterval
77
}
88

9-
public enum UIInteractionKind: Sendable {
9+
public enum TouchKind: Sendable {
1010
case touchDown(CGPoint)
1111
case touchUp(CGPoint)
1212
case swipe(from: CGPoint, to: CGPoint, swipeDirection: SwipeDirection)
@@ -20,9 +20,9 @@ public enum UIInteractionKind: Sendable {
2020
}
2121
}
2222

23-
public struct UIInteraction: Sendable {
23+
public struct TouchInteraction: Sendable {
2424
public let id: Int
25-
public let kind: UIInteractionKind
25+
public let kind: TouchKind
2626
public let timestamp: TimeInterval
2727
public let target: TouchTarget?
2828
}

Sources/Observability/UIInteractions/UIEventSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ public protocol UIEventSource: AnyObject {
66
}
77

88
public protocol UIEventBus: Sendable {
9-
func publish(_ event: UIInteraction)
9+
func publish(_ event: TouchInteraction)
1010
}

Sources/Observability/UIInteractions/UInteraction+Span.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct UIInteractionSpan {
55
let name: String
66
}
77

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

Sources/SessionReplay/Exporter/SessionReplayEventGenerator.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import Foundation
2+
#if canImport(UIKit)
3+
import UIKit
4+
#endif
25
import Common
36
import Observability
47

@@ -62,14 +65,14 @@ actor SessionReplayEventGenerator {
6265
appendFullSnapshotEvents(exportImage, timestamp, &events)
6366
}
6467

65-
case let interaction as UIInteraction:
68+
case let interaction as TouchInteraction:
6669
appendTouchInteraction(interaction: interaction, events: &events)
6770
default:
6871
() //
6972
}
7073
}
7174

72-
fileprivate func appendTouchInteraction(interaction: UIInteraction, events: inout [Event]) {
75+
fileprivate func appendTouchInteraction(interaction: TouchInteraction, events: inout [Event]) {
7376
if let touchEventData: EventDataProtocol = switch interaction.kind {
7477
case .touchDown(let point):
7578
EventData(source: .mouseInteraction,
@@ -109,7 +112,7 @@ actor SessionReplayEventGenerator {
109112
}
110113
}
111114

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

115118
let viewName = interaction.target?.className
@@ -145,13 +148,18 @@ actor SessionReplayEventGenerator {
145148
}
146149

147150
func viewPortEvent(exportImage: ExportImage, timestamp: TimeInterval) -> Event {
151+
#if os(iOS)
152+
let currentOrientation = UIDevice.current.orientation.isLandscape ? 1 : 0
153+
#else
154+
let currentOrientation = 0
155+
#endif
148156
let payload = ViewportPayload(width: exportImage.originalWidth,
149157
height: exportImage.originalHeight,
150158
availWidth: exportImage.originalWidth,
151159
availHeight: exportImage.originalHeight,
152160
colorDepth: 30,
153161
pixelDepth: 30,
154-
orientation: Int.random(in: 0...1))
162+
orientation: currentOrientation)
155163
let eventData = CustomEventData(tag: .viewport, payload: payload)
156164
let event = Event(type: .Custom,
157165
data: AnyEventData(eventData),

0 commit comments

Comments
 (0)