Skip to content

Commit 2b58bef

Browse files
pengdevgithub-actions[bot]
authored andcommitted
[sdk-base][stylegen] Fix generate-ksp breaking ScaleBarSettings (#12556)
GitOrigin-RevId: 62f47fc25333441c1431265cd5fb64f963e462f8
1 parent 1e97570 commit 2b58bef

19 files changed

Lines changed: 359 additions & 226 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Mapbox welcomes participation and contributions from everyone.
1010
* Expose `FeaturesetFeature.originalFeature` property.
1111

1212
## Bug fixes 🐞
13+
14+
* Fix `isMetricUnits`/`distanceUnits` sync in ScaleBar settings DSL generated by KSP codegen.
1315
* [gestures] Fixed interaction leak in `setGesturesManager` causing native map interactions to accumulate.
1416
* [gestures] Added post-cleanup guard to prevent re-registering interactions or listeners after plugin cleanup.
1517

extension-compose/api/Release/metalava.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,8 @@ package com.mapbox.maps.extension.compose.ornaments.logo {
12691269
package com.mapbox.maps.extension.compose.ornaments.scalebar {
12701270

12711271
@androidx.compose.runtime.Immutable @com.mapbox.maps.extension.compose.MapboxMapScopeMarker public final class MapScaleBarScope {
1272-
method @androidx.compose.runtime.Composable public void ScaleBar(androidx.compose.ui.Modifier modifier = Modifier, androidx.compose.foundation.layout.PaddingValues contentPadding = PaddingValues(4.dp), androidx.compose.ui.Alignment alignment = androidx.compose.ui.Alignment.Companion.TopStart, long textColor = Color.Black, long primaryColor = Color.Black, long secondaryColor = Color.White, float borderWidth = 2.dp, float height = 2.dp, float textBarMargin = 8.dp, float textBorderWidth = 2.dp, long textSize = 8.sp, boolean isMetricUnit = true, long refreshInterval = 15.milliseconds, boolean showTextBorder = true, float ratio = 0.5f, boolean useContinuousRendering = false);
1272+
method @Deprecated @androidx.compose.runtime.Composable public void ScaleBar(androidx.compose.ui.Modifier modifier = Modifier, androidx.compose.foundation.layout.PaddingValues contentPadding = PaddingValues(4.dp), androidx.compose.ui.Alignment alignment = androidx.compose.ui.Alignment.Companion.TopStart, long textColor = Color.Black, long primaryColor = Color.Black, long secondaryColor = Color.White, float borderWidth = 2.dp, float height = 2.dp, float textBarMargin = 8.dp, float textBorderWidth = 2.dp, long textSize = 8.sp, boolean isMetricUnit, long refreshInterval = 15.milliseconds, boolean showTextBorder = true, float ratio = 0.5f, boolean useContinuousRendering = false);
1273+
method @androidx.compose.runtime.Composable public void ScaleBar(androidx.compose.ui.Modifier modifier = Modifier, androidx.compose.foundation.layout.PaddingValues contentPadding = PaddingValues(4.dp), androidx.compose.ui.Alignment alignment = androidx.compose.ui.Alignment.Companion.TopStart, long textColor = Color.Black, long primaryColor = Color.Black, long secondaryColor = Color.White, float borderWidth = 2.dp, float height = 2.dp, float textBarMargin = 8.dp, float textBorderWidth = 2.dp, long textSize = 8.sp, com.mapbox.maps.plugin.DistanceUnits distanceUnits = LocaleUnitResolver.distanceUnits, long refreshInterval = 15.milliseconds, boolean showTextBorder = true, float ratio = 0.5f, boolean useContinuousRendering = false);
12731274
}
12741275

12751276
}

extension-compose/api/extension-compose.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ public final class com/mapbox/maps/extension/compose/ornaments/logo/MapLogoScope
10021002
}
10031003

10041004
public final class com/mapbox/maps/extension/compose/ornaments/scalebar/MapScaleBarScope {
1005+
public final fun ScaleBar-vLKV3eY (Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/ui/Alignment;JJJFFFFJLcom/mapbox/maps/plugin/DistanceUnits;JZFZLandroidx/compose/runtime/Composer;III)V
10051006
public final fun ScaleBar-vLKV3eY (Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/ui/Alignment;JJJFFFFJZJZFZLandroidx/compose/runtime/Composer;III)V
10061007
}
10071008

extension-compose/src/main/java/com/mapbox/maps/extension/compose/ornaments/scalebar/MapScaleBarScope.kt

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import androidx.compose.ui.viewinterop.AndroidView
2020
import com.mapbox.maps.MapView
2121
import com.mapbox.maps.extension.compose.MapboxMapScopeMarker
2222
import com.mapbox.maps.extension.compose.ornaments.scalebar.internal.ScaleBarComposePlugin
23+
import com.mapbox.maps.plugin.DistanceUnits
2324
import com.mapbox.maps.plugin.Plugin
25+
import com.mapbox.maps.plugin.scalebar.LocaleUnitResolver
2426
import com.mapbox.maps.plugin.scalebar.ScaleBarImpl
2527
import kotlin.time.Duration
2628
import kotlin.time.Duration.Companion.milliseconds
@@ -61,6 +63,10 @@ public class MapScaleBarScope internal constructor(
6163
* will redraw only on demand. Defaults to False and should not be changed explicitly in most cases.
6264
* Could be set to True to produce correct GPU frame metrics when running gfxinfo command.
6365
*/
66+
@Deprecated(
67+
message = "Use the overload with distanceUnits parameter instead.",
68+
replaceWith = ReplaceWith("ScaleBar(modifier, contentPadding, alignment, textColor, primaryColor, secondaryColor, borderWidth, height, textBarMargin, textBorderWidth, textSize, if (isMetricUnit) DistanceUnits.METRIC else DistanceUnits.IMPERIAL, refreshInterval, showTextBorder, ratio, useContinuousRendering)")
69+
)
6470
@Composable
6571
public fun ScaleBar(
6672
modifier: Modifier = Modifier,
@@ -74,7 +80,72 @@ public class MapScaleBarScope internal constructor(
7480
textBarMargin: Dp = 8.dp,
7581
textBorderWidth: Dp = 2.dp,
7682
textSize: TextUnit = 8.sp,
77-
isMetricUnit: Boolean = true,
83+
isMetricUnit: Boolean,
84+
refreshInterval: Duration = 15.milliseconds,
85+
showTextBorder: Boolean = true,
86+
ratio: Float = 0.5f,
87+
useContinuousRendering: Boolean = false,
88+
) {
89+
ScaleBar(
90+
modifier = modifier,
91+
contentPadding = contentPadding,
92+
alignment = alignment,
93+
textColor = textColor,
94+
primaryColor = primaryColor,
95+
secondaryColor = secondaryColor,
96+
borderWidth = borderWidth,
97+
height = height,
98+
textBarMargin = textBarMargin,
99+
textBorderWidth = textBorderWidth,
100+
textSize = textSize,
101+
distanceUnits = if (isMetricUnit) DistanceUnits.METRIC else DistanceUnits.IMPERIAL,
102+
refreshInterval = refreshInterval,
103+
showTextBorder = showTextBorder,
104+
ratio = ratio,
105+
useContinuousRendering = useContinuousRendering,
106+
)
107+
}
108+
109+
/**
110+
* Add a [ScaleBar] ornament to the map, the scale bar will update accordingly when the map's zoom
111+
* level or latitude changes.
112+
*
113+
* By default, the [ScaleBar] will be placed to the [Alignment.TopStart] of the map with padding of 4dp.
114+
*
115+
* @param modifier Modifier to be applied to the [ScaleBar].
116+
* @param contentPadding The default padding applied to the [ScaleBar], paddings from [modifier] will be applied on top of this default padding.
117+
* @param alignment The alignment of the [ScaleBar] within the Map.
118+
* @param textColor Defines text color of the scale bar.
119+
* @param primaryColor Defines primary color of the scale bar.
120+
* @param secondaryColor Defines secondary color of the scale bar.
121+
* @param borderWidth Defines width of the border for the scale bar.
122+
* @param height Defines height of the scale bar.
123+
* @param textBarMargin Defines margin of the text bar of the scale bar.
124+
* @param textBorderWidth Defines text border width of the scale bar.
125+
* @param textSize Defines text size of the scale bar.
126+
* @param distanceUnits The distance unit type for the scale bar. Defaults to the device locale (metric for most locales, imperial for US/LR/MM).
127+
* @param refreshInterval Configures minimum refresh interval, in millisecond, default is 15 milliseconds.
128+
* @param showTextBorder Configures whether to show the text border or not, default is true.
129+
* @param ratio Configures ratio of scale bar max width compared with MapView width, default is 0.5.
130+
* @param useContinuousRendering If set to True scale bar will be triggering onDraw depending on
131+
* [refreshInterval] even if actual data did not change. If set to False scale bar
132+
* will redraw only on demand. Defaults to False and should not be changed explicitly in most cases.
133+
* Could be set to True to produce correct GPU frame metrics when running gfxinfo command.
134+
*/
135+
@Composable
136+
public fun ScaleBar(
137+
modifier: Modifier = Modifier,
138+
contentPadding: PaddingValues = PaddingValues(4.dp),
139+
alignment: Alignment = Alignment.TopStart,
140+
textColor: Color = Color.Black,
141+
primaryColor: Color = Color.Black,
142+
secondaryColor: Color = Color.White,
143+
borderWidth: Dp = 2.dp,
144+
height: Dp = 2.dp,
145+
textBarMargin: Dp = 8.dp,
146+
textBorderWidth: Dp = 2.dp,
147+
textSize: TextUnit = 8.sp,
148+
distanceUnits: DistanceUnits = LocaleUnitResolver.distanceUnits,
78149
refreshInterval: Duration = 15.milliseconds,
79150
showTextBorder: Boolean = true,
80151
ratio: Float = 0.5f,
@@ -112,7 +183,7 @@ public class MapScaleBarScope internal constructor(
112183
.setTextBarMargin(textBarMargin.toPx())
113184
.setTextBorderWidth(textBorderWidth.toPx())
114185
.setTextSize(textSize.toPx())
115-
.setIsMetricUnits(isMetricUnit)
186+
.setDistanceUnits(distanceUnits)
116187
.setRefreshInterval(refreshInterval.toLong(DurationUnit.MILLISECONDS))
117188
.setShowTextBorder(showTextBorder)
118189
.setRatio(ratio)

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ compose = "1.3.2"
7575
composeBom = "2023.01.00"
7676
gradleVersionsPlugin = "0.42.0"
7777
ksp = "1.0.8"
78-
kotlinDataCompat = "0.8.0"
78+
kotlinDataCompat = "0.10.0"
7979

8080
toster = "0.3.2"
8181

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.widget.FrameLayout
88
import com.mapbox.common.Cancelable
99
import com.mapbox.maps.MapOptions
1010
import com.mapbox.maps.Projection
11+
import com.mapbox.maps.plugin.DistanceUnits
1112
import com.mapbox.maps.plugin.delegates.MapCameraManagerDelegate
1213
import com.mapbox.maps.plugin.delegates.MapDelegateProvider
1314
import com.mapbox.maps.plugin.delegates.MapListenerDelegate
@@ -145,4 +146,56 @@ class ScaleBarPluginTest {
145146
verify(exactly = 1) { mapListenerManagerDelegate.subscribeCameraChangedCoalesced(any()) }
146147
assertEquals(true, scaleBarPlugin.getSettings().enabled)
147148
}
149+
150+
@Suppress("DEPRECATION")
151+
@Test
152+
fun setIsMetricUnits_syncsDistanceUnits() {
153+
scaleBarPlugin.isMetricUnits = false
154+
assertEquals(DistanceUnits.IMPERIAL, scaleBarPlugin.distanceUnits)
155+
156+
scaleBarPlugin.isMetricUnits = true
157+
assertEquals(DistanceUnits.METRIC, scaleBarPlugin.distanceUnits)
158+
}
159+
160+
@Suppress("DEPRECATION")
161+
@Test
162+
fun setDistanceUnits_syncsIsMetricUnits() {
163+
scaleBarPlugin.distanceUnits = DistanceUnits.IMPERIAL
164+
assertEquals(false, scaleBarPlugin.isMetricUnits)
165+
166+
scaleBarPlugin.distanceUnits = DistanceUnits.METRIC
167+
assertEquals(true, scaleBarPlugin.isMetricUnits)
168+
169+
scaleBarPlugin.distanceUnits = DistanceUnits.NAUTICAL
170+
assertEquals(false, scaleBarPlugin.isMetricUnits)
171+
}
172+
173+
@Suppress("DEPRECATION")
174+
@Test
175+
fun updateSettings_isMetricUnits_syncsDistanceUnits() {
176+
scaleBarPlugin.updateSettings { isMetricUnits = false }
177+
assertEquals(DistanceUnits.IMPERIAL, scaleBarPlugin.getSettings().distanceUnits)
178+
179+
scaleBarPlugin.updateSettings { isMetricUnits = true }
180+
assertEquals(DistanceUnits.METRIC, scaleBarPlugin.getSettings().distanceUnits)
181+
}
182+
183+
@Test
184+
fun updateSettings_distanceUnits_syncsIsMetricUnits() {
185+
scaleBarPlugin.updateSettings { distanceUnits = DistanceUnits.NAUTICAL }
186+
@Suppress("DEPRECATION")
187+
assertEquals(false, scaleBarPlugin.getSettings().isMetricUnits)
188+
assertEquals(DistanceUnits.NAUTICAL, scaleBarPlugin.getSettings().distanceUnits)
189+
}
190+
191+
@Suppress("DEPRECATION")
192+
@Test
193+
fun updateSettings_bothChanged_distanceUnitsWins() {
194+
scaleBarPlugin.updateSettings {
195+
isMetricUnits = false
196+
distanceUnits = DistanceUnits.NAUTICAL
197+
}
198+
assertEquals(DistanceUnits.NAUTICAL, scaleBarPlugin.getSettings().distanceUnits)
199+
assertEquals(false, scaleBarPlugin.getSettings().isMetricUnits)
200+
}
148201
}

sdk-base/api/Release/metalava.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,7 +2487,7 @@ package com.mapbox.maps.plugin.gestures.generated {
24872487
method public boolean getDoubleTouchToZoomOutEnabled();
24882488
method public com.mapbox.maps.ScreenCoordinate? getFocalPoint();
24892489
method public boolean getIncreasePinchToZoomThresholdWhenRotating();
2490-
method public boolean getIncreaseRotateThresholdWhenPinchingToZoom();
2490+
method @Deprecated public boolean getIncreaseRotateThresholdWhenPinchingToZoom();
24912491
method public boolean getPinchScrollEnabled();
24922492
method public boolean getPinchToZoomDecelerationEnabled();
24932493
method public boolean getPinchToZoomEnabled();
@@ -2505,7 +2505,7 @@ package com.mapbox.maps.plugin.gestures.generated {
25052505
property public final boolean doubleTouchToZoomOutEnabled;
25062506
property public final com.mapbox.maps.ScreenCoordinate? focalPoint;
25072507
property public final boolean increasePinchToZoomThresholdWhenRotating;
2508-
property public final boolean increaseRotateThresholdWhenPinchingToZoom;
2508+
property @Deprecated public final boolean increaseRotateThresholdWhenPinchingToZoom;
25092509
property public final boolean pinchScrollEnabled;
25102510
property public final boolean pinchToZoomDecelerationEnabled;
25112511
property public final boolean pinchToZoomEnabled;
@@ -2527,7 +2527,7 @@ package com.mapbox.maps.plugin.gestures.generated {
25272527
method public boolean getDoubleTouchToZoomOutEnabled();
25282528
method public com.mapbox.maps.ScreenCoordinate? getFocalPoint();
25292529
method public boolean getIncreasePinchToZoomThresholdWhenRotating();
2530-
method public boolean getIncreaseRotateThresholdWhenPinchingToZoom();
2530+
method @Deprecated public boolean getIncreaseRotateThresholdWhenPinchingToZoom();
25312531
method public boolean getPinchScrollEnabled();
25322532
method public boolean getPinchToZoomDecelerationEnabled();
25332533
method public boolean getPinchToZoomEnabled();
@@ -2544,7 +2544,7 @@ package com.mapbox.maps.plugin.gestures.generated {
25442544
method public com.mapbox.maps.plugin.gestures.generated.GesturesSettings.Builder setDoubleTouchToZoomOutEnabled(boolean doubleTouchToZoomOutEnabled);
25452545
method public com.mapbox.maps.plugin.gestures.generated.GesturesSettings.Builder setFocalPoint(com.mapbox.maps.ScreenCoordinate? focalPoint);
25462546
method public com.mapbox.maps.plugin.gestures.generated.GesturesSettings.Builder setIncreasePinchToZoomThresholdWhenRotating(boolean increasePinchToZoomThresholdWhenRotating);
2547-
method public com.mapbox.maps.plugin.gestures.generated.GesturesSettings.Builder setIncreaseRotateThresholdWhenPinchingToZoom(boolean increaseRotateThresholdWhenPinchingToZoom);
2547+
method @Deprecated public com.mapbox.maps.plugin.gestures.generated.GesturesSettings.Builder setIncreaseRotateThresholdWhenPinchingToZoom(boolean increaseRotateThresholdWhenPinchingToZoom);
25482548
method public com.mapbox.maps.plugin.gestures.generated.GesturesSettings.Builder setPinchScrollEnabled(boolean pinchScrollEnabled);
25492549
method public com.mapbox.maps.plugin.gestures.generated.GesturesSettings.Builder setPinchToZoomDecelerationEnabled(boolean pinchToZoomDecelerationEnabled);
25502550
method public com.mapbox.maps.plugin.gestures.generated.GesturesSettings.Builder setPinchToZoomEnabled(boolean pinchToZoomEnabled);
@@ -2561,7 +2561,7 @@ package com.mapbox.maps.plugin.gestures.generated {
25612561
property public final boolean doubleTouchToZoomOutEnabled;
25622562
property public final com.mapbox.maps.ScreenCoordinate? focalPoint;
25632563
property public final boolean increasePinchToZoomThresholdWhenRotating;
2564-
property public final boolean increaseRotateThresholdWhenPinchingToZoom;
2564+
property @Deprecated public final boolean increaseRotateThresholdWhenPinchingToZoom;
25652565
property public final boolean pinchScrollEnabled;
25662566
property public final boolean pinchToZoomDecelerationEnabled;
25672567
property public final boolean pinchToZoomEnabled;
@@ -3242,13 +3242,13 @@ package com.mapbox.maps.plugin.scalebar.generated {
32423242
method public int getTextColor();
32433243
method public float getTextSize();
32443244
method public boolean getUseContinuousRendering();
3245-
method public boolean isMetricUnits();
3245+
method @Deprecated public boolean isMetricUnits();
32463246
method public com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings.Builder toBuilder();
32473247
property public final float borderWidth;
32483248
property public final com.mapbox.maps.plugin.DistanceUnits distanceUnits;
32493249
property public final boolean enabled;
32503250
property public final float height;
3251-
property public final boolean isMetricUnits;
3251+
property @Deprecated public final boolean isMetricUnits;
32523252
property public final float marginBottom;
32533253
property public final float marginLeft;
32543254
property public final float marginRight;
@@ -3288,9 +3288,9 @@ package com.mapbox.maps.plugin.scalebar.generated {
32883288
method public int getTextColor();
32893289
method public float getTextSize();
32903290
method public boolean getUseContinuousRendering();
3291-
method public boolean isMetricUnits();
3291+
method @Deprecated public boolean isMetricUnits();
32923292
method public com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings.Builder setBorderWidth(float borderWidth);
3293-
method public com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings.Builder setDistanceUnits(com.mapbox.maps.plugin.DistanceUnits units);
3293+
method public com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings.Builder setDistanceUnits(com.mapbox.maps.plugin.DistanceUnits distanceUnits);
32943294
method public com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings.Builder setEnabled(boolean enabled);
32953295
method public com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings.Builder setHeight(float height);
32963296
method @Deprecated public com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings.Builder setIsMetricUnits(boolean isMetricUnits);
@@ -3313,7 +3313,7 @@ package com.mapbox.maps.plugin.scalebar.generated {
33133313
property public final com.mapbox.maps.plugin.DistanceUnits distanceUnits;
33143314
property public final boolean enabled;
33153315
property public final float height;
3316-
property public final boolean isMetricUnits;
3316+
property @Deprecated public final boolean isMetricUnits;
33173317
property public final float marginBottom;
33183318
property public final float marginLeft;
33193319
property public final float marginRight;

sdk-base/api/sdk-base.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3227,7 +3227,7 @@ public final class com/mapbox/maps/plugin/scalebar/ScaleBarPlugin$DefaultImpls {
32273227

32283228
public final class com/mapbox/maps/plugin/scalebar/generated/ScaleBarSettings : android/os/Parcelable {
32293229
public static final field CREATOR Landroid/os/Parcelable$Creator;
3230-
public synthetic fun <init> (ZIFFFFIIIFFFFFZJZFZLcom/mapbox/maps/plugin/DistanceUnits;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
3230+
public synthetic fun <init> (ZIFFFFIIIFFFFFZLcom/mapbox/maps/plugin/DistanceUnits;JZFZLkotlin/jvm/internal/DefaultConstructorMarker;)V
32313231
public fun describeContents ()I
32323232
public fun equals (Ljava/lang/Object;)Z
32333233
public final fun getBorderWidth ()F

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)