Hello,
I am in the process of migrating one of our apps to Jetpack Compose which is using RevenueCat for processing purchases. Earlier, the code to make the purchase was inside the Fragment and hence I was able to pass the Activity Context while calling the purchasePackageWith() function.
However, now the code to make the purchase is moved to the repository where I am injecting the Context using Dagger Hilt. Since, the injected code is an Application Context I am unable to call the purchasePackageWith() function.
I tried getting the Activity Context using the below code but it doesn’t work.
fun Context.findActivity(): Activity? = when (this) {
is Activity -> this
is ContextWrapper -> baseContext.findActivity()
else -> null
}
I can pass the Activity Context from the composable screen to the repository via ViewModel but that may leak the activity. So, is there any proper approach to do the same?