-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
6af116d
to
11a4f46
Compare
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.
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.
app/src/main/java/com/github/swent/echo/compose/map/MapLibreMapViewProvider.kt
Outdated
Show resolved
Hide resolved
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.
11a4f46
to
44bd437
Compare
|
LGTM. Thanks :) |
The problem was that we kept the same instance of the
mapView
across configuration changes. Therefore, when switching the theme, themapView
already had a parent view which causes anIllegalStateException
. To fix this, I recreate themapView
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.