Call plugin onStart after start loading style#680
Conversation
| mapboxMap.loadStyleUri(it) | ||
| } | ||
| } | ||
| pluginRegistry.onStart() |
There was a problem hiding this comment.
On internal convo, you mentioned:
What if we will change here:
pluginRegistry.onStart()
if (!mapboxMap.isStyleLoadInitiated) {
// Load the style in mapInitOptions if no style has loaded yet.
mapInitOptions.styleUri?.let {
mapboxMap.loadStyleUri(it)
}
}
to do like this:
if (!mapboxMap.isStyleLoadInitiated) {
// Load the style in mapInitOptions if no style has loaded yet.
mapInitOptions.styleUri?.let {
mapboxMap.loadStyleUri(it)
pluginRegistry.onStart()
}
}
Proposed change here is actually not part of the style loading callback?
There was a problem hiding this comment.
I think we should call onStart inside the Activity's onStart event, regardless of the style loading status.
and I remember we do have a onStyleChanged listener, we could hook to this listener inside the plugin if the style is need for certain action, wdyt?
There was a problem hiding this comment.
There was no callback, I assume it is loading synchronously. If style is null plugins wouldn’t work.
There was a problem hiding this comment.
@pengdev you are right, this onStart is initially called from Activity/Fragment and implementation is inside MapController, It is entry point.
There was a problem hiding this comment.
Proposed change here is actually not part of the style loading callback?
@tobrun I think the point of this change is that the new style load will clear the style load listeners that previous getStyle() { style -> } sets.
In some plugins we rely on the async getStyle() call to do the initialisation in the plugin's onStart(). And when the new style is loaded after the plugin's onStart, it will result in the plugins' getStyle() callback never being fired.
This fix intentionally moved the pluginRegistry.onStart() after the loadStyleUri call, so that we made sure the styleLoaded listener set by plugins' getStyle() is not cleared.
2fca8bc to
e13103d
Compare
| every { mockNativeObserver.removeOnCameraChangeListener(any()) } just Runs | ||
| every { mockNativeObserver.removeOnStyleDataLoadedListener(any()) } just Runs | ||
|
|
||
| testMapController.simulateStartedState() |
There was a problem hiding this comment.
can we use onStart directly instead of using simulateStartState?
There was a problem hiding this comment.
+1 for that and remove simulateStartState at all. imho there's no possibility in reality to set lifecycleState = LifecycleState.STATE_STARTED and not call onStart at the same time
There was a problem hiding this comment.
I disagree with relaxed, I'm trying to follow Arrange-Action-Assert pattern to write a good tests.
There was a problem hiding this comment.
I disagree with relaxed, I'm trying to follow Arrange-Action-Assert pattern to write a good tests.
Is this comment related to #680 (comment) actually?
| every { mockPluginRegistry.onStart() } just Runs | ||
| every { mockMapboxMap.loadStyleUri(Style.MAPBOX_STREETS) } just Runs | ||
| every { mockNativeObserver.addOnCameraChangeListener(any()) } just Runs | ||
| every { mockNativeObserver.addOnStyleDataLoadedListener(any()) } just Runs | ||
| every { mockRenderer.onStart() } just Runs |
There was a problem hiding this comment.
nit: we can use relaxed mockk to avoid adding every for these functions.
e13103d to
a50b2f9
Compare
PRs must be submitted under the terms of our Contributor License Agreement CLA.
Fixes: < Link to related issues that will be fixed by this pull request, if they exist >
Pull request checklist:
mapbox-maps-androidchangelog:<changelog>Fix initialisation location puck when no style loaded from code by changing Plugin#onStart() call after style loaded</changelog>.Summary of changes
In this PR has been changed order of methods called on lifecycle event onStart. Now plugins will receive onStart after style has been loaded. This reorder prevent of loosing callbacks from StyleObserver when callback were added before style starts loading.
User impact (optional)
User with styleUri attribute in XML will have all plugins started correctly after style has been loaded. Before in this case it was the issue reported here: #641