From 5369f9b193e357c681334e14fbe40f1f9240fee4 Mon Sep 17 00:00:00 2001 From: Maciej Burda Date: Tue, 7 Mar 2023 11:12:09 +0000 Subject: [PATCH] REPLAY-1448 Add custom UIStepper wireframes --- .../NodeRecorders/UIStepperRecorder.swift | 61 ++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/DatadogSessionReplay/Sources/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/UIStepperRecorder.swift b/DatadogSessionReplay/Sources/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/UIStepperRecorder.swift index d49c7d7012..3e3652bf00 100644 --- a/DatadogSessionReplay/Sources/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/UIStepperRecorder.swift +++ b/DatadogSessionReplay/Sources/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/UIStepperRecorder.swift @@ -8,14 +8,22 @@ import UIKit internal struct UIStepperRecorder: NodeRecorder { func semantics(of view: UIView, with attributes: ViewAttributes, in context: ViewTreeRecordingContext) -> NodeSemantics? { - guard let slider = view as? UISlider else { + guard let stepper = view as? UIStepper else { return nil } guard attributes.isVisible else { return InvisibleElement.constant } - let builder = UIStepperWireframesBuilder(wireframeRect: slider.frame) + + let stepperFrame = CGRect(origin: attributes.frame.origin, size: stepper.intrinsicContentSize) + let ids = context.ids.nodeIDs(4, for: stepper) + + let builder = UIStepperWireframesBuilder( + wireframeRect: stepperFrame, + cornerRadius: stepper.subviews.first?.layer.cornerRadius ?? 0, + ids: ids + ) let node = Node(viewAttributes: attributes, wireframesBuilder: builder) return SpecificElement(subtreeStrategy: .ignore, nodes: [node]) } @@ -23,8 +31,55 @@ internal struct UIStepperRecorder: NodeRecorder { internal struct UIStepperWireframesBuilder: NodeWireframesBuilder { var wireframeRect: CGRect + var cornerRadius: CGFloat + var ids: [Int64] func buildWireframes(with builder: WireframesBuilder) -> [SRWireframe] { - return [] + let background = builder.createShapeWireframe( + id: ids[0], + frame: wireframeRect, + borderColor: nil, + borderWidth: nil, + backgroundColor: SystemColors.tertiarySystemBackground, + cornerRadius: cornerRadius + ) + let divider = builder.createShapeWireframe( + id: ids[1], + frame: CGRect( + origin: CGPoint(x: wireframeRect.origin.x + 46.5, y: wireframeRect.origin.y + 6), + size: CGSize(width: 1, height: 20) + ), + backgroundColor: SystemColors.placeholderText + ) + let stepButtonFontSize = CGFloat(30) + let stepButtonSize = CGSize(width: stepButtonFontSize, height: stepButtonFontSize) + let stepButtonLeftOffset = wireframeRect.width / 2 - stepButtonSize.width / 2 + let minus = builder.createTextWireframe( + id: ids[2], + frame: CGRect( + origin: CGPoint( + x: wireframeRect.origin.x + stepButtonLeftOffset, + y: wireframeRect.origin.y + ), + size: stepButtonSize + ), + text: "-", + textColor: SystemColors.label, + font: .systemFont(ofSize: stepButtonFontSize) + ) + let plus = builder.createTextWireframe( + id: ids[3], + frame: CGRect( + origin: CGPoint( + x: wireframeRect.origin.x + wireframeRect.width / 2 + stepButtonLeftOffset, + y: wireframeRect.origin.y + ), + size: stepButtonSize + ), + text: "+", + textColor: SystemColors.label, + font: .systemFont(ofSize: stepButtonFontSize) + ) + return [background, divider, minus, plus] } }