Skip to content

Commit f1296e6

Browse files
authored
Add use-theme to the spec during code generation for Lights (#3004)
* Add use-theme to the spec during code generation for Lights * Remove unused code * Update stylegen commit * Generate Rain use-theme properties from spec * Generate Snow use-theme properties from spec * Remove unused generator code * Reuse logic for creating use-theme properties * Use snapshot build to test gl-native fixes + update example * Update API * Cleanup generated code * Update example and snapshot version for gl-native and common * Add changelog entries * Update submodule pin * Use snapshot build for latest gl-native changes
1 parent 8a0bbed commit f1296e6

File tree

32 files changed

+1734
-508
lines changed

32 files changed

+1734
-508
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Mapbox welcomes participation and contributions from everyone.
55
# main
66
## Bug fixes 🐞
77
* Fix annotation drag being triggered when multi-finger gesture is in progress.
8+
## Features ✨ and improvements 🏁
9+
* Introduce experimental `colorUseTheme` API for `AmbientLight`, `DirectionalLight`, and `FlatLight` to override color theme of light.
10+
* [compose] Introduce experimental `colorUseTheme` API for `AmbientLightState`, `DirectionalLightState`, and `FlatLightState` to override color theme of light.
11+
* [compose] Introduce experimental `vignetteColorUseTheme` and `colorUseTheme` for `RainState` and `SnowState` which allows overriding color theme of precipitations.
812

913
# 11.11.0-rc.1 March 12, 2025
1014
## Features ✨ and improvements 🏁

app/src/androidTest/java/com/mapbox/maps/testapp/annotation/generated/CircleAnnotationManagerAndroidTest.kt

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

app/src/androidTest/java/com/mapbox/maps/testapp/annotation/generated/PointAnnotationManagerAndroidTest.kt

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

app/src/androidTest/java/com/mapbox/maps/testapp/annotation/generated/PolygonAnnotationManagerAndroidTest.kt

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

app/src/androidTest/java/com/mapbox/maps/testapp/annotation/generated/PolylineAnnotationManagerAndroidTest.kt

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

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

Lines changed: 163 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@ package com.mapbox.maps.compose.testapp.examples.style
33
import android.os.Bundle
44
import androidx.activity.ComponentActivity
55
import androidx.activity.compose.setContent
6+
import androidx.compose.foundation.layout.Arrangement
7+
import androidx.compose.foundation.layout.Box
68
import androidx.compose.foundation.layout.Column
9+
import androidx.compose.foundation.layout.Row
710
import androidx.compose.foundation.layout.fillMaxSize
11+
import androidx.compose.foundation.layout.fillMaxWidth
812
import androidx.compose.foundation.layout.padding
913
import androidx.compose.foundation.shape.RoundedCornerShape
14+
import androidx.compose.material.DropdownMenu
15+
import androidx.compose.material.DropdownMenuItem
1016
import androidx.compose.material.ExperimentalMaterialApi
1117
import androidx.compose.material.FilterChip
1218
import androidx.compose.material.FloatingActionButton
1319
import androidx.compose.material.Icon
1420
import androidx.compose.material.Text
1521
import androidx.compose.material.icons.Icons
1622
import androidx.compose.material.icons.filled.Done
23+
import androidx.compose.runtime.Composable
1724
import androidx.compose.runtime.getValue
1825
import androidx.compose.runtime.mutableStateOf
1926
import androidx.compose.runtime.remember
@@ -22,6 +29,7 @@ import androidx.compose.ui.Modifier
2229
import androidx.compose.ui.graphics.Color
2330
import androidx.compose.ui.unit.dp
2431
import com.mapbox.geojson.Point
32+
import com.mapbox.maps.ColorTheme
2533
import com.mapbox.maps.MapboxExperimental
2634
import com.mapbox.maps.Style
2735
import com.mapbox.maps.compose.testapp.ExampleScaffold
@@ -31,9 +39,14 @@ import com.mapbox.maps.dsl.cameraOptions
3139
import com.mapbox.maps.extension.compose.MapboxMap
3240
import com.mapbox.maps.extension.compose.animation.viewport.rememberMapViewportState
3341
import com.mapbox.maps.extension.compose.style.ColorValue
42+
import com.mapbox.maps.extension.compose.style.DoubleValue
3443
import com.mapbox.maps.extension.compose.style.GenericStyle
3544
import com.mapbox.maps.extension.compose.style.StringValue
3645
import com.mapbox.maps.extension.compose.style.atmosphere.generated.rememberAtmosphereState
46+
import com.mapbox.maps.extension.compose.style.precipitations.generated.RainState
47+
import com.mapbox.maps.extension.compose.style.precipitations.generated.SnowState
48+
import com.mapbox.maps.extension.compose.style.precipitations.generated.rememberRainState
49+
import com.mapbox.maps.extension.compose.style.precipitations.generated.rememberSnowState
3750
import com.mapbox.maps.extension.compose.style.rememberColorTheme
3851
import com.mapbox.maps.extension.compose.style.rememberStyleColorTheme
3952
import com.mapbox.maps.extension.compose.style.rememberStyleState
@@ -68,43 +81,145 @@ public class ColorThemeActivity : ComponentActivity() {
6881
mutableStateOf(initialAtmosphereState)
6982
}
7083

84+
val blueSnowState = rememberSnowState().apply {
85+
color = ColorValue(Color.Blue)
86+
}
87+
var currentSnowState by remember {
88+
mutableStateOf(SnowState.DISABLED)
89+
}
90+
91+
val greenRainState = rememberRainState().apply {
92+
color = ColorValue(Color.Green)
93+
opacity = DoubleValue(0.8)
94+
}
95+
var currentRainState by remember {
96+
mutableStateOf(RainState.DISABLED)
97+
}
98+
7199
// When state is toggled, update atmosphere state with correct string value.
72100
// Setting it to "none" means that color theme will not affect atmosphere.
73101
currentAtmosphereState.colorUseTheme = StringValue(
74102
if (atmosphereUseTheme) "default" else "none"
75103
)
76104

105+
var showSnowMenu by remember { mutableStateOf(false) }
106+
var showRainMenu by remember { mutableStateOf(false) }
107+
var showThemeMenu by remember { mutableStateOf(false) }
108+
77109
MapboxMapComposeTheme {
78110
ExampleScaffold(
79111
floatingActionButton = {
80-
Column {
81-
FloatingActionButton(
82-
modifier = Modifier.padding(bottom = 10.dp),
83-
onClick = {
84-
currentColorTheme = monochromeColorTheme
85-
},
86-
shape = RoundedCornerShape(16.dp),
112+
Column(modifier = Modifier.padding(horizontal = 32.dp)) {
113+
Row(
114+
horizontalArrangement = Arrangement.Absolute.SpaceBetween,
115+
modifier = Modifier.fillMaxWidth()
87116
) {
88-
Text(modifier = Modifier.padding(10.dp), text = "Monochrome")
89-
}
90-
FloatingActionButton(
91-
modifier = Modifier.padding(bottom = 10.dp),
92-
onClick = {
93-
currentColorTheme = base64ColorTheme
94-
},
95-
shape = RoundedCornerShape(16.dp),
96-
) {
97-
Text(modifier = Modifier.padding(10.dp), text = "Red")
98-
}
99-
FloatingActionButton(
100-
modifier = Modifier.padding(bottom = 10.dp),
101-
onClick = {
102-
// creating empty style color theme which will reset color theme when set to color theme state.
103-
currentColorTheme = colorTheme()
104-
},
105-
shape = RoundedCornerShape(16.dp),
106-
) {
107-
Text(modifier = Modifier.padding(10.dp), text = "Reset")
117+
Box {
118+
FloatingActionButton(
119+
modifier = Modifier.padding(bottom = 10.dp),
120+
onClick = { showThemeMenu = true },
121+
shape = RoundedCornerShape(16.dp),
122+
) {
123+
Text(modifier = Modifier.padding(10.dp), text = "Theme")
124+
}
125+
ThemeSelector(
126+
items = listOf(
127+
"Monochrome" to monochromeColorTheme,
128+
"Red" to base64ColorTheme,
129+
"Reset" to colorTheme(),
130+
),
131+
expanded = showThemeMenu,
132+
onDismissRequest = { showThemeMenu = false },
133+
{
134+
currentColorTheme = it
135+
showThemeMenu = false
136+
}
137+
)
138+
}
139+
140+
Box {
141+
FloatingActionButton(
142+
modifier = Modifier.padding(bottom = 10.dp),
143+
onClick = { showSnowMenu = true },
144+
shape = RoundedCornerShape(16.dp),
145+
) {
146+
Text(modifier = Modifier.padding(10.dp), text = "Snow")
147+
}
148+
DropdownMenu(
149+
expanded = showSnowMenu,
150+
onDismissRequest = { showSnowMenu = false }
151+
) {
152+
DropdownMenuItem(
153+
onClick = {
154+
currentSnowState = blueSnowState.apply {
155+
colorUseTheme = StringValue("default")
156+
}
157+
showSnowMenu = false
158+
},
159+
content = { Text("Enable (colorUseTheme=default)") }
160+
)
161+
162+
DropdownMenuItem(
163+
onClick = {
164+
currentSnowState = blueSnowState.apply {
165+
colorUseTheme = StringValue("none")
166+
}
167+
showSnowMenu = false
168+
},
169+
content = { Text("Enable (colorUseTheme=none)") }
170+
)
171+
172+
DropdownMenuItem(
173+
onClick = {
174+
currentSnowState = SnowState.DISABLED
175+
showSnowMenu = false
176+
},
177+
content = { Text("Disable") }
178+
)
179+
}
180+
}
181+
182+
Box {
183+
FloatingActionButton(
184+
modifier = Modifier.padding(bottom = 10.dp),
185+
onClick = { showRainMenu = true },
186+
shape = RoundedCornerShape(16.dp),
187+
) {
188+
Text(modifier = Modifier.padding(10.dp), text = "Rain")
189+
}
190+
DropdownMenu(
191+
expanded = showRainMenu,
192+
onDismissRequest = { showRainMenu = false }
193+
) {
194+
DropdownMenuItem(
195+
onClick = {
196+
currentRainState = greenRainState.apply {
197+
colorUseTheme = StringValue("default")
198+
}
199+
showRainMenu = false
200+
},
201+
content = { Text("Enable (colorUseTheme=default)") }
202+
)
203+
204+
DropdownMenuItem(
205+
onClick = {
206+
currentRainState = greenRainState.apply {
207+
colorUseTheme = StringValue("none")
208+
}
209+
showRainMenu = false
210+
},
211+
content = { Text("Enable (colorUseTheme=none)") }
212+
)
213+
214+
DropdownMenuItem(
215+
onClick = {
216+
currentRainState = RainState.DISABLED
217+
showRainMenu = false
218+
},
219+
content = { Text("Disable") }
220+
)
221+
}
222+
}
108223
}
109224

110225
FilterChip(
@@ -140,6 +255,8 @@ public class ColorThemeActivity : ComponentActivity() {
140255
styleState = rememberStyleState {
141256
styleColorTheme = currentStyleColorTheme
142257
atmosphereState = currentAtmosphereState
258+
snowState = currentSnowState
259+
rainState = currentRainState
143260
},
144261
)
145262
}
@@ -149,6 +266,25 @@ public class ColorThemeActivity : ComponentActivity() {
149266
}
150267
}
151268

269+
@Composable
270+
private fun ThemeSelector(
271+
items: List<Pair<String, ColorTheme>>,
272+
expanded: Boolean,
273+
onDismissRequest: () -> Unit,
274+
onThemeSelected: (ColorTheme) -> Unit
275+
) {
276+
DropdownMenu(
277+
expanded = expanded,
278+
onDismissRequest = onDismissRequest
279+
) {
280+
items.forEach { (name, theme) ->
281+
DropdownMenuItem(onClick = { onThemeSelected(theme) }) {
282+
Text(name)
283+
}
284+
}
285+
}
286+
}
287+
152288
public companion object {
153289
/**
154290
* Base64 encoded version of a custom LUT (Look-Up Table) image.

0 commit comments

Comments
 (0)