From abbbfd4c51364e1c0ac84f0947a80422b19692a1 Mon Sep 17 00:00:00 2001 From: Toni Rico Date: Fri, 12 Jan 2024 19:13:58 +0100 Subject: [PATCH] Fix paywall dialog composable sizing issues (#1556) ### Description As I was testing #1551, I noticed that the dialog size wasn't correct. The width of the device sometimes was `MEDIUM` on a phone, causing it to present the dialog in a narrowed version. After more testing, I noticed that it was always one of the dimensions that were not `COMPACT` on my emulator, so I decided to check both. If one of the dimensions is `COMPACT`, we would present the dialog as full screen. | Before | After | | ------------- | ------------- | | ![image](https://github.com/RevenueCat/purchases-android/assets/808417/de5900ca-f0cc-48d1-8e32-64ea58819a7c) | ![image](https://github.com/RevenueCat/purchases-android/assets/808417/c3a987a8-37b2-444c-81cc-4e8a16a98b44) | --- .../purchases/ui/revenuecatui/PaywallDialog.kt | 15 +++------------ .../ui/revenuecatui/helpers/WindowHelper.kt | 7 +++++++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/PaywallDialog.kt b/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/PaywallDialog.kt index 6011a289f7..16ae9538e3 100644 --- a/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/PaywallDialog.kt +++ b/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/PaywallDialog.kt @@ -16,8 +16,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogProperties -import androidx.window.core.layout.WindowWidthSizeClass -import com.revenuecat.purchases.ui.revenuecatui.helpers.computeWindowWidthSizeClass +import com.revenuecat.purchases.ui.revenuecatui.helpers.hasCompactDimension import com.revenuecat.purchases.ui.revenuecatui.helpers.shouldDisplayPaywall import com.revenuecat.purchases.ui.revenuecatui.helpers.windowAspectRatio import kotlinx.coroutines.launch @@ -91,19 +90,11 @@ private fun getDialogMaxHeightPercentage(): Float { if (windowAspectRatio() < UIDialogConstants.MAX_ASPECT_RATIO_TO_APPLY_MAX_HEIGHT) { return 1f } - return computeWindowWidthSizeClass().let { - when (it) { - WindowWidthSizeClass.MEDIUM, WindowWidthSizeClass.EXPANDED -> UIDialogConstants.MAX_HEIGHT_PERCENTAGE_TABLET - else -> 1f - } - } + return if (hasCompactDimension()) 1f else UIDialogConstants.MAX_HEIGHT_PERCENTAGE_TABLET } @Composable @ReadOnlyComposable private fun shouldUsePlatformDefaultWidth(): Boolean { - return when (computeWindowWidthSizeClass()) { - WindowWidthSizeClass.MEDIUM, WindowWidthSizeClass.EXPANDED -> true - else -> false - } + return !hasCompactDimension() } diff --git a/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/helpers/WindowHelper.kt b/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/helpers/WindowHelper.kt index 8528d4d884..da15aa0a4e 100644 --- a/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/helpers/WindowHelper.kt +++ b/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/helpers/WindowHelper.kt @@ -25,6 +25,13 @@ internal fun computeWindowHeightSizeClass(): WindowHeightSizeClass { return windowSizeClass().windowHeightSizeClass } +@Composable +@ReadOnlyComposable +internal fun hasCompactDimension(): Boolean { + return computeWindowHeightSizeClass() == WindowHeightSizeClass.COMPACT || + computeWindowWidthSizeClass() == WindowWidthSizeClass.COMPACT +} + @Composable @ReadOnlyComposable internal fun PaywallState.Loaded.shouldUseLandscapeLayout(): Boolean {