[Kotlin]: Prevent stacked sheet presentations - #600
Draft
kieran-osgood-shopify wants to merge 1 commit into
Draft
Conversation
### TLDR `present` built a new `CheckoutBottomSheet` on every call, so N taps on a checkout button stacked N dialog windows. A device capture showed 73 `present` calls producing 73 sheets, two of them only 153 ms apart. ### What `ShopifyCheckoutKit` now tracks the live presentation. A second `present` for the same activity logs a warning and returns the existing `CheckoutHandle` instead of building another sheet. A stored sheet that is no longer showing counts as stale, so the next `present` proceeds normally. `CheckoutBottomSheet` gains an internal `onDismissFinalized` callback, invoked in `finishDismiss` above the `isShowing` guard, so every dismissal path clears the slot: buyer dismissal, gesture dismissal, programmatic `dismiss`, lifecycle teardown, and `closeCheckoutWithError`. That callback also removes the per-presentation `DefaultLifecycleObserver`. Before this change the observer was removed only when `start()` failed, so each successful presentation leaked one observer holding a dead sheet. No public API change. Both new members are private, or internal on an internal class, so `lib/api/lib.api` does not move. ### How to test Add an item to the cart in the Kotlin sample, then tap Checkout many times quickly. | | Before | After | | --- | --- | --- | | Sheets shown per burst | 5 | 1 | | Leaked sheet windows after closing | 4 | 0 | Leaked sheet windows are `androiddemo` entries in `dumpsys window windows` with `ty=APPLICATION gr=BOTTOM`. Before this change two surfaceless sheet windows survived every close, and one of them still held `mCurrentFocus`. The app then drew nothing, without crashing. `ShopifyCheckoutKitTest.kt` covers the refusal, the returned handle identity, presenting again after a dismissal, and the observer count returning to its starting value.
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Aug 6, 2026
kiftio
reviewed
Aug 7, 2026
| private val activity: ComponentActivity, | ||
| val handle: CheckoutHandle, | ||
| ) { | ||
| fun isShowingFor(context: ComponentActivity): Boolean = activity === context && sheet.isShowing |
Contributor
There was a problem hiding this comment.
Wondering here if the activity === context `check is needed?
Could we still stack if presenting from a separate activity? Is that problematic?
fun isShowing(): Boolean = sheet.isShowingor directly without the function
val alreadyPresented = livePresentation?.takeIf { it.sheet.isShowing }Maybe with docs to say only one checkout can be presented per SDK process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What changes are you making?
spamming the checkout button can open multiple checkouts at once
Screen Recording 2026-08-06 at 12.14.21.mov (uploaded via Graphite)
How to test
spam the button and only 1 checkout will open, the getting stuck height is fixed up stack in 601
Before you merge
Important
platforms/swift/README.mdand/orplatforms/android/README.md)Releasing a new Swift version?
ShopifyCheckoutKit.podspecplatforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swiftplatforms/swift/README.md(major version only)Releasing a new Embedded Checkout Protocol version?
embeddedCheckoutProtocolAndroidinplatforms/android/gradle/libs.versions.tomlprotocol/languages/kotlin/embedded-checkout-protocol/api/embedded-checkout-protocol.apiif the public API changedReleasing a new Android version?
checkoutKitAndroidinplatforms/android/gradle/libs.versions.tomlplatforms/android/README.mdTip
See the Contributing documentation for the full release process per platform.