Skip to content

[Paywalls v2] Adds a default case to most enums and sealed types#2346

Merged
JayShortway merged 6 commits into
mainfrom
pw2-default-sealed-enum-cases-2
Apr 10, 2025
Merged

[Paywalls v2] Adds a default case to most enums and sealed types#2346
JayShortway merged 6 commits into
mainfrom
pw2-default-sealed-enum-cases-2

Conversation

@JayShortway

@JayShortway JayShortway commented Apr 9, 2025

Copy link
Copy Markdown
Member

This is part 2/3:

  1. Adds EnumDeserializerWithDefault and SealedDeserializerWithDefault #2345
  2. 👉 [Paywalls v2] Adds a default case to most enums and sealed types #2346
  3. [Paywalls v2] Adds a default case to Background and ButtonComponent #2347

Description

This uses the EnumDeserializerWithDefault and SealedDeserializerWithDefault to add default cases to all enums and sealed types, except Background and ButtonComponent. Those 2 will be done in the next PR, as they have some cascading effects.

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just some questions, but looks great!!

}

@OptIn(InternalRevenueCatAPI::class)
internal object HorizontalAlignmentDeserializer : EnumDeserializerWithDefault<HorizontalAlignment>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm do we need to make all these @JvmSynthetic?

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.

@JvmSynthetic is not applicable to classes unfortunately.

"rectangle" to { MaskShape.Rectangle.serializer() },
"concave" to { MaskShape.Concave.serializer() },
"convex" to { MaskShape.Convex.serializer() },
"circle" to { MaskShape.Circle.serializer() },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering if there is a way for us to not forget to add a new value here 🤔. I guess the tests you added would catch these, so it's probably ok 👍

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.

Yea agreed. So far I don't think there's any other option other than tests, because sealed types don't have a values() function or entries property to list all cases. So it's impossible (?) to build a mapping with an exhaustive when.

) : PartialComponent

@OptIn(InternalRevenueCatAPI::class)
internal object CarouselPageControlPositionDeserializer : EnumDeserializerWithDefault<PageControl.Position>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i'm wondering, can these serializers be private?

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.

Unfortunately not. I tried that first, but then objects containing these objects cannot be deserialized. For example, if BackgroundDeserializer is private, PaywallComponentsConfig cannot be deserialized because its auto-generated serializer cannot instantiate BackgroundDeserializer.

@skydoves skydoves 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.

Overall looks good to me! 👍

@emerge-tools

emerge-tools Bot commented Apr 10, 2025

Copy link
Copy Markdown

📸 Snapshot Test

416 unchanged

Name Added Removed Modified Renamed Unchanged Errored Approval
TestPurchasesUIAndroidCompatibility Paparazzi
com.revenuecat.testpurchasesuiandroidcompatibility.paparazzi
0 0 0 0 149 0 N/A
TestPurchasesUIAndroidCompatibility
com.revenuecat.testpurchasesuiandroidcompatibility
0 0 0 0 267 0 N/A

🛸 Powered by Emerge Tools

github-merge-queue Bot pushed a commit that referenced this pull request Apr 10, 2025
#2345)

This is part 1/3:
1. 👉  #2345 
2. #2346 
3. #2347
---------------
## Description
Adds 2 abstract serializers that will be used in the follow-up PRs to
deserialize enums and sealed types with a default case.
Base automatically changed from pw2-default-sealed-enum-cases-1 to main April 10, 2025 11:03
@JayShortway JayShortway enabled auto-merge April 10, 2025 11:24
@JayShortway JayShortway disabled auto-merge April 10, 2025 11:31
@JayShortway JayShortway enabled auto-merge April 10, 2025 11:31
@JayShortway JayShortway added this pull request to the merge queue Apr 10, 2025
@codecov

codecov Bot commented Apr 10, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.27%. Comparing base (e1daf5c) to head (71e8cb9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2346      +/-   ##
==========================================
+ Coverage   79.93%   80.27%   +0.34%     
==========================================
  Files         284      284              
  Lines       10051    10104      +53     
  Branches     1422     1423       +1     
==========================================
+ Hits         8034     8111      +77     
+ Misses       1405     1378      -27     
- Partials      612      615       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Merged via the queue into main with commit fb04e0c Apr 10, 2025
@JayShortway JayShortway deleted the pw2-default-sealed-enum-cases-2 branch April 10, 2025 13:34
github-merge-queue Bot pushed a commit that referenced this pull request Apr 11, 2025
…t` (#2347)

This is part 3/3:
1. #2345 
2. #2346 
3. 👉  #2347
---------------
## Description
Adds a new `Unknown` default case to: 
- `Background`
- `ButtonComponent.Action`
- `ButtonComponent.Destination`
- `ButtonComponent.UrlMethod`

And handles this new case in code:
- An unknown background type will cause the paywall to fail to render,
as we can't infer colors and content colors in this case.
- Any unknown button action/destination/method type will cause the
button to be hidden.
github-merge-queue Bot pushed a commit that referenced this pull request Apr 15, 2025
**This is an automatic release.**

## RevenueCat SDK
### 🐞 Bugfixes
* Add missing response fields to `CustomerInfo`. Including transaction
Prices (#2128) via Cesar de la Vega (@vegaro)

## RevenueCatUI SDK
### Paywallv2
#### 🐞 Bugfixes
* [Paywalls v2] Fixes timeline layout when width is Fit (#2354) via
JayShortway (@JayShortway)
* [Paywalls V2] Improves fuzzy matching locale when the region doesn't
match (#2355) via JayShortway (@JayShortway)
* [Paywalls V2] Norwegian Bokmål and Norwegian Nynorsk fall back to
Norwegian. (#2329) via JayShortway (@JayShortway)
### Customer Center
#### 🐞 Bugfixes
* Clean up on restoring functionality in customer center (#2316) via
Cesar de la Vega (@vegaro)

### 🔄 Other Changes
* [Paywalls v2] Adds the unsupported Background type to the error
message (#2350) via JayShortway (@JayShortway)
* [Paywalls v2] Uses a fixed date for template previews to avoid daily
changes. (#2351) via JayShortway (@JayShortway)
* [Paywalls v2] Adds a default case to `Background` and
`ButtonComponent` (#2347) via JayShortway (@JayShortway)
* [Paywalls v2] Improves `PaywallComponentsTemplatePreviewRecorder`
stability (#2352) via JayShortway (@JayShortway)
* [Paywalls v2] Adds a default case to most enums and sealed types
(#2346) via JayShortway (@JayShortway)
* Adds `EnumDeserializerWithDefault` and `SealedDeserializerWithDefault`
(#2345) via JayShortway (@JayShortway)
* [Paywalls V2] Renders template previews in a fixed resolution using
Paparazzi (#2214) via JayShortway (@JayShortway)
* Bump fastlane from 2.227.0 to 2.227.1 (#2344) via dependabot[bot]
(@dependabot[bot])
* Migrate root gradle file to KTS (#2343) via Jaewoong Eum (@skydoves)
* Migrate tester modules to KTS format (#2340) via Jaewoong Eum
(@skydoves)
* Introduce purchases-bom package (#2339) via Jaewoong Eum (@skydoves)
* [AUTOMATIC][Paywalls V2] Updates paywall-preview-resources submodule
(#2338) via RevenueCat Git Bot (@RCGitBot)
* [Diagnostics] Removes Android 7 requirement (#2335) via JayShortway
(@JayShortway)
* [Paywalls v2] Fixes `update-paywall-preview-resources-submodule` CI
job (#2337) via JayShortway (@JayShortway)
* Make purchases module to transitive dependency for the ui module
(#2334) via Jaewoong Eum (@skydoves)
* Migrate settings.gradle to KTS and add the dependency resolutions
(#2328) via Jaewoong Eum (@skydoves)

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.

3 participants