Skip to content

Commit fbd3b90

Browse files
pengdevgithub-actions[bot]
authored andcommitted
Promote interactions API to be stable. (#3640)
GitOrigin-RevId: d5f471a8c3e31320e9d923dcd7ddce380849dd3f
1 parent 3e982f4 commit fbd3b90

39 files changed

+236
-350
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Mapbox welcomes participation and contributions from everyone.
77
* Expose `RenderThreadStatsRecorder` as experimental API.
88
* Expose an experimental API to define a non-rectangular screen culling shape(`MapboxMap.get/setScreenCullingShape`)
99
* Expose new experimental properties: `CircleLayer.circleElevationReference`, `FillLayer.fillConstructBridgeGuardRail`, `FillLayer.fillBridgeGuardRailColor`, `FillLayer.fillTunnelStructureColor`.
10+
* Promote `MapInteraction` APIs to stable, remove experimental `Style.STANDARD_EXPERIMENTAL` constant, as `Style.STANDARD` supports featuresets and map interactions by default.
11+
* [compose] Rename experimental `ExperimentalStandardStyleState` to `StandardStyleState`, rename experimental `MapboxStandardStyleExperimental` to `MapboxStandardStyle(styleImportsContent, topSlot, middleSlot, bottomSlot, standardStyleState)`, and deprecate previous `MapboxStandardStyle` composable functions.
1012

1113
## Bug fixes 🐞
1214
* Fix registering camera change listener every time `mapView.scalebar.enabled` is called with value `true` and it was already enabled.

app/src/main/java/com/mapbox/maps/testapp/examples/JavaInterfaceChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ private void interactions(final MapboxMap mapboxMap) {
702702
)
703703
);
704704

705-
mapboxMap.loadStyle(Style.STANDARD_EXPERIMENTAL);
705+
mapboxMap.loadStyle(Style.STANDARD);
706706
mapboxMap.addInteraction(
707707
StandardInteractions.standardBuildings(
708708
ClickInteraction.Companion,

app/src/main/java/com/mapbox/maps/testapp/examples/StandardStyleInteractionsActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class StandardStyleInteractionsActivity : AppCompatActivity() {
5353
val map = mapView.mapboxMap
5454
val selectedPoiList = mutableListOf<StandardPoiFeature>()
5555

56-
map.loadStyle(Style.STANDARD_EXPERIMENTAL)
56+
map.loadStyle(Style.STANDARD)
5757

5858
// the most basic use-case to highlight clicked building
5959
map.addInteraction(

compose-app/src/main/java/com/mapbox/maps/compose/testapp/examples/style/StandardStyleActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import androidx.compose.runtime.setValue
2323
import androidx.compose.ui.Modifier
2424
import androidx.compose.ui.graphics.Color
2525
import androidx.compose.ui.unit.dp
26-
import com.mapbox.maps.MapboxExperimental
2726
import com.mapbox.maps.compose.testapp.ExampleScaffold
2827
import com.mapbox.maps.compose.testapp.examples.utils.CityLocations
2928
import com.mapbox.maps.compose.testapp.ui.theme.MapboxMapComposeTheme
@@ -33,16 +32,15 @@ import com.mapbox.maps.extension.compose.style.BooleanValue
3332
import com.mapbox.maps.extension.compose.style.StringValue
3433
import com.mapbox.maps.extension.compose.style.standard.LightPresetValue
3534
import com.mapbox.maps.extension.compose.style.standard.MapboxStandardSatelliteStyle
36-
import com.mapbox.maps.extension.compose.style.standard.MapboxStandardStyleExperimental
35+
import com.mapbox.maps.extension.compose.style.standard.MapboxStandardStyle
3736
import com.mapbox.maps.extension.compose.style.standard.ThemeValue
38-
import com.mapbox.maps.extension.compose.style.standard.rememberExperimentalStandardStyleState
37+
import com.mapbox.maps.extension.compose.style.standard.rememberStandardStyleState
3938
import com.mapbox.maps.extension.style.utils.transition
4039

4140
/**
4241
* Example to showcase usage of the configs of `MapboxStandardStyle`.
4342
*/
4443
public class StandardStyleActivity : ComponentActivity() {
45-
@OptIn(MapboxExperimental::class)
4644
override fun onCreate(savedInstanceState: Bundle?) {
4745
super.onCreate(savedInstanceState)
4846
setContent {
@@ -353,8 +351,8 @@ public class StandardStyleActivity : ComponentActivity() {
353351
showPedestrianRoads = BooleanValue(enablePedestrianRoads)
354352
}
355353
} else {
356-
MapboxStandardStyleExperimental(
357-
experimentalStandardStyleState = rememberExperimentalStandardStyleState {
354+
MapboxStandardStyle(
355+
standardStyleState = rememberStandardStyleState {
358356
interactionsState.onBuildingsClicked { clickedBuilding, _ ->
359357
clickedBuilding.setStandardBuildingsState {
360358
highlight(true)

extension-compose/api/Release/metalava.txt

Lines changed: 33 additions & 36 deletions
Large diffs are not rendered by default.

extension-compose/api/extension-compose.api

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4267,18 +4267,6 @@ public abstract class com/mapbox/maps/extension/compose/style/standard/BaseStyle
42674267
public final fun setShowTransitLabels (Lcom/mapbox/maps/extension/compose/style/BooleanValue;)V
42684268
}
42694269

4270-
public final class com/mapbox/maps/extension/compose/style/standard/ExperimentalStandardStyleState : com/mapbox/maps/extension/compose/style/standard/BaseStandardStyleState {
4271-
public fun <init> ()V
4272-
public final fun getConfigurationsState ()Lcom/mapbox/maps/extension/compose/style/standard/StandardStyleConfigurationState;
4273-
public final fun getInteractionsState ()Lcom/mapbox/maps/extension/compose/style/standard/generated/StandardStyleInteractionsState;
4274-
public final fun setConfigurationsState (Lcom/mapbox/maps/extension/compose/style/standard/StandardStyleConfigurationState;)V
4275-
public final fun setInteractionsState (Lcom/mapbox/maps/extension/compose/style/standard/generated/StandardStyleInteractionsState;)V
4276-
}
4277-
4278-
public final class com/mapbox/maps/extension/compose/style/standard/ExperimentalStandardStyleStateKt {
4279-
public static final fun rememberExperimentalStandardStyleState (Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)Lcom/mapbox/maps/extension/compose/style/standard/ExperimentalStandardStyleState;
4280-
}
4281-
42824270
public final class com/mapbox/maps/extension/compose/style/standard/LightPresetValue {
42834271
public static final field Companion Lcom/mapbox/maps/extension/compose/style/standard/LightPresetValue$Companion;
42844272
public static final field DAWN Lcom/mapbox/maps/extension/compose/style/standard/LightPresetValue;
@@ -4307,13 +4295,10 @@ public final class com/mapbox/maps/extension/compose/style/standard/MapboxStanda
43074295
public static final fun MapboxStandardSatelliteStyle (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lcom/mapbox/maps/extension/compose/style/projection/generated/Projection;Lcom/mapbox/maps/extension/compose/style/atmosphere/generated/AtmosphereState;Lcom/mapbox/maps/extension/compose/style/terrain/generated/TerrainState;Lcom/mapbox/maps/extension/compose/style/lights/LightsState;Lcom/mapbox/maps/TransitionOptions;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
43084296
}
43094297

4310-
public final class com/mapbox/maps/extension/compose/style/standard/MapboxStandardStyleExperimentalKt {
4311-
public static final fun MapboxStandardStyleExperimental (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lcom/mapbox/maps/extension/compose/style/standard/ExperimentalStandardStyleState;Landroidx/compose/runtime/Composer;II)V
4312-
}
4313-
43144298
public final class com/mapbox/maps/extension/compose/style/standard/MapboxStandardStyleKt {
43154299
public static final fun MapboxStandardStyle (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lcom/mapbox/maps/extension/compose/style/projection/generated/Projection;Lcom/mapbox/maps/extension/compose/style/atmosphere/generated/AtmosphereState;Lcom/mapbox/maps/extension/compose/style/terrain/generated/TerrainState;Lcom/mapbox/maps/extension/compose/style/lights/LightsState;Lcom/mapbox/maps/TransitionOptions;Lcom/mapbox/maps/extension/compose/style/standard/StandardStyleConfigurationState;Landroidx/compose/runtime/Composer;II)V
43164300
public static final fun MapboxStandardStyle (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lcom/mapbox/maps/extension/compose/style/projection/generated/Projection;Lcom/mapbox/maps/extension/compose/style/atmosphere/generated/AtmosphereState;Lcom/mapbox/maps/extension/compose/style/terrain/generated/TerrainState;Lcom/mapbox/maps/extension/compose/style/lights/LightsState;Lcom/mapbox/maps/TransitionOptions;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
4301+
public static final fun MapboxStandardStyle (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lcom/mapbox/maps/extension/compose/style/standard/StandardStyleState;Landroidx/compose/runtime/Composer;II)V
43174302
}
43184303

43194304
public final class com/mapbox/maps/extension/compose/style/standard/StandardSatelliteStyleConfigurationState : com/mapbox/maps/extension/compose/style/standard/BaseStyleConfigurationState {
@@ -4332,6 +4317,18 @@ public final class com/mapbox/maps/extension/compose/style/standard/StandardStyl
43324317
public final fun setTheme (Lcom/mapbox/maps/extension/compose/style/standard/ThemeValue;)V
43334318
}
43344319

4320+
public final class com/mapbox/maps/extension/compose/style/standard/StandardStyleState : com/mapbox/maps/extension/compose/style/standard/BaseStandardStyleState {
4321+
public fun <init> ()V
4322+
public final fun getConfigurationsState ()Lcom/mapbox/maps/extension/compose/style/standard/StandardStyleConfigurationState;
4323+
public final fun getInteractionsState ()Lcom/mapbox/maps/extension/compose/style/standard/generated/StandardStyleInteractionsState;
4324+
public final fun setConfigurationsState (Lcom/mapbox/maps/extension/compose/style/standard/StandardStyleConfigurationState;)V
4325+
public final fun setInteractionsState (Lcom/mapbox/maps/extension/compose/style/standard/generated/StandardStyleInteractionsState;)V
4326+
}
4327+
4328+
public final class com/mapbox/maps/extension/compose/style/standard/StandardStyleStateKt {
4329+
public static final fun rememberStandardStyleState (Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)Lcom/mapbox/maps/extension/compose/style/standard/StandardStyleState;
4330+
}
4331+
43354332
public final class com/mapbox/maps/extension/compose/style/standard/ThemeValue {
43364333
public static final field Companion Lcom/mapbox/maps/extension/compose/style/standard/ThemeValue$Companion;
43374334
public static final field DEFAULT Lcom/mapbox/maps/extension/compose/style/standard/ThemeValue;

extension-compose/src/main/java/com/mapbox/maps/extension/compose/style/interactions/BasicStyleInteractions.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.mapbox.maps.ClickInteraction
99
import com.mapbox.maps.InteractionContext
1010
import com.mapbox.maps.LongClickInteraction
1111
import com.mapbox.maps.MapInteraction
12-
import com.mapbox.maps.MapboxExperimental
1312
import com.mapbox.maps.MapboxMap
1413
import com.mapbox.maps.extension.compose.style.interactions.generated.FeaturesetFeatureScope
1514
import com.mapbox.maps.extension.compose.style.interactions.generated.FeaturesetFeatureScopeImpl
@@ -22,7 +21,6 @@ import com.mapbox.maps.interactions.FeaturesetFeature
2221
*
2322
* Note this is a generic implementation with no public API exposed.
2423
*/
25-
@MapboxExperimental
2624
public abstract class BasicStyleInteractions {
2725
// map interaction builder entries that will be built and added to the map when the state is bind to the map.
2826
// this property is used directly by generated Standard interactions and then lambda represents (importId? -> MapInteraction)

extension-compose/src/main/java/com/mapbox/maps/extension/compose/style/interactions/generated/FeaturesetFeatureScope.kt

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

extension-compose/src/main/java/com/mapbox/maps/extension/compose/style/standard/BaseStandardStyleState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import com.mapbox.maps.extension.compose.style.terrain.generated.TerrainState
1616
/**
1717
* The base state holder for the Standard Style.
1818
*/
19+
@OptIn(MapboxExperimental::class)
1920
@Stable
20-
@MapboxExperimental
2121
public open class BaseStandardStyleState protected constructor(
2222
initialProjection: Projection,
2323
initialAtmosphereState: AtmosphereState,

extension-compose/src/main/java/com/mapbox/maps/extension/compose/style/standard/MapboxStandardStyle.kt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.mapbox.maps.extension.compose.style.standard
22

33
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.currentComposer
5+
import androidx.compose.runtime.key
46
import androidx.compose.runtime.remember
57
import com.mapbox.maps.Style
68
import com.mapbox.maps.TransitionOptions
79
import com.mapbox.maps.extension.compose.MapboxMapComposable
10+
import com.mapbox.maps.extension.compose.internal.MapApplier
811
import com.mapbox.maps.extension.compose.style.GenericStyle
912
import com.mapbox.maps.extension.compose.style.MapboxStyleComposable
1013
import com.mapbox.maps.extension.compose.style.atmosphere.generated.AtmosphereState
@@ -35,6 +38,7 @@ import com.mapbox.maps.extension.style.utils.transition
3538
*/
3639
@Composable
3740
@MapboxStyleComposable
41+
@Deprecated(message = "Use MapboxStandardStyle with StandardStyleState instead.", replaceWith = ReplaceWith("MapboxStandardStyle(styleImportsContent, topSlot, middleSlot, bottomSlot, standardStyleState)"))
3842
public fun MapboxStandardStyle(
3943
styleImportsContent: (@Composable @MapboxStyleImportComposable StyleImportsScope.() -> Unit)? = null,
4044
topSlot: (@Composable @MapboxMapComposable () -> Unit)? = null,
@@ -120,6 +124,7 @@ public fun MapboxStandardStyle(
120124
*/
121125
@Composable
122126
@MapboxStyleComposable
127+
@Deprecated(message = "Use MapboxStandardStyle with StandardStyleState instead", replaceWith = ReplaceWith("MapboxStandardStyle(styleImportsContent, topSlot, middleSlot, bottomSlot, standardStyleState)"))
123128
public fun MapboxStandardStyle(
124129
styleImportsContent: (@Composable @MapboxStyleImportComposable StyleImportsScope.() -> Unit)? = null,
125130
topSlot: (@Composable @MapboxMapComposable () -> Unit)? = null,
@@ -146,4 +151,82 @@ public fun MapboxStandardStyle(
146151
StandardStyleConfigurationState()
147152
}.apply(init)
148153
)
154+
}
155+
156+
/**
157+
* The convenient composable function to set a Mapbox Standard style to the map, with available slots
158+
* and config options.
159+
*
160+
* @param styleImportsContent The style imports to be added to the current style, note layers and annotations shouldn't be added to this block.
161+
* @param topSlot The content to be set to the top slot of the Mapbox Standard style.
162+
* @param middleSlot The content to be set to the middle slot of the Mapbox Standard style.
163+
* @param bottomSlot The content to be set to the bottom slot of the Mapbox Standard style.
164+
* @param standardStyleState The state holder for the experimental Mapbox Standard Style.
165+
*/
166+
@Composable
167+
@MapboxStyleComposable
168+
public fun MapboxStandardStyle(
169+
styleImportsContent: (@Composable @MapboxStyleImportComposable StyleImportsScope.() -> Unit)? = null,
170+
topSlot: (@Composable @MapboxMapComposable () -> Unit)? = null,
171+
middleSlot: (@Composable @MapboxMapComposable () -> Unit)? = null,
172+
bottomSlot: (@Composable @MapboxMapComposable () -> Unit)? = null,
173+
standardStyleState: StandardStyleState = rememberStandardStyleState(),
174+
) {
175+
GenericStyle(
176+
style = Style.STANDARD,
177+
styleImportsContent = styleImportsContent,
178+
slotsContent = slotsContent {
179+
topSlot?.let { slot("top", it) }
180+
middleSlot?.let { slot("middle", it) }
181+
bottomSlot?.let { slot("bottom", it) }
182+
},
183+
styleState = rememberStyleState {
184+
styleImportsConfig = styleImportsConfig {
185+
importConfig(importId = "basemap") {
186+
with(standardStyleState.configurationsState) {
187+
if (showPlaceLabels.isNotInitial()) {
188+
config(BaseStyleConfigurationState.CONFIG_SHOW_PLACE_LABELS, showPlaceLabels.value)
189+
}
190+
if (showRoadLabels.isNotInitial()) {
191+
config(BaseStyleConfigurationState.CONFIG_SHOW_ROAD_LABELS, showRoadLabels.value)
192+
}
193+
if (showPointOfInterestLabels.isNotInitial()) {
194+
config(
195+
BaseStyleConfigurationState.CONFIG_SHOW_POINT_OF_INTEREST_LABELS,
196+
showPointOfInterestLabels.value
197+
)
198+
}
199+
if (showTransitLabels.isNotInitial()) {
200+
config(
201+
BaseStyleConfigurationState.CONFIG_SHOW_TRANSIT_LABELS,
202+
showTransitLabels.value
203+
)
204+
}
205+
if (lightPreset.notInitial) {
206+
config(BaseStyleConfigurationState.CONFIG_LIGHT_PRESET, lightPreset.value)
207+
}
208+
if (font.isNotInitial()) {
209+
config(BaseStyleConfigurationState.CONFIG_FONT, font.value)
210+
}
211+
if (show3dObjects.isNotInitial()) {
212+
config(StandardStyleConfigurationState.CONFIG_SHOW_3D_OBJECTS, show3dObjects.value)
213+
}
214+
if (theme.notInitial) {
215+
config(StandardStyleConfigurationState.CONFIG_THEME, theme.value)
216+
}
217+
}
218+
}
219+
}
220+
this.projection = standardStyleState.projection
221+
this.atmosphereState = standardStyleState.atmosphereState
222+
this.terrainState = standardStyleState.terrainState
223+
this.lightsState = standardStyleState.lightsState
224+
this.styleTransition = standardStyleState.styleTransition
225+
}
226+
)
227+
val mapApplier = currentComposer.applier as? MapApplier
228+
?: throw IllegalStateException("Illegal use of Style composable outside of MapboxMapComposable")
229+
key(standardStyleState.interactionsState) {
230+
standardStyleState.interactionsState.BindTo(mapboxMap = mapApplier.mapView.mapboxMap)
231+
}
149232
}

0 commit comments

Comments
 (0)