-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Hello Google Pay Team,
I've been looking at the GooglePayButtonComponent.kt file and have a question regarding the use of viewTreeObserver.addOnGlobalLayoutListener { requestLayout() } on line 40:
https://github.com/google-pay/react-native-make-payment/blob/main/android/src/main/java/com/makepayment/GooglePayButtonComponent.kt#L40
I have two main concerns with this implementation:
-
Necessity of the listener: In my own testing with a similar React Native/Android setup, the
requestLayout()call seems to work as expected without a global layout listener. The view updates its size correctly once the dimensions are available. Could you please provide some context on why this specific workaround is in place? Is it addressing a known issue that I might be unaware of?
For a context, I am setting up default minimal size of the view on React level. -
Potential Memory Leak: The
addOnGlobalLayoutListeneris never removed. This is a potential memory leak, as the listener would hold a reference to thePayButtonand its context even after the view has been detached. A best practice is to remove the listener usingremoveOnGlobalLayoutListenerin theonDetachedFromWindowlifecycle method.
Thank you for your time and for maintaining this library.