-
Notifications
You must be signed in to change notification settings - Fork 131
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
Split callbacks originating on getStyle and loadStyle requests. #1114
Conversation
Tests coming |
internal var isStyleLoadInitiated = false | ||
private val styleObserver = StyleObserver(this, nativeObserver, pixelRatio) | ||
private val styleObserver = StyleObserver( |
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.
Removed this
param from StyleObserver, using reference to the object not yet constructed fully could lead to subtle bugs. Instead only passed lambda that inits style directly.
@yunikkk label and changelog entry are missing, can you add those so CI will pass? |
@@ -102,9 +106,9 @@ class MapboxMap internal constructor( | |||
) { | |||
initializeStyleLoad(onStyleLoaded, onMapLoadErrorListener) | |||
if (styleUri.isEmpty()) { | |||
nativeMapWeakRef.call { (this as StyleManagerInterface).styleJSON = EMPTY_STYLE_JSON } | |||
nativeMapWeakRef.call { styleJSON = EMPTY_STYLE_JSON } |
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.
Recommend to use this
keyword to limit the scope of the function to be within nativeMap, so that not to be confused with property/functions with the same name in the MapboxMap
class. It used to cause trouble since we have the exact same functions both inside the NativeMap
and MapboxMap
.
nativeMapWeakRef.call { styleJSON = EMPTY_STYLE_JSON } | |
nativeMapWeakRef.call { this.styleJSON = EMPTY_STYLE_JSON } |
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.
Could you explain a bit more? this.
is implied anyway,
nativeMapWeakRef.call { someProperty ->
should be always the same as
nativeMapWeakRef.call { this.someProperty
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.
we have had some occurrences where it was calling the function on the outer class versus on the native map. Not much of an issue here though
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.
Ah, got it, it seems.
IMO for such situations when this.
context might be confused and outer class may hold similar or same method - better to use explicit named references with let e.g. let { inner -> inner.smth }
instead of apply or similar that changes this.
fac22c6
to
05fff7e
Compare
@@ -102,9 +106,9 @@ class MapboxMap internal constructor( | |||
) { | |||
initializeStyleLoad(onStyleLoaded, onMapLoadErrorListener) | |||
if (styleUri.isEmpty()) { | |||
nativeMapWeakRef.call { (this as StyleManagerInterface).styleJSON = EMPTY_STYLE_JSON } | |||
nativeMapWeakRef.call { styleJSON = EMPTY_STYLE_JSON } |
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.
we have had some occurrences where it was calling the function on the outer class versus on the native map. Not much of an issue here though
531808f
to
f7443cd
Compare
f7443cd
to
660d052
Compare
Summary of changes
Problem this PR addresses : location puck is not displayed after style load #321, #1048.
Background context : at #300 the logic that clears
style loaded
callbacks added withmapboxMap.getStyle
/mapboxMap.loadStyle
was introduced.However, for the
getStyle
the behaviour doesn't feel right.getStyle
name doesn't suggest that it depends on the specificloadStyle
call, instead it would be natural to return ANY style whenever it is loaded.Existing
getStyle
implementation also leads to the issues (mentioned above) with our own LocationComponent. If location component was triggered before style load was started (possible ifMapInitOptions.styleUri = null
or style fails to load), it needs style and waits for it to appear atgetStyle
(in couple places, e.g. here and here. When new style is loaded afterwards - this callbacks of location component are being cleared so it's never initialized, if not triggered manually again after style loaded.I've changed behaviour of
mapboxMap.getStyle
callbacks, now they are not cleared anymore after theloadStyle
call, while callbacksloadStyle
retain current behaviour.User impact (optional)
Aside from fixing bugs with location puck - when user calls
mapboxMap.getStyle
they will receive style from the first style that is loaded successfully in future.Pull request checklist:
@JvmOverloads
,@file:JvmName
, etc).mapbox-maps-android
changelog:<changelog>Fix location component now shown in certain cases.</changelog>
.v10.[version]
release branch fix / enhancement, merge it tomain
firstly and then port tov10.[version]
release branch.Fixes: #321, #1048
PRs must be submitted under the terms of our Contributor License Agreement CLA.