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

Fix don't keep activities on add fragment. #4466

Merged
merged 39 commits into from
Feb 8, 2022

Conversation

michelleb-stripe
Copy link
Contributor

@michelleb-stripe michelleb-stripe commented Dec 13, 2021

Please review, but let's wait until after internal dogfood before releasing.

Summary

When don't keep activities is turned on we need to properly restore the state in the BaseAddFragment.

When a viewModel has a savedStateHandle onCreate must complete. This means no factories can be used.
Values in the viewModel are saved in the SavedStateHandle so they are restored.
When don't keep activities is turned on, when activities are re-created the previous fragment is restored, so we should not replace this fragment.

There are still a few outstanding issues to be addressed in a follow up PR (see MOBILESDK-252):

  • Error messages are not kept on restore
  • The compose fields are not restored
  • Custom flow does not save and return the callback to update the icon

Waiting on reproduction of: Returning customer, PI, USD:

  • User has saved PMs, choose +Add
  • Select Klarna, enter email, tap Pay
    • Also happens with Afterpay, doesn't with card 3063
  • Cancel, with the top left (both probably work)
  • Go back to saved PMs (Michelle had to select a different PM)
  • Choose +Add, it shows Klarna form field, seems to be in the processing state (close is disabled, edit fields are disabled)
  • Can't interact with Payment Sheet

Not reproduced on master

Motivation

#4457
MOBILESDK 252
I think this addresses MOBILESDK 367
No longer reproduce: MOBILESDK 210 with nav bar disappearing.

Testing

  • Added tests
  • Modified tests
  • Manually verified

Screenshots

Before After
before screenshot after screenshot

@michelleb-stripe michelleb-stripe changed the title Michelleb/dka add fragment Fix don't keep activities on add fragment. Dec 13, 2021
@michelleb-stripe michelleb-stripe self-assigned this Dec 13, 2021
Copy link
Contributor

@brnunes-stripe brnunes-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have tests for this situation?

Comment on lines 126 to 134
viewLifecycleOwner.lifecycleScope.launch {
formViewModel.completeFormValues.collect { formFieldValues ->
sheetViewModel.updateSelection(
transformToPaymentSelection(
formFieldValues,
formFragment.paramKeySpec,
selectedPaymentMethod
)
}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this change, but what we're doing here can be achieved with launchIn: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/launch-in.html

override fun onCreate(savedInstanceState: Bundle?) {
// When the fragment is destroyed and recreated, the child fragment is re-instantiated
// during onCreate, so the factory must be set before calling super.
childFragmentManager.fragmentFactory = AddPaymentMethodsFragmentFactory(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have to re-create the fragment, then the viewModel will be created, but the SavedStateHandle can not be observed until after create is complete.

skyler-stripe
skyler-stripe previously approved these changes Feb 7, 2022
…mentSheetActivity.kt

Co-authored-by: Bruno R. Nunes <77990083+brnunes-stripe@users.noreply.github.com>
michelleb-stripe and others added 3 commits February 8, 2022 04:41
…mentSheetActivity.kt

Co-authored-by: Bruno R. Nunes <77990083+brnunes-stripe@users.noreply.github.com>
@michelleb-stripe michelleb-stripe merged commit 34a4975 into master Feb 8, 2022
@michelleb-stripe michelleb-stripe deleted the michelleb/dka-add-fragment branch February 8, 2022 17:04
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.

4 participants