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

Fixes Crash On Double Click Of Space FABs #7102

Merged
merged 3 commits into from
Sep 14, 2022

Conversation

ericdecanini
Copy link
Contributor

@ericdecanini ericdecanini commented Sep 12, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Fixes Crash On Double Click Of Space FABs

Motivation and context

Fixes #7087

Screenshots / GIFs

N/A

Tests

Double quick really quickly on the space list or new chat FABs in the new layout. These would have previously crashed the app.

Tested devices

  • Physical
  • Emulator
  • OS version(s): Android 12

Checklist

@ericdecanini ericdecanini marked this pull request as ready for review September 12, 2022 16:29
Copy link
Contributor

@fedrunov fedrunov left a comment

Choose a reason for hiding this comment

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

LGTM

// Click action for open spaces modal goes here
spaceListBottomSheet.show(requireActivity().supportFragmentManager, SpaceListBottomSheet.TAG)
views.newLayoutOpenSpacesButton.debouncedClicks {
spaceListBottomSheet.takeIf { !it.isAdded }?.show(requireActivity().supportFragmentManager, SpaceListBottomSheet.TAG)
Copy link
Member

Choose a reason for hiding this comment

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

I think the root cause of the issue is to instantiate the BottomSheets in advance at this point. I would have fixed this issue differently. Using debouncedClicks is OK, but using takeIf { !it.isAdded } looks a bit like a workaround.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Also there is no need to inject the constructor here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the approach you're leading towards is to instantiate the bottom sheet as we show it? (SpaceListBottomSheet.show())

I considered this approach but doing so would just reduce the bug from a crash to having two bottom sheets show together. debouncedClicks may help with this, but I wanted to add the !it.isAdded check as a guaranteed method.

Research also shows me that making this check (or using bottomSheet.isShowing in other cases) is a common practice.

Copy link
Member

Choose a reason for hiding this comment

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

OK, thanks for cleaning the constructor.

Copy link
Member

Choose a reason for hiding this comment

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

One more point:
When spaceListBottomSheet is displayed, if the user rotates it's device, the Fragment SpaceListBottomSheet will be restored by the System (the BottomSheet will still be visible), but NewHomeDetailFragment will not have a correct reference to this Fragment, since it will just instantiate a new instance in the constructor.

So this code:
https://github.com/vector-im/element-android/blob/develop/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt#L197

will not work (I did not check though).

You should try to get the reference (by tag for instance) to the restored bottom sheet Fragment instead of creating a new one.

@ericdecanini ericdecanini requested a review from bmarty September 13, 2022 20:34
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@bmarty bmarty merged commit 8dbfafb into develop Sep 14, 2022
@bmarty bmarty deleted the feature/eric/double-space-click-fix branch September 14, 2022 08:15
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.

Quickly double clicking the space button always crashes the app
3 participants