Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUM-6195: Add support for Compose Checkbox #2414

Merged
merged 5 commits into from
Dec 18, 2024

Conversation

jonathanmos
Copy link
Member

@jonathanmos jonathanmos commented Nov 25, 2024

What does this PR do?

Adds support for the Checkbox Semantics role. Resolves the path of the checkbox to a bitmap and sends as an imageWireframe, but if unsuccessful will create a ShapeWireframe approximation. This pr includes:

• Creation of checked/unchecked state for the checkbox.
• Fallback to a manual shape wireframe if we couldn't resolve the checkmark path.
• Caching of the checkmark resourceId in the ResourcesLruCache.
• Generation of a cache key for the checkmark using PathMeasure on the path to fingerprint it by sampling at intervals. This is bounded by a configurable maximum number of samples.

Unchecked state:
Screenshot 2024-11-26 at 15 28 36

Checked state if succesful in resolving the path:
Screenshot 2024-11-26 at 14 40 11

Checked state fallback if path resolution is unsuccessful:
Screenshot 2024-11-25 at 17 08 58

Motivation

Part of the initiative to support Jetpack Compose.

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@jonathanmos jonathanmos force-pushed the jmoskovich/rum-6195/checkbox-semantics-mapper branch 2 times, most recently from 33e6311 to 66d7340 Compare November 26, 2024 09:40
@codecov-commenter
Copy link

codecov-commenter commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 77.25000% with 91 lines in your changes missing coverage. Please review.

Project coverage is 69.96%. Comparing base (4e7d937) to head (c1b4f66).
Report is 6 commits behind head on develop.

Files with missing lines Patch % Lines
...ay/internal/recorder/resources/ResourceResolver.kt 51.67% 28 Missing and 1 partial ⚠️
.../android/sessionreplay/internal/utils/PathUtils.kt 84.51% 7 Missing and 4 partials ⚠️
...y/compose/internal/reflection/ComposeReflection.kt 0.00% 9 Missing ⚠️
...sessionreplay/compose/internal/utils/ColorUtils.kt 18.18% 9 Missing ⚠️
.../sessionreplay/compose/internal/utils/PathUtils.kt 25.00% 9 Missing ⚠️
...onreplay/compose/internal/utils/ReflectionUtils.kt 0.00% 7 Missing ⚠️
...ionreplay/compose/internal/utils/SemanticsUtils.kt 76.67% 0 Missing and 7 partials ⚠️
...l/mappers/semantics/CheckboxSemanticsNodeMapper.kt 96.83% 1 Missing and 3 partials ⚠️
...d/sessionreplay/recorder/wrappers/BitmapWrapper.kt 40.00% 3 Missing ⚠️
...ndroid/sessionreplay/utils/ImageWireframeHelper.kt 33.33% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2414      +/-   ##
===========================================
+ Coverage    69.92%   69.96%   +0.04%     
===========================================
  Files          781      785       +4     
  Lines        28915    29278     +363     
  Branches      4835     4884      +49     
===========================================
+ Hits         20217    20483     +266     
- Misses        7358     7431      +73     
- Partials      1340     1364      +24     
Files with missing lines Coverage Δ
...ernal/mappers/semantics/RootSemanticsNodeMapper.kt 75.31% <100.00%> (+0.31%) ⬆️
...nreplay/internal/recorder/SessionReplayRecorder.kt 97.10% <100.00%> (+0.02%) ⬆️
...y/internal/recorder/resources/ImageTypeResolver.kt 100.00% <100.00%> (ø)
...roid/sessionreplay/internal/utils/DrawableUtils.kt 95.38% <100.00%> (+0.30%) ⬆️
...d/sessionreplay/recorder/wrappers/CanvasWrapper.kt 28.00% <100.00%> (ø)
.../recorder/resources/DefaultImageWireframeHelper.kt 98.33% <98.04%> (-0.09%) ⬇️
...ndroid/sessionreplay/utils/ImageWireframeHelper.kt 62.50% <33.33%> (ø)
...d/sessionreplay/recorder/wrappers/BitmapWrapper.kt 12.90% <40.00%> (ø)
...l/mappers/semantics/CheckboxSemanticsNodeMapper.kt 96.83% <96.83%> (ø)
...onreplay/compose/internal/utils/ReflectionUtils.kt 1.82% <0.00%> (-0.27%) ⬇️
... and 6 more

... and 35 files with indirect coverage changes

@jonathanmos jonathanmos force-pushed the jmoskovich/rum-6195/checkbox-semantics-mapper branch from 66d7340 to 9d12c72 Compare November 26, 2024 12:28
@jonathanmos jonathanmos marked this pull request as ready for review November 26, 2024 13:23
@jonathanmos jonathanmos requested review from a team as code owners November 26, 2024 13:23
Copy link
Member

@0xnm 0xnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly went through the production files, didn't cover tests

@@ -37,6 +37,16 @@ internal object ComposeReflection {
val ColorField = BackgroundElementClass?.getDeclaredFieldSafe("color")
val ShapeField = BackgroundElementClass?.getDeclaredFieldSafe("shape")

val CheckDrawingCacheClass = getClassSafe("androidx.compose.material.CheckDrawingCache")
val CheckboxKtClass = getClassSafe("androidx.compose.material.CheckboxKt\$CheckboxImpl\$1\$1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, updating proguard consumer rules is necessary

@jonathanmos jonathanmos force-pushed the jmoskovich/rum-6195/checkbox-semantics-mapper branch from 9d12c72 to f23bb5f Compare November 27, 2024 12:11
@jonathanmos jonathanmos force-pushed the jmoskovich/rum-6195/checkbox-semantics-mapper branch from f23bb5f to 8864b27 Compare December 9, 2024 08:41
@jonathanmos jonathanmos changed the base branch from develop to jmoskovich/rum-6195/caches-any-key December 9, 2024 08:41
@jonathanmos jonathanmos force-pushed the jmoskovich/rum-6195/checkbox-semantics-mapper branch 3 times, most recently from 4411582 to a02fc56 Compare December 11, 2024 13:36
@jonathanmos jonathanmos changed the base branch from jmoskovich/rum-6195/caches-any-key to marcosaia/RUM-7018/react-native-support December 11, 2024 13:37
@marco-saia-datadog marco-saia-datadog force-pushed the marcosaia/RUM-7018/react-native-support branch 4 times, most recently from 427dafe to 7a92c24 Compare December 12, 2024 14:28
@jonathanmos jonathanmos force-pushed the jmoskovich/rum-6195/checkbox-semantics-mapper branch from b35cace to 0da9659 Compare December 16, 2024 11:28
@marco-saia-datadog marco-saia-datadog force-pushed the marcosaia/RUM-7018/react-native-support branch 5 times, most recently from 7f56e9a to a12c7ad Compare December 17, 2024 08:46
Base automatically changed from marcosaia/RUM-7018/react-native-support to develop December 17, 2024 10:50
@jonathanmos jonathanmos force-pushed the jmoskovich/rum-6195/checkbox-semantics-mapper branch from 0da9659 to 2ef05ac Compare December 17, 2024 12:22
@jonathanmos jonathanmos force-pushed the jmoskovich/rum-6195/checkbox-semantics-mapper branch from 2ef05ac to 8b092b1 Compare December 17, 2024 12:26
Copy link
Member

@0xnm 0xnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! I left some comments/suggestions, but nothing major.

}
}

if (wireframes.isNotEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: you probably can just do return wireframes.ifEmpty { createManualCheckedWireframe }

@jonathanmos jonathanmos force-pushed the jmoskovich/rum-6195/checkbox-semantics-mapper branch 2 times, most recently from cd5a77c to 11155d6 Compare December 18, 2024 10:42
@jonathanmos jonathanmos requested a review from 0xnm December 18, 2024 11:27
.thenReturn(TextAndInputPrivacy.MASK_ALL_INPUTS)

// When
val wireframes = testedMapper.map(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since return type is SemanticsWireframe should this one be called wireframe? or checkboxWireframe.

Otherwise wireframes.wireframes below looks strange.

// Then
assertThat(wireframes.wireframes).hasSize(1)
val actualWireframe = wireframes.wireframes[0] as MobileSegment.Wireframe.ShapeWireframe
assertThat(actualWireframe).isNotNull
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to have null at all? the type here is MobileSegment.Wireframe.ShapeWireframe, not MobileSegment.Wireframe.ShapeWireframe?

Comment on lines 34 to 42
fun `M return input value W convertRgbaToArgb() { length is less than 8 }`(
forge: Forge
) {
// Given
val input = forge.anAsciiString(1)

// Then
assertThat(testedUtils.convertRgbaToArgb(input)).isEqualTo(input)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if we pass rgb string, the output will be wrong? Shouldn't we check in the convertRgbaToArgb method that input is exactly 8 characters (or 6 if we want to support rgb?

Otherwise we may have this function trying to compose something for the strings of format we don't expect.

@jonathanmos jonathanmos force-pushed the jmoskovich/rum-6195/checkbox-semantics-mapper branch from 11155d6 to c1b4f66 Compare December 18, 2024 13:50
@jonathanmos jonathanmos merged commit f9bc2b5 into develop Dec 18, 2024
24 checks passed
@jonathanmos jonathanmos deleted the jmoskovich/rum-6195/checkbox-semantics-mapper branch December 18, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants