Skip to content

Commit

Permalink
Paywalls: disable PurchaseButton during purchases
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Oct 16, 2023
1 parent d1e6945 commit 785cf1b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import com.revenuecat.purchases.Offering
Expand All @@ -19,6 +18,7 @@ import com.revenuecat.purchases.models.Period
import com.revenuecat.purchases.models.Price
import com.revenuecat.purchases.models.TestStoreProduct
import com.revenuecat.purchases.paywalls.PaywallData
import com.revenuecat.purchases.ui.revenuecatui.composables.DisableTouchesComposable
import com.revenuecat.purchases.ui.revenuecatui.composables.Fade
import com.revenuecat.purchases.ui.revenuecatui.composables.PlaceholderDefaults
import com.revenuecat.purchases.ui.revenuecatui.composables.placeholder
Expand Down Expand Up @@ -75,7 +75,7 @@ internal fun LoadingPaywallView(mode: PaywallViewMode) {

@Composable
private fun LoadingPaywallView(state: PaywallViewState.Loaded, viewModel: PaywallViewModel) {
Box {
DisableTouchesComposable {
// Template
Template2(
state = state,
Expand All @@ -90,19 +90,6 @@ private fun LoadingPaywallView(state: PaywallViewState.Loaded, viewModel: Paywal
color = LoadingPaywallConstants.placeholderColor,
),
)

// Overlay to capture touches
Box(
Modifier
.matchParentSize()
.pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
awaitPointerEvent()
}
}
},
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.revenuecat.purchases.ui.revenuecatui.composables

import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput

@Composable
fun DisableTouchesComposable(
shouldDisable: Boolean = true,
content: @Composable () -> Unit,
) {
Box {
content()

if (shouldDisable) {
// Overlay to capture touches
Box(
Modifier
.matchParentSize()
.pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
awaitPointerEvent()
}
}
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ internal fun PurchaseButton(
viewModel: PaywallViewModel,
childModifier: Modifier = Modifier,
) {
PurchaseButton(
colors = state.templateConfiguration.getCurrentColors(),
packages = state.templateConfiguration.packages,
selectedPackage = state.selectedPackage,
viewModel = viewModel,
childModifier = childModifier,
)
DisableTouchesComposable(shouldDisable = viewModel.actionInProgress.value) {
PurchaseButton(
colors = state.templateConfiguration.getCurrentColors(),
packages = state.templateConfiguration.packages,
selectedPackage = state.selectedPackage,
viewModel = viewModel,
childModifier = childModifier,
)
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ internal class PaywallViewModelImpl(
*/
private fun verifyNoActionInProgressOrStartAction(): Boolean {
if (_actionInProgress.value) {
Logger.d("Ignoring purchase or restore because there already is an action in progress");
Logger.d("Ignoring purchase or restore because there already is an action in progress")
return true
}

Expand Down

0 comments on commit 785cf1b

Please sign in to comment.