Closed zenyagami closed 8 months ago
👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!
Hi @zenyagami, thanks for reporting! We're taking a look but we haven't been able to repro yet. A few questions to help us debug this:
Paywall
composable inside a fragment correct? It might be related to this change but we're not sure yet since we aren't able to repro.
Hi @zenyagami, thanks for reporting! We're taking a look but we haven't been able to repro yet. A few questions to help us debug this:
- Seems that you're using the
Paywall
composable inside a fragment correct?- Could you share a snippet of code on how you're creating/displaying the paywall?
- Are you able to reproduce yourself?
- Is this the first version where you've implemented paywalls or did you have them before? If so, did you have the crash before?
It might be related to this change but we're not sure yet since we aren't able to repro.
I reproduced in a Realme 5i, and I saw devices like:
CPH1909, K2501, Model:Sp7731e_1h10_native, QUAD-CORE T3 P1, YT9213AJ,Vivo 1916 which are basically a headunit/tablets from china, that being said is related to the change in 1551, what I can see , the issue is in getScreenSize from your helper class WindowHelperKt
and the issue is in computeCurrentWindowMetrics
which expects UI context (no idea why). perhaps worth using something like
val windowSize = calculateWindowSizeClass(requireActivity()) // you can get the activity in compose as well
and yes I'm using a paywall in a fragment, it was not happening before, this is new this is my code
AppTheme {
val windowSize = calculateWindowSizeClass(requireActivity())
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
stringResource(id = AZ.string.premium_choose_title),
overflow = TextOverflow.Ellipsis
)
},
navigationIcon = {
IconButton(onClick = { onNavigationClicked() }) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.common_done)
)
}
},
actions = {
IconButton(onClick = { launchGoogleHelp() }) {
Icon(
imageVector = Icons.Filled.ManageAccounts,
contentDescription = null,
)
}
}
)
}
) { paddingValues ->
Box(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
) {
val options = PaywallOptions.Builder(
dismissRequest = {
onNavigationClicked()
},
).setListener(object : PaywallListener {
override fun onPurchaseCompleted(
customerInfo: CustomerInfo,
storeTransaction: StoreTransaction
) {
viewModel.onPurchaseCompleted(customerInfo)
onSuccessPurchase()
}
override fun onRestoreCompleted(customerInfo: CustomerInfo) {
viewModel.onPurchaseCompleted(customerInfo)
onRestored()
}
}).build()
// this is my workaround for the paywall, I'm forcing to use portrait but for some reason,
// some tablets the portrait mode is like landscape, so I used this in the mean time until RC implements the
// the landscape which is here I think https://github.com/RevenueCat/purchases-android/pull/1551
if (windowSize.heightSizeClass == WindowHeightSizeClass.Compact) {
PaywallFooter(options = options)
} else {
Paywall(
options = options
)
}
}
}
}
Hi @zenyagami, I've been investigating and it seems when using StrictMode
, it's possible this error might be triggered (Currently trying to repro). Is it possible you have StrictMode
enabled?
As for getting the activity, we currently use LocalContext.current
which may not be an UI context. We don't have direct access to the activity from the library right now. We could try to obtain it like this: https://stackoverflow.com/a/67927037 but that also had some issues from our tests, so we're studying our options.
Hi @zenyagami, I've been investigating and it seems when using
StrictMode
, it's possible this error might be triggered (Currently trying to repro). Is it possible you haveStrictMode
enabled?As for getting the activity, we currently use
LocalContext.current
which may not be an UI context. We don't have direct access to the activity from the library right now. We could try to obtain it like this: https://stackoverflow.com/a/67927037 but that also had some issues from our tests, so we're studying our options.
I dont have StrictMode explicitly enabled, and seems it does not hapens in all devices tho, the other alternative is that we send the windowSize already as param, the SO is using app Compat, maybe you can try how Google was getting it
/**
* Find the closest Activity in a given Context.
*/
internal fun Context.findActivity(): Activity {
var context = this
while (context is ContextWrapper) {
if (context is Activity) return context
context = context.baseContext
}
throw IllegalStateException("Permissions should be called in the context of an Activity")
}
This is from the accompanist and similar to the one in StackOverflow Here
Hi @zenyagami, we've just released version 7.4.0 with a fix we hope it might solve your problem: https://github.com/RevenueCat/purchases-android/pull/1570. Do you mind giving it a try?
Hi @zenyagami, we've just released version 7.4.0 with a fix we hope it might solve your problem: #1570. Do you mind giving it a try?
I have this error on react-native-purchase. When i look logcat i saw this error. "java.lang.IllegalArgumentException: Context android.app.ContextImpl@c4a1430 is not a UiContext" Have you any feedback about that? And if released android version was solution when this available for react native package?
Hi @furkanuzun, we just released a new version of the react native SDK with this fix: 7.17.1. Do you mind giving it a try and see if the issue still happens? Thanks for reporting this!
Hi @furkanuzun, we just released a new version of the react native SDK with this fix: 7.17.1. Do you mind giving it a try and see if the issue still happens? Thanks for reporting this!
Hi @tonidero, problem was solved in 7.17.1 version. Thanks!
Thanks @furkanuzun! Considering we already have reports of this being fixed, going to close this tentatively. If there are more issues we can reopen. Thanks again for reporting!
This issue has been automatically locked due to no recent activity after it was closed. Please open a new issue for related reports.
Describe the bug There is a crash in some devices, apparently in Tablets
Context android.app.ContextImpl@61fd4b4 is not a UiContext
I found that is in this codeval metrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(context)
apparentlycomputeCurrentWindowMetrics
need to be "UI context" and seems that is not always the case here is a stack traceAdditional context Add any other context about the problem here.