Shopify / checkout-sheet-kit-android

Shopify’s Checkout Sheet Kit makes it simple to perform a checkout inside your Android app.
MIT License
10 stars 1 forks source link

Ensure no existing parent is present before adding to container #128

Open kiftio opened 5 days ago

kiftio commented 5 days ago

What changes are you making?

CLOSES https://github.com/Shopify/checkout-sheet-kit-android/issues/127

When preloading is enabled and we fetch the checkout web view from the cache, there are some scenarios where we try to add the fetched view to a parent container when it already has a parent (causing an IllegalStateException).

This can be reproduced by enabling preloading, then calling present() twice without dismissing the modal (there also may be other cases).

This PR looks to ensure the webView has no existing parent before we add it to its container.

Note: When we remove webViews from its container, we look to ensure it's destroyed if will not be used again, to avoid memory leaks. We don't want to do that in this case, as the view will be added to the view hierachy shortly after removing the existing parent.

How to test

Add the following below ShopifyCheckoutSheetKit.present(url, activity, eventProcessor) in the MobileBuyIntegration samples CartViewModel to trigger a delayed second present call.

Handler(Looper.getMainLooper()).postDelayed({
     ShopifyCheckoutSheetKit.present(url, activity, eventProcessor)
}, 500)

Repeat on main and on this branch.

Before you merge

[!IMPORTANT]


Checklist for releasing a new version - [x] I have bumped the version number in the [`build.gradle` file](https://github.com/Shopify/checkout-kit-android/blob/main/lib/build.gradle#L17) - [x] I have added a [Changelog](https://github.com/shopify/checkout-sheet-kit-android/blob/main/CHANGELOG.md) entry. - [x] I have updated the versions in the [README.md](https://github.com/shopify/checkout-sheet-kit-android/blob/main/README.md) for both Gradle and Maven.

[!TIP] See the Contributing documentation for instructions on how to publish a new version of the library.