Skip to content

RUMM-2779 Resolve view snapshot background from theme color#1230

Merged
mariusc83 merged 1 commit into
feature/sdkv2from
mconstantin/rumm-2779/resolve-theme-background-in-wireframes
Jan 13, 2023
Merged

RUMM-2779 Resolve view snapshot background from theme color#1230
mariusc83 merged 1 commit into
feature/sdkv2from
mconstantin/rumm-2779/resolve-theme-background-in-wireframes

Conversation

@mariusc83

@mariusc83 mariusc83 commented Jan 12, 2023

Copy link
Copy Markdown
Member

Resolve view snapshot background from theme color

What does this PR do?

In this PR we are making sure that whenever a screen snapshot is performed for SR records, if the root wireframe does not have a ShapeStyle (meaning that we could not resolve the background from a potential drawable attached to the View) we will resolve the ShapeStyle from the Theme#windowBackground. This way we will make sure that we will not have transparent backgrounds in our snapshots and we simulate the system behaviour.

Motivation

What inspired you to submit this pull request?

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)

@mariusc83 mariusc83 self-assigned this Jan 12, 2023
@mariusc83
mariusc83 force-pushed the mconstantin/rumm-2779/resolve-theme-background-in-wireframes branch 2 times, most recently from 11b7319 to 1f53698 Compare January 12, 2023 10:12
@mariusc83
mariusc83 marked this pull request as ready for review January 12, 2023 10:27
@mariusc83
mariusc83 requested a review from a team as a code owner January 12, 2023 10:27

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice! I've added few comments/questions

fun resolveThemeColor(theme: Theme): Int? {
val a = TypedValue()
theme.resolveAttribute(android.R.attr.windowBackground, a, true)
return if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

probably here it should be && instead of ||, because we want to check that value is in the range TypedValue.TYPE_FIRST_COLOR_INT..TypedValue.TYPE_LAST_COLOR_INT. With || I believe this condition always evaluates to true.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, of course 🤦

// region hasNonTranslucentColor

@Test
fun `M return true W hasNonTranslucentColor { backgroundColor no translucent }`(forge: Forge) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
fun `M return true W hasNonTranslucentColor { backgroundColor no translucent }`(forge: Forge) {
fun `M return true W hasNonTranslucentColor { backgroundColor not translucent }`(forge: Forge) {

}

// Then
assertThat(ThemeUtils.resolveThemeColor(mockTheme)).isEqualTo(fakeColor)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

probably it should be isNull here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes and that's the reason I could not discover the bug in the code because this test was passing :)

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #1230 (1f53698) into feature/sdkv2 (8747487) will increase coverage by 0.00%.
The diff coverage is 93.88%.

@@              Coverage Diff               @@
##           feature/sdkv2    #1230   +/-   ##
==============================================
  Coverage          82.79%   82.79%           
==============================================
  Files                354      358    +4     
  Lines              12590    12616   +26     
  Branches            2088     2095    +7     
==============================================
+ Hits               10423    10445   +22     
- Misses              1526     1527    +1     
- Partials             641      644    +3     
Impacted Files Coverage Δ
...nreplay/recorder/listener/WindowsOnDrawListener.kt 93.94% <0.00%> (ø)
.../datadog/android/sessionreplay/utils/ThemeUtils.kt 66.67% <66.67%> (ø)
.../android/sessionreplay/processor/WireframeUtils.kt 100.00% <100.00%> (ø)
...android/sessionreplay/recorder/SnapshotProducer.kt 88.89% <100.00%> (+6.28%) ⬆️
...ssionreplay/recorder/mapper/BaseWireframeMapper.kt 100.00% <100.00%> (ø)
...ssionreplay/recorder/mapper/TextWireframeMapper.kt 90.16% <100.00%> (ø)
...ssionreplay/recorder/mapper/ViewWireframeMapper.kt 88.46% <100.00%> (ø)
...tadog/android/sessionreplay/utils/ShapeStyleExt.kt 100.00% <100.00%> (ø)
...datadog/android/sessionreplay/utils/StringUtils.kt 100.00% <100.00%> (ø)
...atadog/android/sessionreplay/utils/WireframeExt.kt 100.00% <100.00%> (ø)
... and 12 more

@mariusc83
mariusc83 force-pushed the mconstantin/rumm-2779/resolve-theme-background-in-wireframes branch from 1f53698 to 8f1f52f Compare January 12, 2023 14:50
@mariusc83
mariusc83 merged commit 7b37814 into feature/sdkv2 Jan 13, 2023
@mariusc83
mariusc83 deleted the mconstantin/rumm-2779/resolve-theme-background-in-wireframes branch January 13, 2023 08:38
@xgouchet xgouchet added this to the 1.17.0 milestone Dec 13, 2023
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.

4 participants