Skip to content

Conversation

joshdholtz
Copy link
Member

@joshdholtz joshdholtz commented Jun 2, 2025

⚠️ I did not run this yet...

Motivation

Use new paywall resources format to have multiple sets of paywalls to screenshot

Description

Looking more dynamically for screenshots

@joshdholtz joshdholtz requested review from JayShortway, a team and Copilot June 2, 2025 21:13
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the paywall screenshot resource handling to support a new resource format and addresses lint issues.

  • Replace static resource path with a dynamic directory search for paywall assets.
  • Refactor JSON parsing to process multiple offerings from individual directories.
Comments suppressed due to low confidence (1)

ui/revenuecatui/src/debug/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/TemplatePreviews.kt:183

  • [nitpick] Matching the image file solely by its name might lead to ambiguities if duplicate names exist in different subdirectories. Consider incorporating additional path context to uniquely identify the file.
val matchingFile = getResourcesBaseDir().walkTopDown().firstOrNull { it.isFile && it.name == relativePath.substringAfterLast("/") }

Copy link

emerge-tools bot commented Jun 2, 2025

📸 Snapshot Test

186 added, 29 renamed, 418 unchanged

Name Added Removed Modified Renamed Unchanged Errored Approval
TestPurchasesUIAndroidCompatibility
com.revenuecat.testpurchasesuiandroidcompatibility
93 0 0 29 261 0 ✅ Approved
TestPurchasesUIAndroidCompatibility Paparazzi
com.revenuecat.testpurchasesuiandroidcompatibility.paparazzi
93 0 0 0 157 0 ✅ Approved

🛸 Powered by Emerge Tools

Copy link
Member

@JayShortway JayShortway left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Just some perf issues that we should optimize.

Comment on lines 182 to 184
// Look for a matching file in all subdirectories
val matchingFile = getResourcesBaseDir().walkTopDown()
.firstOrNull { it.isFile && it.name == relativePath.substringAfterLast("/") }
Copy link
Member

Choose a reason for hiding this comment

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

This seems very unoptimized. The previous approach was based on the fact that we could be certain of a file's location given its URL. Just walking the file tree every time is a bit wasteful. The Emerge Snapshots environment is also very sensitive to performance problems, so that's why it caught my eye.

Copy link
Member

Choose a reason for hiding this comment

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

Actually it seems that Emerge does trip over the changes in this PR. It only registers removed screenshots, but that is unexpected. There are also some errors. My hunch is that we need to optimize for memory, as I had to do in the previous iteration of this.

Comment on lines 200 to 203
private fun getResourcesBaseDir(): File {
return File(BuildConfig.PROJECT_DIR)
.resolve("../../upstream/paywall-preview-resources/resources")
}
Copy link
Member

Choose a reason for hiding this comment

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

This only works in Android Studio. When the screenshot is rendered on the actual Android OS (device or emulator, as Emerge does), it won't be able to find the resources. We need to check the class loader instead. Check the implementation of getResourceStream() for an example.

@JayShortway
Copy link
Member

JayShortway commented Jun 4, 2025

TODO:

Copy link

emerge-tools bot commented Jun 4, 2025

1 build increased size

Name Version Download Change Install Change Approval
⚠️ TestPurchasesUIAndroidCompatibility
com.revenuecat.testpurchasesuiandroidcompatibility
1.0 (1) 52.4 MB ⬆️ 34.5 MB (192.84%) 92.2 MB ⬆️ 47.8 MB (107.65%) N/A

TestPurchasesUIAndroidCompatibility 1.0 (1)
com.revenuecat.testpurchasesuiandroidcompatibility

⚖️ Compare build
⏱️ Analyze build performance

Total install size change: ⬆️ 47.8 MB (107.65%)
Total download size change: ⬆️ 34.5 MB (192.84%)

Largest size changes

Item Install Size Change Download Size Change
📝 957060_1741639342.heic ⬆️ 1.2 MB ⬆️ 1.2 MB
📝 387178_1739250499.heic ⬆️ 1.2 MB ⬆️ 1.2 MB
📝 453869_1740097911.heic ⬆️ 930.3 kB ⬆️ 930.6 kB
📝 1201192_1741375926.heic ⬆️ 818.8 kB ⬆️ 819.0 kB
📝 1188871_1745890350.heic ⬆️ 708.4 kB ⬆️ 708.4 kB
View Treemap

Image of diff


🛸 Powered by Emerge Tools

Comment trigger: Size diff threshold of 100.00kB exceeded

Comment on lines +90 to 99
internal fun Result<FontSpec, PaywallValidationError>.recoverFromFontAliasError(): Result<FontSpec?, PaywallValidationError> =
flatMapError { error ->
if (error is PaywallValidationError.MissingFontAlias && error.alias.value.isBlank()) {
// Treating this as a dashboard error and just ignoring it. No need to log.
Result.Success(null)
} else if (error is PaywallValidationError.MissingFontAlias) {
Logger.e(
"Font named '${error.alias}' was not found in the font config. Try re-adding it in the Paywall editor.",
)
Result.Success(null)
Copy link
Member

Choose a reason for hiding this comment

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

@tonidero FYI, I don't think this should conflict with your stuff right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh it's a different part of the code so I don't think so either. Thanks for checking!

Copy link
Member Author

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

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

I can't review my own PR even though this was all @JayShortway but... looks good to me! :shipit:

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.

This looks great!!

val offering = paywall.offering
val parentFolder = paywall.parentFolder
// validatePaywallComponentsDataOrNullForPreviews should only return null if the Offering has no paywallComponents,
// but we filter those out in the PaywallResourcesProvider.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine for previews 👍

@JayShortway JayShortway enabled auto-merge June 5, 2025 12:28
@JayShortway JayShortway added this pull request to the merge queue Jun 5, 2025
Copy link

codecov bot commented Jun 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.66%. Comparing base (953f553) to head (0184489).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2413   +/-   ##
=======================================
  Coverage   79.66%   79.66%           
=======================================
  Files         284      284           
  Lines       10263    10263           
  Branches     1457     1457           
=======================================
  Hits         8176     8176           
  Misses       1460     1460           
  Partials      627      627           

☔ 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 700b7cc Jun 5, 2025
14 checks passed
@JayShortway JayShortway deleted the use-new-resource-format-cross-validation branch June 5, 2025 13:07
tonidero added a commit that referenced this pull request Jun 6, 2025
**This is an automatic release.**

## RevenueCatUI SDK
### Paywallv2
#### 🐞 Bugfixes
* [Paywalls] Fix Bold text in Markdown on higher Weights Text
composables (#2421) via Toni Rico (@tonidero)

### 🔄 Other Changes
* Add coroutines dependency to core SDK (#2423) via Toni Rico
(@tonidero)
* [Paywalls] Add `font_weight_int` to `TextComponent` (#2419) via Toni
Rico (@tonidero)
* [Paywalls V2] Downloadable fonts (#2414) via Toni Rico (@tonidero)
* [AUTOMATIC][Paywalls V2] Updates paywall-preview-resources submodule
(#2412) via RevenueCat Git Bot (@RCGitBot)
* Use new resource format for cross validation screenshots and fix lint
(#2413) via Josh Holtz (@joshdholtz)

---------

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

Successfully merging this pull request may close these issues.

3 participants