Skip to content

Commit

Permalink
Merge pull request #1579 from Adyen/fix/action-component-leak
Browse files Browse the repository at this point in the history
Fix memroy leak in action components
  • Loading branch information
jreij committed Apr 24, 2024
2 parents 634b72c + df7b346 commit 89bb2f4
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 20 deletions.
Expand Up @@ -66,12 +66,14 @@ constructor(

Adyen3DS2Component(
delegate = adyen3DS2Delegate,
actionComponentEventHandler = DefaultActionComponentEventHandler(callback),
actionComponentEventHandler = DefaultActionComponentEventHandler(),
)
}
return ViewModelProvider(viewModelStoreOwner, threeDS2Factory)[key, Adyen3DS2Component::class.java]
.also { component ->
component.observe(lifecycleOwner, component.actionComponentEventHandler::onActionComponentEvent)
component.observe(lifecycleOwner) {
component.actionComponentEventHandler.onActionComponentEvent(it, callback)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Expand Up @@ -9,4 +9,4 @@
[//]: # ( - Configurations public constructor are deprecated, please use each Configuration's builder to make a Configuration object)

## Fixed
- Fixed a memory leak in `DropInActivity`.
- Fixed various memory leaks.
Expand Up @@ -62,12 +62,14 @@ constructor(
val genericActionDelegate = getDelegate(checkoutConfiguration, savedStateHandle, application)
GenericActionComponent(
genericActionDelegate = genericActionDelegate,
actionComponentEventHandler = DefaultActionComponentEventHandler(callback),
actionComponentEventHandler = DefaultActionComponentEventHandler(),
)
}
return ViewModelProvider(viewModelStoreOwner, genericActionFactory)[key, GenericActionComponent::class.java]
.also { component ->
component.observe(lifecycleOwner, component.actionComponentEventHandler::onActionComponentEvent)
component.observe(lifecycleOwner) {
component.actionComponentEventHandler.onActionComponentEvent(it, callback)
}
}
}

Expand Down
Expand Up @@ -62,11 +62,13 @@ constructor(
val awaitDelegate = getDelegate(checkoutConfiguration, savedStateHandle, application)
AwaitComponent(
awaitDelegate,
DefaultActionComponentEventHandler(callback),
DefaultActionComponentEventHandler(),
)
}
return ViewModelProvider(viewModelStoreOwner, awaitFactory)[key, AwaitComponent::class.java].also { component ->
component.observe(lifecycleOwner, component.actionComponentEventHandler::onActionComponentEvent)
component.observe(lifecycleOwner) {
component.actionComponentEventHandler.onActionComponentEvent(it, callback)
}
}
}

Expand Down
Expand Up @@ -9,8 +9,9 @@
package com.adyen.checkout.components.core.internal

import androidx.annotation.RestrictTo
import com.adyen.checkout.components.core.ActionComponentCallback

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
interface ActionComponentEventHandler {
fun onActionComponentEvent(event: ActionComponentEvent)
fun onActionComponentEvent(event: ActionComponentEvent, actionComponentCallback: ActionComponentCallback)
}
Expand Up @@ -14,11 +14,9 @@ import com.adyen.checkout.core.AdyenLogLevel
import com.adyen.checkout.core.internal.util.adyenLog

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
class DefaultActionComponentEventHandler(
private val actionComponentCallback: ActionComponentCallback
) : ActionComponentEventHandler {
class DefaultActionComponentEventHandler : ActionComponentEventHandler {

override fun onActionComponentEvent(event: ActionComponentEvent) {
override fun onActionComponentEvent(event: ActionComponentEvent, actionComponentCallback: ActionComponentCallback) {
adyenLog(AdyenLogLevel.VERBOSE) { "Event received $event" }
when (event) {
is ActionComponentEvent.ActionDetails -> actionComponentCallback.onAdditionalDetails(event.data)
Expand Down
Expand Up @@ -61,12 +61,14 @@ constructor(
val qrCodeDelegate = getDelegate(checkoutConfiguration, savedStateHandle, application)
QRCodeComponent(
delegate = qrCodeDelegate,
actionComponentEventHandler = DefaultActionComponentEventHandler(callback),
actionComponentEventHandler = DefaultActionComponentEventHandler(),
)
}
return ViewModelProvider(viewModelStoreOwner, qrCodeFactory)[key, QRCodeComponent::class.java]
.also { component ->
component.observe(lifecycleOwner, component.actionComponentEventHandler::onActionComponentEvent)
component.observe(lifecycleOwner) {
component.actionComponentEventHandler.onActionComponentEvent(it, callback)
}
}
}

Expand Down
Expand Up @@ -59,12 +59,14 @@ constructor(
val redirectDelegate = getDelegate(checkoutConfiguration, savedStateHandle, application)
RedirectComponent(
delegate = redirectDelegate,
actionComponentEventHandler = DefaultActionComponentEventHandler(callback),
actionComponentEventHandler = DefaultActionComponentEventHandler(),
)
}
return ViewModelProvider(viewModelStoreOwner, redirectFactory)[key, RedirectComponent::class.java]
.also { component ->
component.observe(lifecycleOwner, component.actionComponentEventHandler::onActionComponentEvent)
component.observe(lifecycleOwner) {
component.actionComponentEventHandler.onActionComponentEvent(it, callback)
}
}
}

Expand Down
Expand Up @@ -57,12 +57,14 @@ constructor(
val voucherDelegate = getDelegate(checkoutConfiguration, savedStateHandle, application)
VoucherComponent(
delegate = voucherDelegate,
actionComponentEventHandler = DefaultActionComponentEventHandler(callback),
actionComponentEventHandler = DefaultActionComponentEventHandler(),
)
}
return ViewModelProvider(viewModelStoreOwner, voucherFactory)[key, VoucherComponent::class.java]
.also { component ->
component.observe(lifecycleOwner, component.actionComponentEventHandler::onActionComponentEvent)
component.observe(lifecycleOwner) {
component.actionComponentEventHandler.onActionComponentEvent(it, callback)
}
}
}

Expand Down
Expand Up @@ -59,13 +59,15 @@ constructor(
val weChatDelegate = getDelegate(checkoutConfiguration, savedStateHandle, application)
WeChatPayActionComponent(
delegate = weChatDelegate,
actionComponentEventHandler = DefaultActionComponentEventHandler(callback),
actionComponentEventHandler = DefaultActionComponentEventHandler(),
)
}

return ViewModelProvider(viewModelStoreOwner, weChatFactory)[key, WeChatPayActionComponent::class.java]
.also { component ->
component.observe(lifecycleOwner, component.actionComponentEventHandler::onActionComponentEvent)
component.observe(lifecycleOwner) {
component.actionComponentEventHandler.onActionComponentEvent(it, callback)
}
}
}

Expand Down

0 comments on commit 89bb2f4

Please sign in to comment.