-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add PaywallFragmentViewModel to share data with caller fragment/activity #602
Conversation
Tested this in flutter. I was able to make it work!! (get the result returned through the VM) |
internal class PaywallFragment( | ||
private val requiredEntitlementIdentifier: String?, | ||
) : Fragment(), PaywallResultHandler { | ||
internal class PaywallFragment : Fragment(), PaywallResultHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that since we're using a fragment, this does require the hybrid to use some subclass of a FragmentActivity
... But most hybrids provide some of those, without having to provide our own version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember that we found out that we needed to use an activity on Flutter, as they say that's the preferred method. Are you thinking of forcing users to use our own fragment parent class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the idea is for the developer to use FlutterFragmentActivity
(provided by flutter) instead of the PurchasesFlutterActivity
. That way, the current presentPaywallFromFragment
method we have here should take care of launching this fragment and from there the activity.
I believe the reason we created that custom activity was to try to get a result back from the paywall activity right? @NachoSoto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be solved with the view model we're adding here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this works then sounds great!
Yup it works well! The only thing I see is that the activity in Android has the title bar, which it didn't use to have, but I think that's unrelated to this change and possibly related to RevenueCat/purchases-android#1511. Want to take a look at that tomorrow |
### RevenueCatUI * Separate paywalls into a different module (#604) via Toni Rico (@tonidero) * Add PaywallFragmentViewModel to share data with caller fragment/activity (#602) via Toni Rico (@tonidero) * Paywalls: Expose delegate in PaywallProxy to receive events (#586) via Toni Rico (@tonidero) ### Other Changes * Update paywalls branch with main (#592) via Cesar de la Vega (@vegaro) * Re-organize android library (#603) via Toni Rico (@tonidero) * Update paywalls with latest main (#601) via Toni Rico (@tonidero) * Actually set delegate via NachoSoto (@NachoSoto) * Dismiss paywall automatically via NachoSoto (@NachoSoto) * `displayCloseButton` via NachoSoto (@NachoSoto) * Lint via NachoSoto (@NachoSoto) * [remove me] change `minSdkVersion` via NachoSoto (@NachoSoto) * Fix other platforms via NachoSoto (@NachoSoto) * Optional parameter via NachoSoto (@NachoSoto) * Lint via NachoSoto (@NachoSoto) * Revert SDK version change via NachoSoto (@NachoSoto) * Finished API via NachoSoto (@NachoSoto) * [WIP] `RevenueCatUI` support via NachoSoto (@NachoSoto)
After RevenueCat/purchases-hybrid-common#602, we can now use the `PaywallHelpers.presentPaywallFromFragment` method to present the paywall and receive a result back using an internal view model. This makes it so the `PurchasesFlutterActivity` isn't needed anymore and we can make use of that functionality, shared with other hybrids. Note that this does mean developers need to make sure their android activity inherits from `FlutterFragmentActivity` (or other `FragmentActivity`) and not `FlutterActivity`, as we need to present the fragment. ### TODO - [x] Hide action bar: RevenueCat/purchases-android#1532 - [x] Update PHC with those 2 changes.
This is an attempt to be able to have some sort of completion listener from the calling fragment/activity. The idea is to use a shared view model, which doesn't need to be exposed, to share data using the underlying activity. The flow would be:
PaywallResultListener
to listen to the result of the paywallPaywallFragmentViewModel
using the underlying activity and set that listener therePaywallFragment
itself, we also get the same instance of thePaywallFragmentViewModel
, giving us access to the same result listener.Note that I haven't exposed a
PaywallListener
directly. The reason for that is that we're using a different activity for the paywall, so we can't use the underlying activity to communicate with that (we would need the underlying application context). This would require making the Paywall activity as a fragment instead of an activity in purchases-android.