Skip to content

Commit 8661145

Browse files
commit 1 -> no FC dep on paymentsheet.
1 parent 0931ac1 commit 8661145

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

paymentsheet-example/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ emerge {
3434
dependencies {
3535
implementation project(':payments')
3636
implementation project(':stripecardscan')
37-
implementation project(':financial-connections')
3837

3938
implementation 'androidx.compose.foundation:foundation:1.7.8'
4039
implementation libs.androidx.activity

paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/PaymentSheetPlaygroundActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.compose.material.Button
1717
import androidx.compose.material.Text
1818
import androidx.compose.runtime.Composable
1919
import androidx.compose.runtime.LaunchedEffect
20+
import androidx.compose.runtime.collectAsState
2021
import androidx.compose.runtime.getValue
2122
import androidx.compose.runtime.mutableStateOf
2223
import androidx.compose.runtime.remember
@@ -51,7 +52,6 @@ import com.stripe.android.paymentsheet.example.samples.ui.shared.BuyButton
5152
import com.stripe.android.paymentsheet.example.samples.ui.shared.CHECKOUT_TEST_TAG
5253
import com.stripe.android.paymentsheet.example.samples.ui.shared.PaymentMethodSelector
5354
import com.stripe.android.paymentsheet.model.PaymentOption
54-
import com.stripe.android.uicore.utils.collectAsState
5555
import kotlinx.coroutines.Dispatchers
5656
import kotlinx.coroutines.flow.update
5757
import kotlinx.coroutines.withContext

paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/embedded/EmbeddedPlaygroundActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.compose.material.CircularProgressIndicator
1717
import androidx.compose.material.Text
1818
import androidx.compose.runtime.Composable
1919
import androidx.compose.runtime.LaunchedEffect
20+
import androidx.compose.runtime.collectAsState
2021
import androidx.compose.runtime.getValue
2122
import androidx.compose.runtime.mutableStateOf
2223
import androidx.compose.runtime.remember
@@ -44,7 +45,6 @@ import com.stripe.android.paymentsheet.example.playground.settings.PlaygroundCon
4445
import com.stripe.android.paymentsheet.example.playground.settings.PlaygroundSettings
4546
import com.stripe.android.paymentsheet.example.samples.ui.shared.BuyButton
4647
import com.stripe.android.paymentsheet.example.samples.ui.shared.PaymentMethodSelector
47-
import com.stripe.android.uicore.utils.collectAsState
4848
import kotlinx.coroutines.launch
4949

5050
@OptIn(ExperimentalEmbeddedPaymentElementApi::class)

paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/settings/PlaygroundSettings.kt

+45-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.os.Parcel
55
import android.os.Parcelable
66
import android.util.Log
7+
import androidx.annotation.RestrictTo
78
import androidx.compose.runtime.Stable
89
import androidx.core.content.edit
910
import com.stripe.android.core.utils.FeatureFlags
@@ -14,10 +15,17 @@ import com.stripe.android.paymentsheet.PaymentSheet
1415
import com.stripe.android.paymentsheet.example.playground.PlaygroundState
1516
import com.stripe.android.paymentsheet.example.playground.model.CheckoutRequest
1617
import com.stripe.android.paymentsheet.example.playground.model.CustomerEphemeralKeyRequest
17-
import com.stripe.android.uicore.utils.mapAsStateFlow
18+
import kotlinx.coroutines.InternalCoroutinesApi
19+
import kotlinx.coroutines.Job
20+
import kotlinx.coroutines.currentCoroutineContext
21+
import kotlinx.coroutines.ensureActive
22+
import kotlinx.coroutines.flow.Flow
23+
import kotlinx.coroutines.flow.FlowCollector
1824
import kotlinx.coroutines.flow.MutableStateFlow
1925
import kotlinx.coroutines.flow.StateFlow
2026
import kotlinx.coroutines.flow.asStateFlow
27+
import kotlinx.coroutines.flow.distinctUntilChanged
28+
import kotlinx.coroutines.flow.map
2129
import kotlinx.serialization.Serializable
2230
import kotlinx.serialization.SerializationException
2331
import kotlinx.serialization.builtins.MapSerializer
@@ -466,3 +474,39 @@ internal class PlaygroundSettings private constructor(
466474
uiSettingDefinitions + nonUiSettingDefinitions
467475
}
468476
}
477+
478+
private class FlowToStateFlow<T>(
479+
private val flow: Flow<T>,
480+
private val produceValue: () -> T,
481+
) : StateFlow<T> {
482+
483+
override val replayCache: List<T>
484+
get() = listOf(value)
485+
486+
override val value: T
487+
get() = produceValue()
488+
489+
@InternalCoroutinesApi
490+
override suspend fun collect(collector: FlowCollector<T>): Nothing {
491+
val collectorJob = currentCoroutineContext()[Job]
492+
flow.distinctUntilChanged().collect(collector)
493+
494+
try {
495+
while (true) {
496+
collectorJob?.ensureActive()
497+
}
498+
} finally {
499+
// Nothing to do here
500+
}
501+
}
502+
}
503+
504+
fun <T, R> StateFlow<T>.mapAsStateFlow(
505+
transform: (T) -> R,
506+
): StateFlow<R> {
507+
@Suppress("DEPRECATION")
508+
return FlowToStateFlow(
509+
flow = map(transform),
510+
produceValue = { transform(value) },
511+
)
512+
}

0 commit comments

Comments
 (0)