react-native-purchases icon indicating copy to clipboard operation
react-native-purchases copied to clipboard

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

Open NosimusAI opened this issue 8 months ago • 4 comments

  • Closes #1127

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:

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

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

  • [ ] If applicable, unit tests.

NosimusAI avatar Feb 22 '25 17:02 NosimusAI