@maplibre/maplibre-react-native 11.0.0-beta.30 → 11.0.0-beta.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. package/android/src/main/java/org/maplibre/reactnative/components/layer/MLRNLayer.kt +8 -8
  2. package/android/src/main/java/org/maplibre/reactnative/components/layer/style/MLRNStyle.kt +60 -0
  3. package/android/src/main/java/org/maplibre/reactnative/components/layer/style/MLRNStyleFactory.kt +3005 -0
  4. package/android/src/main/java/org/maplibre/reactnative/components/layer/style/MLRNStyleValue.kt +159 -0
  5. package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +3 -1
  6. package/ios/components/layer/style/MLRNStyle.h +1 -1
  7. package/ios/components/layer/style/MLRNStyle.m +1 -1
  8. package/lib/commonjs/utils/getStylePropertyType.js +1 -1
  9. package/lib/module/utils/getStylePropertyType.js +1 -1
  10. package/lib/typescript/commonjs/types/MapLibreRNStyles.d.ts +92 -59
  11. package/lib/typescript/commonjs/types/MapLibreRNStyles.d.ts.map +1 -1
  12. package/lib/typescript/module/types/MapLibreRNStyles.d.ts +92 -59
  13. package/lib/typescript/module/types/MapLibreRNStyles.d.ts.map +1 -1
  14. package/package.json +1 -1
  15. package/src/types/MapLibreRNStyles.ts +102 -119
  16. package/src/utils/getStylePropertyType.ts +1 -1
  17. package/android/src/main/java/org/maplibre/reactnative/components/layer/style/MLRNStyle.java +0 -76
  18. package/android/src/main/java/org/maplibre/reactnative/components/layer/style/MLRNStyleFactory.java +0 -2285
  19. package/android/src/main/java/org/maplibre/reactnative/components/layer/style/MLRNStyleFunctionParser.java +0 -94
  20. package/android/src/main/java/org/maplibre/reactnative/components/layer/style/MLRNStyleValue.java +0 -207
  21. package/android/src/main/java/org/maplibre/reactnative/events/AndroidCallbackEvent.java +0 -34
@@ -0,0 +1,159 @@
1
+ package org.maplibre.reactnative.components.layer.style
2
+
3
+ import com.facebook.react.bridge.Dynamic
4
+ import com.facebook.react.bridge.ReadableArray
5
+ import com.facebook.react.bridge.ReadableMap
6
+ import com.facebook.react.bridge.ReadableType
7
+ import com.facebook.react.bridge.WritableNativeMap
8
+ import org.maplibre.android.style.expressions.Expression
9
+ import org.maplibre.android.style.layers.TransitionOptions
10
+ import org.maplibre.reactnative.utils.ExpressionParser.fromTyped
11
+ import org.maplibre.reactnative.utils.ImageEntry
12
+
13
+ class MLRNStyleValue(
14
+ config: ReadableMap,
15
+ ) {
16
+ var type: String?
17
+ private set
18
+ private var isExpression = false
19
+ private var mExpression: Expression? = null
20
+ private var mPayload: ReadableMap?
21
+
22
+ var imageURI: String? = null
23
+ private set
24
+ private var isAddImage = false
25
+ var imageScale: Double = ImageEntry.DEFAULT_SCALE
26
+ private set
27
+
28
+ init {
29
+ this.type = config.getString("styletype")
30
+ mPayload = config.getMap("stylevalue")
31
+
32
+ if ("image" == this.type) {
33
+ imageScale = ImageEntry.DEFAULT_SCALE
34
+ if ("hashmap" == mPayload!!.getString("type")) {
35
+ val map = this.map
36
+ imageURI = map.getMap("uri")!!.getString("value")
37
+ if (map.getMap("scale") != null) {
38
+ imageScale = map.getMap("scale")!!.getDouble("value")
39
+ }
40
+ } else if ("string" == mPayload!!.getString("type")) {
41
+ val value = mPayload!!.getString("value")
42
+ if (value!!.contains("://")) {
43
+ imageURI = value
44
+ } else {
45
+ imageURI = null
46
+ isExpression = true
47
+ mExpression = Expression.literal(value)
48
+ }
49
+ }
50
+
51
+ isAddImage = imageURI != null
52
+ }
53
+
54
+ if (!isAddImage) {
55
+ val dynamic = mPayload!!.getDynamic("value")
56
+ if (dynamic.type == ReadableType.Array) {
57
+ val array = dynamic.asArray()
58
+ if (array!!.size() > 0 && mPayload!!.getString("type") == "array") {
59
+ val map = array.getMap(0)
60
+ if (map != null && map.getString("type") == "string") {
61
+ isExpression = true
62
+ mExpression = fromTyped(mPayload)
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ fun getInt(key: String): Int = mPayload!!.getInt(key)
70
+
71
+ fun getString(key: String): String = mPayload!!.getString(key)!!
72
+
73
+ fun getDouble(key: String): Double = mPayload!!.getDouble(key)
74
+
75
+ fun getFloat(key: String): Float = getDouble(key).toFloat()
76
+
77
+ fun getDynamic(key: String): Dynamic = mPayload!!.getDynamic(key)
78
+
79
+ fun getArray(key: String): ReadableArray? = mPayload!!.getArray(key)
80
+
81
+ fun getBoolean(key: String): Boolean = mPayload!!.getBoolean(key)
82
+
83
+ fun getFloatArray(key: String): Array<Float?> {
84
+ val arr = getArray(key)
85
+
86
+ val floatArr = arrayOfNulls<Float>(arr!!.size())
87
+ for (i in 0..<arr.size()) {
88
+ val item = arr.getMap(i)
89
+ floatArr[i] = item!!.getDouble("value").toFloat()
90
+ }
91
+
92
+ return floatArr
93
+ }
94
+
95
+ fun getStringArray(key: String): Array<String?> {
96
+ val arr = getArray(key)
97
+
98
+ val stringArr = arrayOfNulls<String>(arr!!.size())
99
+ for (i in 0..<arr.size()) {
100
+ val item = arr.getMap(i)
101
+ stringArr[i] = item!!.getString("value")
102
+ }
103
+
104
+ return stringArr
105
+ }
106
+
107
+ val map: ReadableMap
108
+ get() {
109
+ val result = WritableNativeMap()
110
+
111
+ if ("hashmap" == mPayload!!.getString("type")) {
112
+ val keyValues = mPayload!!.getArray("value")
113
+ for (i in 0..<keyValues!!.size()) {
114
+ val keyValue = keyValues.getArray(i)
115
+ val stringKey = keyValue!!.getMap(0)!!.getString("value")
116
+ val value = WritableNativeMap()
117
+ value.merge(keyValue.getMap(1)!!)
118
+ result.putMap(stringKey!!, value)
119
+ }
120
+ }
121
+
122
+ return result
123
+ }
124
+
125
+ fun getExpression(): Expression? = mExpression
126
+
127
+ fun isExpression(): Boolean = isExpression
128
+
129
+ fun shouldAddImage(): Boolean = isAddImage
130
+
131
+ val isImageStringValue: Boolean
132
+ get() = "string" == mPayload!!.getString("type")
133
+
134
+ fun getImageStringValue(): String? = mPayload!!.getString("value")
135
+
136
+ val transition: TransitionOptions?
137
+ get() {
138
+ if (this.type != "transition") {
139
+ return null
140
+ }
141
+ val config = this.map
142
+
143
+ var enablePlacementTransitions = true
144
+ if (config.hasKey("enablePlacementTransitions")) {
145
+ enablePlacementTransitions =
146
+ config.getMap("enablePlacementTransitions")!!.getBoolean("value")
147
+ }
148
+ var duration = 300
149
+ var delay = 0
150
+ if (config.hasKey("duration") && ReadableType.Map == config.getType("duration")) {
151
+ duration = config.getMap("duration")!!.getInt("value")
152
+ }
153
+ if (config.hasKey("delay") && ReadableType.Map == config.getType("delay")) {
154
+ delay = config.getMap("delay")!!.getInt("value")
155
+ }
156
+
157
+ return TransitionOptions(duration.toLong(), delay.toLong(), enablePlacementTransitions)
158
+ }
159
+ }
@@ -797,7 +797,9 @@ open class MLRNMapView(
797
797
 
798
798
  if (style != null && reactLightProps != null) {
799
799
  val light = style.light
800
- MLRNStyleFactory.setLightLayerStyle(light, MLRNStyle(context, reactLightProps, map))
800
+ if (light != null) {
801
+ MLRNStyleFactory.setLightLayerStyle(light, MLRNStyle(context, reactLightProps, map))
802
+ }
801
803
  }
802
804
  }
803
805
 
@@ -1,5 +1,5 @@
1
1
  // DO NOT MODIFY
2
- // This file is auto-generated from scripts/src/templates/MLRNStyle.h.ejs
2
+ // This file is auto-generated from scripts/src/templates/renderMLRNStyle.ts
3
3
 
4
4
  #import "MLRNStyle.h"
5
5
  #import "MLRNStyleValue.h"
@@ -1,5 +1,5 @@
1
1
  // DO NOT MODIFY
2
- // This file is auto-generated from scripts/src/templates/MLRNStyle.m.ejs
2
+ // This file is auto-generated from scripts/src/templates/renderMLRNStyle.ts
3
3
 
4
4
  #import "MLRNStyle.h"
5
5
  #import "MLRNImageLoader.h"
@@ -7,7 +7,7 @@ exports.getStylePropertyType = getStylePropertyType;
7
7
  var _index = require("./index.js");
8
8
  /* eslint-disable */
9
9
  // DO NOT MODIFY
10
- // This file is auto-generated from scripts/src/templates/getStylePropertyType.ts.ejs
10
+ // This file is auto-generated from scripts/src/templates/renderGetStylePropertyType.ts
11
11
 
12
12
  const StyleType = {
13
13
  Constant: "constant",
@@ -2,7 +2,7 @@
2
2
 
3
3
  /* eslint-disable */
4
4
  // DO NOT MODIFY
5
- // This file is auto-generated from scripts/src/templates/getStylePropertyType.ts.ejs
5
+ // This file is auto-generated from scripts/src/templates/renderGetStylePropertyType.ts
6
6
 
7
7
  import { isAndroid } from "./index.js";
8
8
  const StyleType = {