Skip to content

Discussion: use of viewTreeObserver.addOnGlobalLayoutListener #63

@descorp

Description

@descorp

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:

  1. 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.

  2. Potential Memory Leak: The addOnGlobalLayoutListener is never removed. This is a potential memory leak, as the listener would hold a reference to the PayButton and its context even after the view has been detached. A best practice is to remove the listener using removeOnGlobalLayoutListener in the onDetachedFromWindow lifecycle method.

Thank you for your time and for maintaining this library.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions