Fix: erroneous initializations of the PurchaseHandler from a button#6827
Conversation
…omer center would get invoked.
1318ff7 to
d0d43b2
Compare
|
Nice catch! I think we introduced this when we added Paywall support for CustomerCenter. I suspect the root cause is that If the paywall path instead observed the existing handler rather than owning it, the binding alone would be enough. The A small paywall-internal modifier could do: private struct PaywallCustomerCenterSheetModifier: ViewModifier {
@EnvironmentObject private var purchaseHandler: PurchaseHandler
@Binding var isPresented: Bool
let onDismiss: (() -> Void)?
func body(content: Content) -> some View {
content.sheet(isPresented: $isPresented, onDismiss: onDismiss) {
CustomerCenterView()
....
}
}
}Totally fine to ship as-is and tackle the ownership cleanup separately. |
|
Did some quick sanity check testing
|
Created PWENG-101 for this change, so we can unblock this PR and merge. |
Checklist
purchases-androidand hybridsMotivation
All buttons initialized new purchase handlers whether or not the customer center would get presented by the button. This resulted in 1 purchase handler instance per button, and there were many created during the draw phase only to get deinitialized in moments
Description
Conditionally apply the logic that caused that problem
Note
Low Risk
Scoped presentation and handler reuse for Customer Center buttons; no auth or purchase API surface changes beyond using the existing environment handler.
Overview
Paywalls V2 button views no longer attach Customer Center presentation (and a fresh
PurchaseHandler) on every draw.ButtonComponentViewnow usesapplyIfso.presentCustomerCenterruns only when the button action is navigate to Customer Center, via a newopensCustomerCentercheck onButtonComponentViewModel.An internal
presentCustomerCenter(isPresented:purchaseHandler:onDismiss:)overload wires the sheet throughPresentingCustomerCenterModifierwith the paywall’s existingpurchaseHandlerfrom the environment instead ofPurchaseHandler.default(), so Customer Center shares the same handler instance when it is shown.Reviewed by Cursor Bugbot for commit d0d43b2. Bugbot is set up for automated code reviews on this repo. Configure here.