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 app crash when switching theme #367

Merged
merged 2 commits into from
May 31, 2024

Conversation

octogradiste
Copy link
Contributor

The problem was that we kept the same instance of the mapView across configuration changes. Therefore, when switching the theme, the mapView already had a parent view which causes an IllegalStateException. To fix this, I recreate the mapView at every configuration change. This has the side effect of re-centering the map at every configuration change. To avoid this, I save the camera position every time it moves, so I can restore the previous camera position when the map is recreated. Closes #333.

@octogradiste octogradiste added the bug Something isn't working label May 30, 2024
@octogradiste octogradiste self-assigned this May 30, 2024
@octogradiste octogradiste marked this pull request as ready for review May 30, 2024 07:46
@octogradiste octogradiste force-pushed the fix/app-crash-when-switching-theme branch 2 times, most recently from 6af116d to 11a4f46 Compare May 31, 2024 10:37
Copy link
Contributor

@alejandrocalles alejandrocalles left a comment

Choose a reason for hiding this comment

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

Amazing, thanks for fixing this! Good job on finding the source of the issue :)

I've made a small request for change, but other than that the code looks really clean.

One thing we could consider, in the future, is a way to only re-create the map on configuration changes, as it seems mildly inefficient to re-create the map every time we navigate to it (or every time we switch from list mode to map mode).
However, for the moment, the app seems to be running as smoothly as before, so it may not even be an issue.

@violoncelloCH violoncelloCH added this to the Milestone 4 milestone May 31, 2024
The problem was that we kept the same instance of the `mapView` across configuration changes. Therefore, when switching the theme, the `mapView` already had a parent view which causes an `IllegalStateException`. To fix this, I recreate the `mapView` at every configuration change. This has the side effect of re-centering the map at every configuration change. To avoid this, I save the camera position every time it moves, so I can restore the previous camera position when the map is recreated.
@octogradiste octogradiste force-pushed the fix/app-crash-when-switching-theme branch from 11a4f46 to 44bd437 Compare May 31, 2024 20:45
Copy link

@alejandrocalles
Copy link
Contributor

LGTM. Thanks :)

@alejandrocalles alejandrocalles merged commit 28b72b0 into main May 31, 2024
2 checks passed
@alejandrocalles alejandrocalles deleted the fix/app-crash-when-switching-theme branch May 31, 2024 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App crashes when switching the color scheme
3 participants