Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove last usages of stateIn. #8421

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ import com.stripe.android.uicore.utils.mapAsStateFlow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
Expand Down Expand Up @@ -129,11 +127,7 @@ internal class PaymentOptionsViewModel @Inject constructor(
override var newPaymentSelection: PaymentSelection.New? =
args.state.paymentSelection as? PaymentSelection.New

override val primaryButtonUiState = primaryButtonUiStateMapper.forCustomFlow().stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = null,
)
override val primaryButtonUiState = primaryButtonUiStateMapper.forCustomFlow()

init {
SessionSavedStateHandler.attachTo(this, savedStateHandle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeoutOrNull
Expand Down Expand Up @@ -201,11 +199,7 @@ internal class PaymentSheetViewModel @Inject internal constructor(
}
}

override val primaryButtonUiState = primaryButtonUiStateMapper.forCompleteFlow().stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = null,
)
override val primaryButtonUiState = primaryButtonUiStateMapper.forCompleteFlow()

override val error: StateFlow<String?> = buyButtonState.mapAsStateFlow { it?.errorMessage?.message }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.paymentsheet.navigation.PaymentSheetScreen
import com.stripe.android.paymentsheet.ui.PrimaryButton
import com.stripe.android.ui.core.Amount
import kotlinx.coroutines.flow.Flow
import com.stripe.android.uicore.utils.combineAsStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import com.stripe.android.ui.core.R as StripeUiCoreR

internal class PrimaryButtonUiStateMapper(
Expand All @@ -24,8 +23,8 @@ internal class PrimaryButtonUiStateMapper(
private val onClick: () -> Unit,
) {

fun forCompleteFlow(): Flow<PrimaryButton.UIState?> {
return combine(
fun forCompleteFlow(): StateFlow<PrimaryButton.UIState?> {
return combineAsStateFlow(
currentScreenFlow,
buttonsEnabledFlow,
amountFlow,
Expand All @@ -41,8 +40,8 @@ internal class PrimaryButtonUiStateMapper(
}
}

fun forCustomFlow(): Flow<PrimaryButton.UIState?> {
return combine(
fun forCustomFlow(): StateFlow<PrimaryButton.UIState?> {
return combineAsStateFlow(
currentScreenFlow,
buttonsEnabledFlow,
selectionFlow,
Expand Down
Loading