-
Notifications
You must be signed in to change notification settings - Fork 661
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
Conversation
There was a problem hiding this 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?
viewLifecycleOwner.lifecycleScope.launch { | ||
formViewModel.completeFormValues.collect { formFieldValues -> | ||
sheetViewModel.updateSelection( | ||
transformToPaymentSelection( | ||
formFieldValues, | ||
formFragment.paramKeySpec, | ||
selectedPaymentMethod | ||
) | ||
} | ||
) |
There was a problem hiding this comment.
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
paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetActivity.kt
Outdated
Show resolved
Hide resolved
paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt
Outdated
Show resolved
Hide resolved
…ncel authenticate, Add new card
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( |
There was a problem hiding this comment.
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.
paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsViewModel.kt
Outdated
Show resolved
Hide resolved
paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsActivity.kt
Outdated
Show resolved
Hide resolved
paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsViewModel.kt
Outdated
Show resolved
Hide resolved
paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetActivity.kt
Outdated
Show resolved
Hide resolved
paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetViewModel.kt
Outdated
Show resolved
Hide resolved
...ain/java/com/stripe/android/paymentsheet/paymentdatacollection/CardDataCollectionFragment.kt
Show resolved
Hide resolved
...est/java/com/stripe/android/googlepaylauncher/GooglePayPaymentMethodLauncherViewModelTest.kt
Show resolved
Hide resolved
…er/GooglePayPaymentMethodLauncherViewModelTest.kt
…-android into michelleb/dka-add-fragment
…mentSheetActivity.kt Co-authored-by: Bruno R. Nunes <77990083+brnunes-stripe@users.noreply.github.com>
…mentSheetActivity.kt Co-authored-by: Bruno R. Nunes <77990083+brnunes-stripe@users.noreply.github.com>
…-android into michelleb/dka-add-fragment
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):
Waiting on reproduction of: Returning customer, PI, USD:
Not reproduced on master
Motivation
#4457
MOBILESDK 252
I think this addresses MOBILESDK 367
No longer reproduce: MOBILESDK 210 with nav bar disappearing.
Testing
Screenshots