11package com.mapbox.maps.extension.compose.style
22
33import android.util.Range
4+ import androidx.annotation.RestrictTo
5+ import androidx.compose.runtime.Composable
46import androidx.compose.runtime.Immutable
7+ import androidx.compose.runtime.MutableState
58import androidx.compose.ui.graphics.Color
69import com.mapbox.bindgen.Value
710import com.mapbox.geojson.Point
811import com.mapbox.maps.extension.compose.style.internal.ComposeTypeUtils
12+ import com.mapbox.maps.extension.compose.style.layers.ImageValue
13+ import com.mapbox.maps.extension.compose.style.layers.internal.LayerNode
914import com.mapbox.maps.extension.style.expressions.generated.Expression
1015import com.mapbox.maps.extension.style.utils.ColorUtils
1116
17+ internal interface HoldsValue {
18+ val value: Value
19+
20+ fun isNotInitial (): Boolean
21+ }
22+
23+ @Composable
24+ internal fun ActionWhenNotInitial (
25+ action : (name: String , value: Value ) -> Unit ,
26+ state : MutableState <out HoldsValue >,
27+ name : String
28+ ) {
29+ with (state.value) {
30+ if (isNotInitial()) {
31+ action(name, value)
32+ }
33+ }
34+ }
35+
36+ @Composable
37+ internal fun AddImageWhenNotInitial (
38+ layerNode : LayerNode ,
39+ state : MutableState <ImageValue >,
40+ name : String
41+ ) {
42+ with (state.value) {
43+ if (notInitial) {
44+ styleImage?.let {
45+ layerNode.addImage(it)
46+ }
47+ layerNode.setProperty(name, value)
48+ }
49+ }
50+ }
51+
1252/* *
1353 * Defines the color used by the Maps render engine.
1454 * It can be either [Color] or an [Expression].
1555 *
1656 * @param value a value representing the color. See [Color](https://docs.mapbox.com/style-spec/reference/types/#color).
1757 */
1858@Immutable
19- public data class ColorValue (public val value : Value ) {
59+ public data class ColorValue (public override val value : Value ) : HoldsValue {
2060 /* *
2161 * Construct the Color with [Color].
2262 */
@@ -44,8 +84,8 @@ public data class ColorValue(public val value: Value) {
4484 /* *
4585 * True if the this value is not [INITIAL]
4686 */
47- internal val notInitial : Boolean
48- get() = this != = INITIAL
87+ @RestrictTo( RestrictTo . Scope . LIBRARY_GROUP )
88+ override fun isNotInitial (): Boolean = this != = INITIAL
4989
5090 /* *
5191 * [ColorValue]'s companion object.
@@ -77,7 +117,7 @@ public data class ColorValue(public val value: Value) {
77117 * @param value a value representing a number. See [Number](https://docs.mapbox.com/style-spec/reference/types/#number)
78118 */
79119@Immutable
80- public data class DoubleValue (public val value : Value ) {
120+ public data class DoubleValue (public override val value : Value ) : HoldsValue {
81121 /* *
82122 * Create a [DoubleValue] that contains finite double [value].
83123 *
@@ -99,8 +139,8 @@ public data class DoubleValue(public val value: Value) {
99139 /* *
100140 * True if the this value is not [INITIAL]
101141 */
102- internal val notInitial : Boolean
103- get() = this != = INITIAL
142+ @RestrictTo( RestrictTo . Scope . LIBRARY_GROUP )
143+ override fun isNotInitial (): Boolean = this != = INITIAL
104144
105145 /* *
106146 * [DoubleValue]'s companion object.
@@ -131,7 +171,7 @@ public data class DoubleValue(public val value: Value) {
131171 *
132172 * @param value a value representing an array of two numbers. See [Number](https://docs.mapbox.com/style-spec/reference/types/#number)
133173 */
134- public data class DoubleRangeValue (public val value : Value ) {
174+ public data class DoubleRangeValue (public override val value : Value ) : HoldsValue {
135175
136176 /* *
137177 * Create a [DoubleRangeValue] that contains a list of [Double] that represent a range.
@@ -181,8 +221,8 @@ public data class DoubleRangeValue(public val value: Value) {
181221 /* *
182222 * True if the this value is not [INITIAL]
183223 */
184- internal val notInitial : Boolean
185- get() = this != = INITIAL
224+ @RestrictTo( RestrictTo . Scope . LIBRARY_GROUP )
225+ override fun isNotInitial (): Boolean = this != = INITIAL
186226
187227 /* *
188228 * [DoubleRangeValue]'s companion object.
@@ -214,7 +254,7 @@ public data class DoubleRangeValue(public val value: Value) {
214254 * @param value a value representing a number. See [Number](https://docs.mapbox.com/style-spec/reference/types/#number)
215255 */
216256@Immutable
217- public data class LongValue (public val value : Value ) {
257+ public data class LongValue (public override val value : Value ) : HoldsValue {
218258 /* *
219259 * Create a [LongValue] that contains long [value].
220260 *
@@ -236,8 +276,8 @@ public data class LongValue(public val value: Value) {
236276 /* *
237277 * True if the this value is not [INITIAL]
238278 */
239- internal val notInitial : Boolean
240- get() = this != = INITIAL
279+ @RestrictTo( RestrictTo . Scope . LIBRARY_GROUP )
280+ override fun isNotInitial (): Boolean = this != = INITIAL
241281
242282 /* *
243283 * [LongValue]'s companion object.
@@ -269,7 +309,7 @@ public data class LongValue(public val value: Value) {
269309 * @param value a value representing a boolean.
270310 */
271311@Immutable
272- public data class BooleanValue (public val value : Value ) {
312+ public data class BooleanValue (public override val value : Value ) : HoldsValue {
273313 /* *
274314 * Create a [BooleanValue] that contains boolean [value].
275315 *
@@ -289,10 +329,10 @@ public data class BooleanValue(public val value: Value) {
289329 get() = value.contents as ? Boolean
290330
291331 /* *
292- * True if the this value is not [INITIAL]
332+ * True if this value is not [INITIAL]
293333 */
294- internal val notInitial : Boolean
295- get() = this != = INITIAL
334+ @RestrictTo( RestrictTo . Scope . LIBRARY_GROUP )
335+ override fun isNotInitial (): Boolean = this != = INITIAL
296336
297337 /* *
298338 * [BooleanValue]'s companion object.
@@ -324,7 +364,7 @@ public data class BooleanValue(public val value: Value) {
324364 * @param value a value representing a string.
325365 */
326366@Immutable
327- public data class StringValue (public val value : Value ) {
367+ public data class StringValue (public override val value : Value ) : HoldsValue {
328368 /* *
329369 * Create a [StringValue] that contains string [value].
330370 *
@@ -346,8 +386,8 @@ public data class StringValue(public val value: Value) {
346386 /* *
347387 * True if the this value is not [INITIAL]
348388 */
349- internal val notInitial : Boolean
350- get() = this != = INITIAL
389+ @RestrictTo( RestrictTo . Scope . LIBRARY_GROUP )
390+ override fun isNotInitial (): Boolean = this != = INITIAL
351391
352392 /* *
353393 * [StringValue]'s companion object.
@@ -379,7 +419,7 @@ public data class StringValue(public val value: Value) {
379419 * @param value a value representing a string.
380420 */
381421@Immutable
382- public data class StringListValue (public val value : Value ) {
422+ public data class StringListValue (public override val value : Value ) : HoldsValue {
383423 /* *
384424 * Create a [StringListValue] that contains string [value].
385425 *
@@ -426,8 +466,8 @@ public data class StringListValue(public val value: Value) {
426466 /* *
427467 * True if the this value is not [INITIAL]
428468 */
429- internal val notInitial : Boolean
430- get() = this != = INITIAL
469+ @RestrictTo( RestrictTo . Scope . LIBRARY_GROUP )
470+ override fun isNotInitial (): Boolean = this != = INITIAL
431471
432472 /* *
433473 * [StringValue]'s companion object.
@@ -458,7 +498,7 @@ public data class StringListValue(public val value: Value) {
458498 *
459499 * @param value a value representing an array of numbers. See [Number](https://docs.mapbox.com/style-spec/reference/types/#number)
460500 */
461- public data class DoubleListValue (public val value : Value ) {
501+ public data class DoubleListValue (public override val value : Value ) : HoldsValue {
462502 /* *
463503 * Create a [DoubleListValue] from a list of [Double].
464504 *
@@ -505,8 +545,8 @@ public data class DoubleListValue(public val value: Value) {
505545 /* *
506546 * True if the this value is not [INITIAL]
507547 */
508- internal val notInitial : Boolean
509- get() = this != = INITIAL
548+ @RestrictTo( RestrictTo . Scope . LIBRARY_GROUP )
549+ override fun isNotInitial (): Boolean = this != = INITIAL
510550
511551 /* *
512552 * [DoubleListValue]'s companion object.
@@ -537,7 +577,7 @@ public data class DoubleListValue(public val value: Value) {
537577 *
538578 * @param value the transition wrapped in [Value] to be used with native renderer.
539579 */
540- public data class Transition internal constructor(public val value : Value ) {
580+ public data class Transition internal constructor(public override val value : Value ) : HoldsValue {
541581
542582 /* *
543583 * Construct the [Transition] with duration and delay.
@@ -568,8 +608,8 @@ public data class Transition internal constructor(public val value: Value) {
568608 /* *
569609 * True if the this value is not [INITIAL]
570610 */
571- internal val notInitial : Boolean
572- get() = this != = INITIAL
611+ @RestrictTo( RestrictTo . Scope . LIBRARY_GROUP )
612+ override fun isNotInitial (): Boolean = this != = INITIAL
573613
574614 /* *
575615 * Public companion object.
@@ -599,7 +639,7 @@ public data class Transition internal constructor(public val value: Value) {
599639 *
600640 * @param value a value representing an array of coordinates. See [Array](https://docs.mapbox.com/style-spec/reference/types/#array)
601641 */
602- public data class PointListValue (public val value : Value ) {
642+ public data class PointListValue (public override val value : Value ) : HoldsValue {
603643
604644 /* *
605645 * Create a [PointListValue] that contains a list of [Point]s.
@@ -654,8 +694,8 @@ public data class PointListValue(public val value: Value) {
654694 /* *
655695 * True if the this value is not [INITIAL]
656696 */
657- internal val notInitial : Boolean
658- get() = this != = INITIAL
697+ @RestrictTo( RestrictTo . Scope . LIBRARY_GROUP )
698+ override fun isNotInitial (): Boolean = this != = INITIAL
659699
660700 /* *
661701 * [PointListValue]'s companion object.
0 commit comments