Skip to content

Commit

Permalink
Fix paywall dialog composable sizing issues (#1556)
Browse files Browse the repository at this point in the history
### 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)
|
  • Loading branch information
tonidero authored Jan 12, 2024
1 parent 2f73f5d commit abbbfd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit abbbfd4

Please sign in to comment.