Skip to content

Commit 57d14fb

Browse files
committed
fix: add FragmentActivity check and error handling in RNPaywallsModule (fixes RevenueCat#1127)
1 parent 23db42a commit 57d14fb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

react-native-purchases-ui/android/src/main/java/com/revenuecat/purchases/react/ui/PaywallViewManager.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ internal class PaywallViewManager : BasePaywallViewManager<PaywallView>() {
1818
}
1919

2020
override fun createViewInstance(themedReactContext: ThemedReactContext): PaywallView {
21-
return PaywallView(themedReactContext).also { view ->
22-
view.setPaywallListener(createPaywallListenerWrapper(themedReactContext, view))
23-
view.setDismissHandler(getDismissHandler(themedReactContext, view))
21+
return PaywallView(themedReactContext).apply {
22+
// Ensure the view is properly initialized before setting listeners
23+
post {
24+
setPaywallListener(createPaywallListenerWrapper(themedReactContext, this))
25+
setDismissHandler(getDismissHandler(themedReactContext, this))
26+
}
2427
}
2528
}
2629

react-native-purchases-ui/android/src/main/java/com/revenuecat/purchases/react/ui/RNPaywallsModule.kt

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal class RNPaywallsModule(reactContext: ReactApplicationContext) :
2626
is FragmentActivity -> currentActivity
2727
else -> {
2828
Log.e(NAME, "RevenueCat paywalls require application to use a FragmentActivity")
29+
promise.reject("E_ACTIVITY_NOT_FRAGMENT", "Current activity is not a FragmentActivity")
2930
null
3031
}
3132
}

0 commit comments

Comments
 (0)