Skip to content

Commit b825df3

Browse files
lyydikoigithub-actions[bot]
authored andcommitted
Map view enabled settings fix (#7683)
[Jira ticket ](https://mapbox.atlassian.net/browse/MAPSAND-2223): Align behaviour between `mapView.<plugin>.enabled = false` and `mapView.<plugin>.updateSettings { enabled = false }` ### Fix: Camera listener not unsubscribed when disabling ScaleBar via updateSettings **Problem** Calling `mapView.scalebar.updateSettings { enabled = false } ` didn't unsubscribe the camera listener, causing unnecessary updates and potential performance issues. Root cause: `updateSettings()` bypassed the **enabled** property setter, which contains the listener management logic in `ScaleBarPluginImpl.` **Solution** Updated the code generator template to route through the enabled property setter: ``` override fun updateSettings(block: ScaleBarSettings.Builder.() -> Unit) { val newSettings = this.internalSettings.toBuilder().apply(block).build() this.enabled = newSettings.enabled // ✅ Triggers listener management this.internalSettings = newSettings applySettings() } ``` **Changes** 1. Template: Updated `config_abstract_class.kt.ejs` to call `this.enabled = newSettings.enabled` when enabled property exists 2. Generated code: Regenerated all plugin settings (ScaleBar, Compass, Logo, Attribution, LocationComponent) 3. Tests: Added 5 tests verifying listener subscription/cancellation behavior cc @mapbox/maps-android cc @mapbox/sdk-ci GitOrigin-RevId: d155fc4b27df3b372c11ab97542f5a7491baacd4
1 parent 16a19b3 commit b825df3

File tree

8 files changed

+58
-7
lines changed

8 files changed

+58
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ Mapbox welcomes participation and contributions from everyone.
66
77
# main
88

9+
# 11.17.0-rc.1
10+
## Features ✨ and improvements 🏁
911
* Promote `ModelLayer` to stable.
1012
* Add `SymbolLayer.occlusionOpacityMode`, `SymbolLayer.iconColorBrightnessMax`, `SymbolLayer.iconColorBrightnessMin`, `SymbolLayer.iconColorContrast` properties.
1113
* Add `FillExtrusionLayer.castShadows` property.
1214
* Add `GeoJsonSource.minZoom` property.
1315
* Add `RasterArraySource.volatile` experimental property.
1416

17+
## Bug fixes 🐞
18+
* Fix camera listener not unsubscribed when disabling ScaleBar via `updateSettings { enabled = false }`
1519

1620
# 11.17.0-beta.1 November 05, 2025
1721
## Breaking changes ⚠️
@@ -56,7 +60,6 @@ Mapbox welcomes participation and contributions from everyone.
5660
## Dependencies
5761
* Update gl-native to [v11.16.1](https://github.com/mapbox/mapbox-maps-android/releases/tag/v11.16.1), common to [v24.16.1](https://github.com/mapbox/mapbox-maps-android/releases/tag/v11.16.1).
5862

59-
6063
# 11.16.0 October 21, 2025
6164
## Bug fixes 🐞
6265
* Fix location request leak when setting custom location provider after updating settings

plugin-scalebar/src/test/java/com/mapbox/maps/plugin/scalebar/ScaleBarPluginTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.res.TypedArray
55
import android.graphics.Color
66
import android.graphics.drawable.Drawable
77
import android.widget.FrameLayout
8+
import com.mapbox.common.Cancelable
89
import com.mapbox.maps.MapOptions
910
import com.mapbox.maps.Projection
1011
import com.mapbox.maps.plugin.delegates.MapCameraManagerDelegate
@@ -40,6 +41,7 @@ class ScaleBarPluginTest {
4041
private val context: Context = mockk(relaxed = true)
4142
private val typedArray: TypedArray = mockk(relaxUnitFun = true)
4243
private val drawable = mockk<Drawable>(relaxed = true)
44+
private val cancelable = mockk<Cancelable>(relaxUnitFun = true)
4345

4446
@Before
4547
fun setUp() {
@@ -63,6 +65,7 @@ class ScaleBarPluginTest {
6365
every { typedArray.getDrawable(any()) } returns drawable
6466
every { typedArray.hasValue(any()) } returns true
6567
every { scaleBarView.pixelRatio } returns 1.5f
68+
every { mapListenerManagerDelegate.subscribeCameraChangedCoalesced(any()) } returns cancelable
6669

6770
scaleBarPlugin = ScaleBarPluginImpl { scaleBarView }
6871
scaleBarPlugin.onDelegateProvider(delegateProvider)
@@ -85,12 +88,14 @@ class ScaleBarPluginTest {
8588
fun setEnabled_true() {
8689
scaleBarPlugin.enabled = true
8790
assertEquals(true, scaleBarPlugin.getSettings().enabled)
91+
verify(atLeast = 1) { mapListenerManagerDelegate.subscribeCameraChangedCoalesced(any()) }
8892
}
8993

9094
@Test
9195
fun setEnabled_false() {
9296
scaleBarPlugin.enabled = false
9397
assertEquals(false, scaleBarPlugin.getSettings().enabled)
98+
verify { cancelable.cancel() }
9499
}
95100

96101
@Test
@@ -113,4 +118,31 @@ class ScaleBarPluginTest {
113118
verify { scaleBarPlugin.useContinuousRendering = true }
114119
verify { scaleBarView.useContinuousRendering = true }
115120
}
121+
122+
@Test
123+
fun updateSettings_disable() {
124+
assertEquals(true, scaleBarPlugin.getSettings().enabled)
125+
scaleBarPlugin.updateSettings { enabled = false }
126+
verify { cancelable.cancel() }
127+
verify { scaleBarView.enable = false }
128+
assertEquals(false, scaleBarPlugin.getSettings().enabled)
129+
}
130+
131+
@Test
132+
fun updateSettings_enable() {
133+
scaleBarPlugin.enabled = false
134+
scaleBarPlugin.updateSettings { enabled = true }
135+
verify(atLeast = 2) { mapListenerManagerDelegate.subscribeCameraChangedCoalesced(any()) }
136+
verify { scaleBarView.enable = true }
137+
assertEquals(true, scaleBarPlugin.getSettings().enabled)
138+
}
139+
140+
@Test
141+
fun updateSettings_enableUnchanged() {
142+
assertEquals(true, scaleBarPlugin.getSettings().enabled)
143+
scaleBarPlugin.updateSettings { marginLeft = 20f }
144+
// listener remains active (only subscribed once during initialize)
145+
verify(exactly = 1) { mapListenerManagerDelegate.subscribeCameraChangedCoalesced(any()) }
146+
assertEquals(true, scaleBarPlugin.getSettings().enabled)
147+
}
116148
}

sdk-base/src/main/java/com/mapbox/maps/plugin/attribution/generated/AttributionSettingsBase.kt

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk-base/src/main/java/com/mapbox/maps/plugin/compass/generated/CompassSettingsBase.kt

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk-base/src/main/java/com/mapbox/maps/plugin/gestures/generated/GesturesSettingsBase.kt

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk-base/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentSettingsBase.kt

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk-base/src/main/java/com/mapbox/maps/plugin/logo/generated/LogoSettingsBase.kt

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk-base/src/main/java/com/mapbox/maps/plugin/scalebar/generated/ScaleBarSettingsBase.kt

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)