Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Swift Concurrency Support for PaymentMethodMessagingView #4448

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

esreli
Copy link

@esreli esreli commented Jan 8, 2025

See relevant issue: #4447

Summary

This PR refactors the initialization flow of PaymentMethodMessagingView to use Swift concurrency (async/await) rather than relying on a completion callback. It also introduces cancellation checks to ensure that any ongoing tasks are correctly canceled before initiating new work (such as when trait collection changes in rapid succession).

Motivation

  • Async/Await Simplification: By switching from completion closures to async/await, the code becomes more readable and makes better use of Swift concurrency’s structured approach.
  • Cancellation Safety: In traitCollectionDidChange, quickly toggling between appearance modes (e.g., Light/Dark) can trigger multiple UI updates and server fetches in quick succession. Introducing a shared Task reference that is canceled before starting a new one ensures we don’t perform redundant or conflicting work.
  • Maintain UI Accuracy: Canceling outdated tasks prevents older (stale) data from overwriting the latest UI changes.

Testing

Happy to test. I did not see any relevant tests in the sibling test module.

Changelog

  • [Changed] PaymentMethodMessagingView.create(configuration:) to use an async initializer.
  • [Changed] Updated traitCollectionDidChange(_:) to cancel and restart any in-flight tasks, ensuring stale work isn’t applied after a trait change.

Copy link

cla-assistant bot commented Jan 8, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

cla-assistant bot commented Jan 8, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant