Skip to content

Commit

Permalink
Add Embedded Appearance params to AppearanceBottomSheetDialogFragment (
Browse files Browse the repository at this point in the history
…#9727)

* Add Embedded Appearance params to AppearanceBottomSheetDialogFragment
  • Loading branch information
tjclawson-stripe authored Dec 5, 2024
1 parent d0b46bc commit ff9c0f9
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 5 deletions.
6 changes: 6 additions & 0 deletions paymentsheet-example/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
<ID>EmptyFunctionBlock:DrawablePainter.kt$EmptyPainter${}</ID>
<ID>FunctionNaming:Receipt.kt$@Preview @Composable fun Receipt_Editable()</ID>
<ID>FunctionNaming:Receipt.kt$@Preview @Composable fun Receipt_NotEditable()</ID>
<ID>LongMethod:AppearanceBottomSheetDialogFragment.kt$@Composable private fun AppearancePicker( currentAppearance: PaymentSheet.Appearance, updateAppearance: (PaymentSheet.Appearance) -> Unit, embeddedAppearance: EmbeddedAppearance, updateEmbedded: (EmbeddedAppearance) -> Unit, resetAppearance: () -> Unit, )</ID>
<ID>LongMethod:AppearanceBottomSheetDialogFragment.kt$@Composable private fun Colors( currentAppearance: PaymentSheet.Appearance, updateAppearance: (PaymentSheet.Appearance) -> Unit, )</ID>
<ID>LongMethod:AppearanceBottomSheetDialogFragment.kt$@Composable private fun EmbeddedPicker( embeddedAppearance: EmbeddedAppearance, updateEmbedded: (EmbeddedAppearance) -> Unit )</ID>
<ID>LongMethod:AppearanceBottomSheetDialogFragment.kt$@Composable private fun PrimaryButton( currentAppearance: PaymentSheet.Appearance, updateAppearance: (PaymentSheet.Appearance) -> Unit, )</ID>
<ID>LongMethod:Receipt.kt$@Composable fun Receipt( isLoading: Boolean, cartState: CartState, isEditable: Boolean = false, onQuantityChanged: (CartProduct.Id, Int) -> Unit = { _, _ -> }, bottomContent: @Composable () -> Unit, )</ID>
<ID>MagicNumber:AppearanceBottomSheetDialogFragment.kt$16</ID>
<ID>MagicNumber:AppearanceBottomSheetDialogFragment.kt$33</ID>
<ID>MagicNumber:CartProduct.kt$100</ID>
<ID>MagicNumber:DrawablePainter.kt$DrawablePainter$23</ID>
<ID>MagicNumber:DrawablePainter.kt$DrawablePainter$255</ID>
<ID>MagicNumber:EmbeddedAppearanceSettingsDefinition.kt$EmbeddedAppearance$0x33787880</ID>
<ID>MagicNumber:EmbeddedAppearanceSettingsDefinition.kt$EmbeddedAppearance$0xFF007AFF</ID>
<ID>MagicNumber:EmbeddedAppearanceSettingsDefinition.kt$EmbeddedAppearance$0xFF787880</ID>
<ID>MagicNumber:Payment.kt$0.5f</ID>
<ID>PackageNaming:CompleteFlowActivity.kt$package com.stripe.android.paymentsheet.example.samples.ui.paymentsheet.complete_flow</ID>
<ID>PackageNaming:CompleteFlowViewModel.kt$package com.stripe.android.paymentsheet.example.samples.ui.paymentsheet.complete_flow</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -53,8 +52,10 @@ import com.stripe.android.paymentsheet.example.playground.activity.AppearanceBot
import com.stripe.android.paymentsheet.example.playground.activity.AppearanceStore
import com.stripe.android.paymentsheet.example.playground.activity.FawryActivity
import com.stripe.android.paymentsheet.example.playground.activity.QrCodeActivity
import com.stripe.android.paymentsheet.example.playground.activity.getEmbeddedAppearance
import com.stripe.android.paymentsheet.example.playground.embedded.EmbeddedPlaygroundContract
import com.stripe.android.paymentsheet.example.playground.settings.CheckoutMode
import com.stripe.android.paymentsheet.example.playground.settings.EmbeddedAppearanceSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.InitializationType
import com.stripe.android.paymentsheet.example.playground.settings.PlaygroundConfigurationData
import com.stripe.android.paymentsheet.example.playground.settings.PlaygroundSettings
Expand All @@ -63,6 +64,7 @@ import com.stripe.android.paymentsheet.example.samples.ui.shared.BuyButton
import com.stripe.android.paymentsheet.example.samples.ui.shared.CHECKOUT_TEST_TAG
import com.stripe.android.paymentsheet.example.samples.ui.shared.PaymentMethodSelector
import com.stripe.android.paymentsheet.model.PaymentOption
import com.stripe.android.uicore.utils.collectAsState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -210,9 +212,23 @@ internal class PaymentSheetPlaygroundActivity : AppCompatActivity(), ExternalPay

@Composable
private fun AppearanceButton() {
val settings = viewModel.playgroundSettingsFlow.collectAsState().value
val embeddedAppearance = settings?.get(EmbeddedAppearanceSettingsDefinition)?.collectAsState()?.value
supportFragmentManager.setFragmentResultListener(
AppearanceBottomSheetDialogFragment.REQUEST_KEY,
this@PaymentSheetPlaygroundActivity
) { _, bundle ->
viewModel.updateEmbeddedAppearance(
EmbeddedAppearanceSettingsDefinition,
bundle.getEmbeddedAppearance()
)
}
Button(
onClick = {
val bottomSheet = AppearanceBottomSheetDialogFragment.newInstance()
bottomSheet.arguments = Bundle().apply {
putParcelable(AppearanceBottomSheetDialogFragment.EMBEDDED_KEY, embeddedAppearance)
}
bottomSheet.show(supportFragmentManager, bottomSheet.tag)
},
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import com.stripe.android.paymentsheet.example.playground.settings.Country
import com.stripe.android.paymentsheet.example.playground.settings.CustomEndpointDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CustomerSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CustomerType
import com.stripe.android.paymentsheet.example.playground.settings.EmbeddedAppearance
import com.stripe.android.paymentsheet.example.playground.settings.EmbeddedAppearanceSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.InitializationType
import com.stripe.android.paymentsheet.example.playground.settings.PlaygroundConfigurationData
import com.stripe.android.paymentsheet.example.playground.settings.PlaygroundSettings
Expand Down Expand Up @@ -591,6 +593,21 @@ internal class PaymentSheetPlaygroundViewModel(
}
}

fun updateEmbeddedAppearance(appearanceSetting: EmbeddedAppearanceSettingsDefinition, value: EmbeddedAppearance) {
playgroundSettingsFlow.value?.let { settings ->
settings[appearanceSetting] = value
setPlaygroundState(
state.value?.let { state ->
val updatedSnapshot = settings.snapshot()
when (state) {
is PlaygroundState.Customer -> state.copy(snapshot = updatedSnapshot)
is PlaygroundState.Payment -> state.copy(snapshot = updatedSnapshot)
}
}
)
}
}

private fun updatePaymentOptionForCustomerSheet(paymentOption: PaymentOption?) {
customerSheetState.update { existingState ->
existingState?.copy(
Expand Down
Loading

0 comments on commit ff9c0f9

Please sign in to comment.