Skip to content

Commit

Permalink
Introduced custom interaction blocked flag (#255)
Browse files Browse the repository at this point in the history
* Introduced custom interaction blocked flag

* Moved from UIApplicationMain to main
  • Loading branch information
Robert-SD authored Aug 30, 2024
1 parent 50dcc3f commit fb5d486
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import com.adyen.checkout.flutter.components.instant.InstantComponentManager
import com.adyen.checkout.flutter.components.view.ComponentLoadingBottomSheet
import com.adyen.checkout.flutter.session.SessionHolder
import com.adyen.checkout.flutter.utils.Constants
import com.adyen.checkout.flutter.utils.Constants.Companion.CARD_SESSION_COMPONENT_KEY
import com.adyen.checkout.flutter.utils.Constants.Companion.CARD_ADVANCED_COMPONENT_KEY
import com.adyen.checkout.redirect.RedirectComponent
import io.flutter.embedding.engine.plugins.FlutterPlugin
import org.json.JSONObject
Expand Down Expand Up @@ -154,7 +152,6 @@ class ComponentPlatformApi(
resultCode: String?,
componentId: String
) {
resetPaymentInProgress(componentId)
val model =
ComponentCommunicationModel(
ComponentCommunicationType.RESULT,
Expand All @@ -180,7 +177,6 @@ class ComponentPlatformApi(
error: ErrorDTO?,
componentId: String
) {
resetPaymentInProgress(componentId)
val model =
ComponentCommunicationModel(
ComponentCommunicationType.RESULT,
Expand Down Expand Up @@ -215,11 +211,4 @@ class ComponentPlatformApi(
currentComponent?.handleIntent(intent)
}
}

// Reset isPaymentInProgress to false again. We can remove this when the pay button handles the pressed state itself.
private fun resetPaymentInProgress(componentId: String) {
when (componentId) {
CARD_ADVANCED_COMPONENT_KEY, CARD_SESSION_COMPONENT_KEY -> cardComponentManager.setPaymentInProgress(false)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ abstract class BaseCardComponent(

fun setCurrentCardComponent() = setCurrentCardComponent(this)

fun setPaymentInProgress(isLoading: Boolean) = cardComponent?.setInteractionBlocked(isLoading)

companion object {
const val CARD_COMPONENT_CONFIGURATION_KEY = "cardComponentConfiguration"
const val PAYMENT_METHOD_KEY = "paymentMethod"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ internal class CardComponentManager(
)
}

fun setPaymentInProgress(isLoading: Boolean) = currentCardComponent?.setPaymentInProgress(isLoading)

private fun setCurrentCardComponent(currentCardComponent: BaseCardComponent) {
this.currentCardComponent = currentCardComponent
assignCurrentComponent(currentCardComponent.cardComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ internal class CardAdvancedCallback(
private val componentFlutterApi: ComponentFlutterInterface,
private val componentId: String,
private val assignCurrentComponent: () -> Unit,
private val setPaymentInProgress: (Boolean) -> Unit,
) : ComponentAdvancedCallback<CardComponentState>(componentFlutterApi, componentId) {
override fun onSubmit(state: CardComponentState) {
assignCurrentComponent.invoke()
setPaymentInProgress.invoke(true)
super.onSubmit(state)
}

override fun onError(componentError: ComponentError) {
setPaymentInProgress.invoke(false)
super.onError(componentError)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ internal class CardAdvancedComponent(
componentFlutterApi,
componentId,
::setCurrentCardComponent,
::setPaymentInProgress
),
key = UUID.randomUUID().toString()
)
Expand All @@ -57,7 +56,6 @@ internal class CardAdvancedComponent(
componentFlutterApi,
componentId,
::setCurrentCardComponent,
::setPaymentInProgress
),
key = UUID.randomUUID().toString()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ internal class CardSessionCallback(
private val componentId: String,
private val onActionCallback: (Action) -> Unit,
private val assignCurrentComponent: () -> Unit,
private val setPaymentInProgress: (Boolean) -> Unit,
) : ComponentSessionCallback<CardComponentState>(componentFlutterApi, componentId, onActionCallback) {
override fun onSubmit(state: CardComponentState): Boolean {
assignCurrentComponent()
return super.onSubmit(state)
}

override fun onLoading(isLoading: Boolean) {
setPaymentInProgress.invoke(isLoading)
super.onLoading(isLoading)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ internal class CardSessionComponent(
componentId,
::onAction,
::setCurrentCardComponent,
::setPaymentInProgress
),
key = UUID.randomUUID().toString()
)
Expand All @@ -76,7 +75,6 @@ internal class CardSessionComponent(
componentId,
::onAction,
::setCurrentCardComponent,
::setPaymentInProgress
),
key = UUID.randomUUID().toString()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DynamicComponentView
private var componentFlutterApi: ComponentFlutterInterface? = null
private var componentId: String = ""
private var ignoreLayoutChanges = false
private var interactionBlocked = false

constructor(
componentActivity: ComponentActivity,
Expand Down Expand Up @@ -81,6 +82,7 @@ class DynamicComponentView
activity = null
componentFlutterApi = null
ignoreLayoutChanges = false
interactionBlocked = false
}

private fun <T> onComponentViewGlobalLayout(
Expand All @@ -105,7 +107,11 @@ class DynamicComponentView
payButton?.setOnClickListener {
isHintAnimationEnabledOnTextInputFields(this, false)
ignoreLayoutChanges = true
component.submit()
if (!interactionBlocked) {
interactionBlocked = true
component.submit()
}
resetInteractionBlocked()
postDelayed(100) {
resizeFlutterViewport(calculateFlutterViewportHeight())
}
Expand Down Expand Up @@ -143,4 +149,11 @@ class DynamicComponentView
}
}
}

// TODO - We can use cardComponent.setInteractionBlocked() when the fix for releasing the blocked interaction is available in then native SDK
private fun resetInteractionBlocked() {
postDelayed(1000) {
interactionBlocked = false
}
}
}
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import adyen_checkout
import Flutter
import UIKit

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down

0 comments on commit fb5d486

Please sign in to comment.