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

Paywall views: Support updating options state after initial layout #1582

Merged
merged 4 commits into from
Jan 30, 2024

Conversation

tonidero
Copy link
Contributor

@tonidero tonidero commented Jan 29, 2024

Description

This will make it so calling the setOfferingId method after the initial layout updates the state causing a recomposition of the paywall.

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b245bbb) 83.73% compared to head (ed7db57) 83.73%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1582   +/-   ##
=======================================
  Coverage   83.73%   83.73%           
=======================================
  Files         218      218           
  Lines        7248     7248           
  Branches     1007     1007           
=======================================
  Hits         6069     6069           
  Misses        788      788           
  Partials      391      391           

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

offeringSelection = OfferingSelection.OfferingId(newOfferingId)
)
}
}
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 we need to do this not only for the offering id but also for the font provider and the dismiss button... can we do something similar with the whole state?

Copy link
Contributor

Choose a reason for hiding this comment

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

@vegaro
I think that'll help our team a lot since we won't have to fork off this repository for fontProvider changes :D

Copy link
Contributor

Choose a reason for hiding this comment

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

I took a stab at that in #1586 in case you're interested

Copy link
Contributor

@Jjastiny Jjastiny Jan 29, 2024

Choose a reason for hiding this comment

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

awesome
https://github.com/Jjastiny/purchases-android/pull/1/files
Just curious, any concerns or thoughts on using mutableStateOf outside of the composable function?

.setShouldDisplayDismissButton(shouldDisplayDismissButton ?: false)
.build())
}
updateOfferingId = {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Sorry to bother you guys again, but I highly recommend staying away from unstable lambdas, as it may cause unforeseen recompositions and performance hits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @Jjastiny, I believe in this case it should be fine since we are only storing a lambda to trigger the update from outside the compose context, but I agree it's probably not the cleanest approach. I just pushed another approach inspired by your approach that also seems to work fine. cc @vegaro

@vegaro
Copy link
Contributor

vegaro commented Jan 29, 2024

Took another approach in #1586

@tonidero tonidero changed the title Recreate compose view on setters that require it Support updating options state after initial layout Jan 30, 2024
@tonidero tonidero changed the title Support updating options state after initial layout Paywall views: Support updating options state after initial layout Jan 30, 2024
@tonidero tonidero marked this pull request as ready for review January 30, 2024 10:51
@tonidero tonidero requested a review from a team January 30, 2024 10:51
} else {
OfferingSelection.OfferingId(offeringId)
}
paywallOptionsState.value = paywallOptionsState.value.copy(offeringSelection = offeringSelection)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is quite a bit of repetition on these, we probably need to refactor these to avoid it.

Copy link
Contributor

@vegaro vegaro left a comment

Choose a reason for hiding this comment

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

Tested it in react native and it works perfectly

@tonidero tonidero merged commit 3fff2a8 into main Jan 30, 2024
9 checks passed
@tonidero tonidero deleted the recreate-compose-view-on-setters branch January 30, 2024 11:54
options = paywallOptions,
)
val paywallOptions by remember {
paywallOptionsState
Copy link
Contributor

Choose a reason for hiding this comment

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

@vegaro
Wouldn't this not update after OfferingSelection changes once? Not a big deal, but I think it may lead to future bugs 😭

Copy link
Contributor Author

@tonidero tonidero Jan 30, 2024

Choose a reason for hiding this comment

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

Hi @Jjastiny, I believe the changes in this PR would update the state every time the setOfferingId method is called, even if it's called multiple times. Can you explain why you think this would only work once?

Copy link
Contributor

Choose a reason for hiding this comment

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

@tonidero
hhm yeah, I stand corrected. It does look like it's recomposing for me. Sorry for the misunderstanding!

vegaro pushed a commit that referenced this pull request Feb 5, 2024
**This is an automatic release.**

### RevenueCatUI
* `Paywalls`: fix template 5 title alignment (#1585) via NachoSoto
(@NachoSoto)
* `Paywalls`: replace `TextAlign.Left` with `TextAlign.Start` to better
support RTL (#1584) via NachoSoto (@NachoSoto)
* Paywall views: Support updating options state after initial layout
(#1582) via Toni Rico (@tonidero)
* `Paywalls`: improve `PaywallData.configForLocale()` disambiguation
(#1579) via NachoSoto (@NachoSoto)
### Dependency Updates
* Bump fastlane-plugin-revenuecat_internal from `e6ba247` to `9c82c7a`
(#1583) via dependabot[bot] (@dependabot[bot])
### Other Changes
* `OfferingsFactory`: debug logs when creating `Offerings` (#1576) via
NachoSoto (@NachoSoto)
* `Paywalls`: log error when creating `PaywallState.Error` (#1574) via
NachoSoto (@NachoSoto)

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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants