Skip to content

Commit

Permalink
Create generic StripeBottomSheetLayout and use in Payments
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed May 9, 2024
1 parent ec923ae commit 32aa4ea
Show file tree
Hide file tree
Showing 33 changed files with 411 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.stripe.android.StripePaymentController.Companion.SETUP_REQUEST_CODE
import com.stripe.android.model.PaymentMethodCreateParams
import com.stripe.android.model.StripeIntent
import com.stripe.android.payments.core.analytics.ErrorReporter
import com.stripe.android.utils.fadeOut
import com.stripe.android.uicore.utils.fadeOut
import com.stripe.android.view.AuthActivityStarterHost
import kotlinx.coroutines.launch
import org.json.JSONObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.google.android.gms.wallet.contract.ApiTaskResult
import com.google.android.gms.wallet.contract.TaskResultContracts.GetPaymentDataResult
import com.stripe.android.model.PaymentMethod
import com.stripe.android.payments.core.analytics.ErrorReporter
import com.stripe.android.utils.fadeOut
import com.stripe.android.uicore.utils.fadeOut
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.stripe.android.core.exception.StripeException
import com.stripe.android.payments.core.analytics.ErrorReporter
import com.stripe.android.utils.fadeOut
import com.stripe.android.uicore.utils.fadeOut
import com.stripe.android.view.AuthActivityStarterHost
import kotlinx.coroutines.launch

Expand Down

This file was deleted.

7 changes: 0 additions & 7 deletions paymentsheet/api/paymentsheet.api
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
public abstract interface annotation class com/stripe/android/ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi : java/lang/annotation/Annotation {
}

public final class com/stripe/android/common/ui/ComposableSingletons$BottomSheetKt {
public static final field INSTANCE Lcom/stripe/android/common/ui/ComposableSingletons$BottomSheetKt;
public static field lambda-1 Lkotlin/jvm/functions/Function2;
public fun <init> ()V
public final fun getLambda-1$paymentsheet_release ()Lkotlin/jvm/functions/Function2;
}

public abstract interface class com/stripe/android/customersheet/CustomerAdapter {
public static final field Companion Lcom/stripe/android/customersheet/CustomerAdapter$Companion;
public abstract fun attachPaymentMethod (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
1 change: 0 additions & 1 deletion paymentsheet/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<ID>LongMethod:USBankAccountForm.kt$@Composable private fun AccountDetailsForm( showCheckbox: Boolean, isProcessing: Boolean, bankName: String?, last4: String?, saveForFutureUseElement: SaveForFutureUseElement, onRemoveAccount: () -> Unit, )</ID>
<ID>MagicNumber:AutocompleteScreen.kt$0.07f</ID>
<ID>MagicNumber:BaseSheetActivity.kt$BaseSheetActivity$30</ID>
<ID>MagicNumber:BottomSheet.kt$BottomSheetState$10</ID>
<ID>MagicNumber:PaymentMethodsUI.kt$.3f</ID>
<ID>MagicNumber:PaymentMethodsUI.kt$.4f</ID>
<ID>MagicNumber:PaymentMethodsUI.kt$.5f</ID>
Expand Down
207 changes: 0 additions & 207 deletions paymentsheet/src/main/java/com/stripe/android/common/ui/BottomSheet.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.stripe.android.common.ui

import android.os.Build
import androidx.annotation.RestrictTo
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.ime
import androidx.compose.runtime.Composable
Expand All @@ -9,14 +11,23 @@ import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalTextInputService
import androidx.compose.ui.text.input.TextInputService
import com.stripe.android.uicore.BuildConfig
import com.stripe.android.uicore.elements.bottomsheet.StripeBottomSheetDismissalInterceptor
import kotlinx.coroutines.flow.first

internal class BottomSheetKeyboardHandler(
@RestrictTo(RestrictTo.Scope.LIBRARY)
class BottomSheetKeyboardHandler internal constructor(
private val textInputService: TextInputService?,
private val isKeyboardVisible: State<Boolean>,
) {
) : StripeBottomSheetDismissalInterceptor {

suspend fun dismiss() {
override suspend fun onBottomSheetDismissal() {
if (skipHideAnimation) {
return
}

// We dismiss the keyboard before we dismiss the sheet. This looks cleaner and prevents
// a CancellationException.
if (isKeyboardVisible.value) {
@Suppress("DEPRECATION")
textInputService?.hideSoftwareKeyboard()
Expand All @@ -29,10 +40,28 @@ internal class BottomSheetKeyboardHandler(
}
}

@RestrictTo(RestrictTo.Scope.LIBRARY)
@Composable
internal fun rememberBottomSheetKeyboardHandler(): BottomSheetKeyboardHandler {
fun rememberBottomSheetKeyboardHandler(): BottomSheetKeyboardHandler {
val imeHeight = WindowInsets.ime.getBottom(LocalDensity.current)
val isImeVisibleState = rememberUpdatedState(newValue = imeHeight > 0)
val textInputService = LocalTextInputService.current
return BottomSheetKeyboardHandler(textInputService, isImeVisibleState)
}

private val skipHideAnimation: Boolean
get() = BuildConfig.DEBUG && (isRunningUnitTest || isRunningUiTest)

private val isRunningUnitTest: Boolean
get() {
return runCatching {
Build.FINGERPRINT.lowercase() == "robolectric"
}.getOrDefault(false)
}

private val isRunningUiTest: Boolean
get() {
return runCatching {
Class.forName("androidx.test.InstrumentationRegistry")
}.isSuccess
}

0 comments on commit 32aa4ea

Please sign in to comment.