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

[Paywalls V2] TextComponentView updates when the theme changes #1966

Merged
merged 37 commits into from
Dec 10, 2024

Conversation

JayShortway
Copy link
Member

Description

The individual components should be able to update themselves if the "environment", such as the theme, changes. If they aren't, the entire tree of ComponentStyles needs to be rebuilt for every change, which is far from optimal.

This PR starts by making sure TextComponentView can react to theme changes. We'll need to repeat this exercise for the other components and for other environment changes (e.g. screen orientation).

Changes

  • Adds TextComponentViewTests, which tests that the background color and test color update when the theme changes.
  • Modifies TextComponentStyle and TextComponentView to make the above tests pass.
  • Adds utilities to be able to write the above tests:
    • themeChangingTest, to easily test behavior across theme changes.
    • assertTextColorEquals
    • assertPixelColorEquals
    • captureToImageJvm(), which is a Robolectric compatible way of taking a screenshot of a Composable, taken from here. Used to check pixel color values.

Comment on lines +47 to +64
/**
* Robolectric-compatible way of capturing a [SemanticsNodeInteraction] to an [ImageBitmap]. It's a copy from
* Google's version, minus a forced redraw which doesn't work on Robolectric.
*
* Make sure your test class or function has the following annotations. `sdk` has to be >= 26.
*
* ```kotlin
* @GraphicsMode(GraphicsMode.Mode.NATIVE)
* @Config(shadows = [ShadowPixelCopy::class], sdk = [26])
* ```
*
* See [this issue](https://github.com/robolectric/robolectric/issues/8071) for more info.
*
* [Source](https://github.com/robolectric/robolectric/issues/8071#issuecomment-1774365222)
*/
@OptIn(ExperimentalTestApi::class)
@SdkSuppress(minSdkVersion = 26)
private fun SemanticsNodeInteraction.captureToImageJvm(): ImageBitmap {
Copy link
Member Author

Choose a reason for hiding this comment

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

Everything below is copied from robolectric/robolectric#8071 (comment).

Base automatically changed from pw2-stylefactory to main December 10, 2024 13:03
# Conflicts:
#	ui/revenuecatui/src/test/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/style/StyleFactoryTests.kt
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.87%. Comparing base (43cbbf1) to head (729e23c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1966   +/-   ##
=======================================
  Coverage   81.87%   81.87%           
=======================================
  Files         260      260           
  Lines        8493     8493           
  Branches     1226     1226           
=======================================
  Hits         6954     6954           
  Misses       1041     1041           
  Partials      498      498           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

LGTM!

@JayShortway JayShortway merged commit eda371a into main Dec 10, 2024
12 checks passed
@JayShortway JayShortway deleted the pw2-text-theme-tests branch December 10, 2024 17:14
tonidero pushed a commit that referenced this pull request Dec 12, 2024
**This is an automatic release.**

## RevenueCatUI SDK
### 🐞 Bugfixes
* Fix multi-tier template to allow optional header image (#1971) via
Josh Holtz (@joshdholtz)

### 🔄 Other Changes
* [Paywalls V2] Adds first version of `LoadedPaywallComponents` (#1970)
via JayShortway (@JayShortway)
* [Paywalls V2] Add `ButtonComponentView` (#1963) via Toni Rico
(@tonidero)
* [Paywalls V2] Adds `PaywallState.Loaded.Components` (#1969) via
JayShortway (@JayShortway)
* [Paywalls V2] Adds image background tests (#1967) via JayShortway
(@JayShortway)
* [Paywalls V2] `TextComponentView` updates when the theme changes
(#1966) via JayShortway (@JayShortway)
* [Paywalls V2] Adds a `StyleFactory` (#1965) via JayShortway
(@JayShortway)
* [EXTERNAL] fix: update polish translations (#1919) via @radko93
(#1964) via JayShortway (@JayShortway)
* [Paywalls V2] Adds `ImageComponentView` (#1959) via Toni Rico
(@tonidero)
* WebPurchaseRedemption: Rename `AlreadyRedeemed` result to
`PurchaseBelongsToOtherUser` (#1962) via Toni Rico (@tonidero)
* [Paywalls V2] Extends support for blurred shadows to all Android
versions (#1957) via JayShortway (@JayShortway)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants