fix(Android): crash on tab change with open form sheet #2416
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.
Description
This PR fixes android crash when changing tab with
formSheet
opened.The fix is achieved by not triggering
dismissSelf()
in theON_STOP
lifecycle event, which was intended to run with native events, such as pulling the sheet down, but was also triggered by this particular case - causing theFragmentManager is already executing transactions
ERROR.To ensure the dismissal is correctly triggered by the native events, a
NativeDismissalObserver
was created and is triggered byBottomSheetBehavior.STATE_HIDDEN
state change.After applying the fix another problem appeared: upon re-visiting a tab with
formSheet
opened it's background turned transparent.During the first
attachShapeToScreen
screensbackground
property is replaced withshape
of typeMaterialShapeDrawable
. Thus on each subsequent call the(screen.background as? ColorDrawable?)?.color
property is unreachable as it's notColorDrawable
anymore. It's fixed by looking for(screen.background as? MaterialShapeDrawable?)?.tintList?.defaultColor
fallback.Fixes #2379 .
Changes
Test2379
reproTest code and steps to reproduce
Test2379
reproChecklist