Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions sdk/src/main/java/com/mapbox/maps/MapboxMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class MapboxMap internal constructor(
internal var isStyleLoadInitiated = false
private val styleObserver = StyleObserver(this, nativeMapWeakRef, nativeObserver, pixelRatio)
internal var renderHandler: Handler? = null
internal var styleLoaded = false
Copy link
Contributor

@alexander-kulikovskii alexander-kulikovskii Sep 15, 2021

Choose a reason for hiding this comment

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

should it be with private setter?
because in Java internal converted into public

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need set it in test cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use annotation VisibleForTesting ?


/**
* Represents current camera state.
Expand Down Expand Up @@ -209,8 +210,15 @@ class MapboxMap internal constructor(
onMapLoadErrorListener: OnMapLoadErrorListener? = null
) {
// clear listeners from previous invocation
styleObserver.onNewStyleLoad(onStyleLoaded, onMapLoadErrorListener)
styleObserver.onNewStyleLoad(
{
styleLoaded = true
onStyleLoaded?.onStyleLoaded(it)
},
onMapLoadErrorListener
)
isStyleLoadInitiated = true
styleLoaded = false
}

/**
Expand All @@ -220,7 +228,7 @@ class MapboxMap internal constructor(
*/
fun getStyle(onStyleLoaded: Style.OnStyleLoaded) {
if (::style.isInitialized) {
if (style.isStyleLoaded) {
if (styleLoaded) {
// style has loaded, notify callback immediately
onStyleLoaded.onStyleLoaded(style)
} else {
Expand All @@ -237,7 +245,7 @@ class MapboxMap internal constructor(
* Get the Style of the map synchronously, will return null is style is not loaded yet.
*/
fun getStyle(): Style? {
if (::style.isInitialized && style.isStyleLoaded) {
if (::style.isInitialized && styleLoaded) {
// style has loaded, return it immediately
return style
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/test/java/com/mapbox/maps/MapboxMapTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class MapboxMapTest {
fun getStyleLoadedCallback() {
val style = mockk<Style>()
mapboxMap.style = style
every { style.isStyleLoaded } returns true
mapboxMap.styleLoaded = true
val styleLoadCallback = mockk<Style.OnStyleLoaded>(relaxed = true)
mapboxMap.getStyle(styleLoadCallback)
verify { styleLoadCallback.onStyleLoaded(style) }
Expand All @@ -198,15 +198,15 @@ class MapboxMapTest {
fun getStyleSynchronously() {
val style = mockk<Style>()
mapboxMap.style = style
every { style.isStyleLoaded } returns true
mapboxMap.styleLoaded = true
assertNotNull(mapboxMap.getStyle())
}

@Test
fun getStyleSynchronouslyNull() {
val style = mockk<Style>()
mapboxMap.style = style
every { style.isStyleLoaded } returns false
mapboxMap.styleLoaded = false
assertNull(mapboxMap.getStyle())
}

Expand Down