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

fix: add FragmentActivity check in RNPaywallsModule (fixes #1127) #1186

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

NosimusAI
Copy link

What and Why
This PR addresses an issue where the paywall presentation on Android can lead to crashes when the current activity is not a FragmentActivity or when the PaywallView is not fully initialized. The changes introduced aim to:

Delayed Initialization:
By ensuring that the view is fully initialized (using techniques like posting to the view), we can attach listeners only after the PaywallView is attached to the window. This minimizes the risk of lifecycle-related crashes during asynchronous operations or UI updates.

FragmentActivity Check:
The updated code now verifies whether the current activity is an instance of FragmentActivity. If it isn’t, an error is logged and the promise is rejected with the code E_ACTIVITY_NOT_FRAGMENT. This prevents the paywall from being presented in an unsupported activity type, which could otherwise lead to runtime crashes.

Additional Considerations
Testing:
This change has not been fully tested yet. Once integrated, please ensure thorough testing across various Android devices and configurations to confirm that the paywall presentation behaves correctly without crashes.

Logging:
Enhanced logging is in place to help diagnose if an unsupported activity type is encountered, which should aid in future debugging efforts.

Thank you for contributing to react-native-purchases. Before pressing the "Create Pull Request" button, please provide the following:

  • A description about what and why you are contributing, even if it's trivial.

  • The issue number(s) or PR number(s) in the description if you are contributing in response to those.

  • If applicable, unit tests.

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.

Thank you for opening. It makes sense to me. We can also make the changes if you prefer

view.setDismissHandler(getDismissHandler(themedReactContext, view))
return PaywallView(themedReactContext).apply {
// Ensure the view is properly initialized before setting listeners
post {
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 makes sense @RevenueCat/coresdk ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I guess doing it like this we could potentially lose some events if they happen before the view displays. So for example, if for some reason we want to send a dismiss event before the view is drawn... This seems unlikely so it should be ok yeah, we just need to be aware of this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android app crashes when paywall is triggered
3 participants