@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
@@ -1,94 +0,0 @@
1
- package org.maplibre.reactnative.components.layer.style;
2
-
3
- import com.facebook.react.bridge.Dynamic;
4
- import com.facebook.react.bridge.NoSuchKeyException;
5
- import com.facebook.react.bridge.ReadableArray;
6
- import com.facebook.react.bridge.ReadableMap;
7
- import com.facebook.react.bridge.ReadableType;
8
-
9
- import org.maplibre.android.style.layers.PropertyValue;
10
-
11
- import java.util.ArrayList;
12
- import java.util.List;
13
-
14
- public abstract class MLRNStyleFunctionParser<T, V> {
15
- private MLRNStyleValue mStyleValue;
16
-
17
- public MLRNStyleFunctionParser(MLRNStyleValue styleValue) {
18
- mStyleValue = styleValue;
19
- }
20
-
21
- public List<StopConfig> getRawStops() {
22
- ReadableArray readableArrayRawStops = mStyleValue.getArray("stops");
23
-
24
- List<StopConfig> rawStops = new ArrayList<>();
25
-
26
- for (int i = 0; i < readableArrayRawStops.size(); i++) {
27
- ReadableArray rawStop = readableArrayRawStops.getArray(i);
28
-
29
- ReadableMap jsStopKey = rawStop.getMap(0);
30
- ReadableMap jsStopValue = rawStop.getMap(1);
31
- MLRNStyleValue innerStyleValue = new MLRNStyleValue(jsStopValue);
32
-
33
- Object propertyValue = null;
34
- try {
35
- Dynamic dynamicPropertyValue = innerStyleValue.getDynamic("propertyValue");
36
- ReadableType type = dynamicPropertyValue.getType();
37
-
38
- if (type.equals(ReadableType.Number)) {
39
- propertyValue = dynamicPropertyValue.asDouble();
40
- } else if (type.equals(ReadableType.Boolean)){
41
- propertyValue = dynamicPropertyValue.asBoolean();
42
- } else {
43
- propertyValue = dynamicPropertyValue.asString();
44
- }
45
- } catch (NoSuchKeyException e) {
46
- // not a zoom-property value
47
- }
48
-
49
- StopConfig config;
50
- if (propertyValue != null) {
51
- config = new StopConfig(getStopKey(jsStopKey), getRawStopValue(innerStyleValue), propertyValue);
52
- } else {
53
- config = new StopConfig(getStopKey(jsStopKey), getRawStopValue(innerStyleValue));
54
- }
55
-
56
- rawStops.add(config);
57
- }
58
-
59
- return rawStops;
60
- }
61
-
62
- protected abstract T getRawStopValue (MLRNStyleValue styleValue);
63
- protected abstract PropertyValue<V> getStopValue(T value);
64
-
65
- private Object getStopKey(ReadableMap jsStopKey) {
66
- String payloadKey = "value";
67
- String type = jsStopKey.getString("type");
68
-
69
- switch (type) {
70
- case "number":
71
- return jsStopKey.getDouble(payloadKey);
72
- case "boolean":
73
- return jsStopKey.getBoolean(payloadKey);
74
- default:
75
- return jsStopKey.getString(payloadKey);
76
- }
77
- }
78
-
79
- private class StopConfig {
80
- Object propertyValue;
81
- T value;
82
- Object key;
83
-
84
- StopConfig(Object key, T value) {
85
- this(key, value, null);
86
- }
87
-
88
- StopConfig(Object key, T value, Object propertyValue) {
89
- this.key = key;
90
- this.value = value;
91
- this.propertyValue = propertyValue;
92
- }
93
- }
94
- }
@@ -1,207 +0,0 @@
1
- package org.maplibre.reactnative.components.layer.style;
2
-
3
- import androidx.annotation.NonNull;
4
-
5
- import com.facebook.react.bridge.Dynamic;
6
- import com.facebook.react.bridge.ReadableArray;
7
- import com.facebook.react.bridge.ReadableMap;
8
- import com.facebook.react.bridge.ReadableType;
9
- import com.facebook.react.bridge.WritableNativeMap;
10
-
11
- import org.maplibre.android.style.expressions.Expression;
12
- import org.maplibre.android.style.layers.TransitionOptions;
13
- import org.maplibre.reactnative.utils.ExpressionParser;
14
- import org.maplibre.reactnative.utils.ImageEntry;
15
-
16
- public class MLRNStyleValue {
17
-
18
- private String mType;
19
- private boolean isExpression;
20
- private Expression mExpression;
21
- private ReadableMap mPayload;
22
-
23
- private String imageURI = "";
24
- private boolean isAddImage;
25
- private Double imageScale = ImageEntry.DEFAULT_SCALE;
26
-
27
- public static final int InterpolationModeExponential = 100;
28
- public static final int InterpolationModeInterval = 101;
29
- public static final int InterpolationModeCategorical = 102;
30
- public static final int InterpolationModeIdentity = 103;
31
-
32
- public MLRNStyleValue(@NonNull ReadableMap config) {
33
- mType = config.getString("styletype");
34
- mPayload = config.getMap("stylevalue");
35
-
36
- if ("image".equals(mType)) {
37
- imageScale = ImageEntry.DEFAULT_SCALE;
38
- if ("hashmap".equals(mPayload.getString("type"))) {
39
- ReadableMap map = getMap();
40
- imageURI = map.getMap("uri").getString("value");
41
- if (map.getMap("scale") != null) {
42
- imageScale = map.getMap("scale").getDouble("value");
43
- }
44
- } else if ("string".equals(mPayload.getString("type"))) {
45
- String value = mPayload.getString("value");
46
- if (value.contains("://")) {
47
- imageURI = value;
48
- } else {
49
- imageURI = null;
50
- isExpression = true;
51
- mExpression = Expression.literal(value);
52
- }
53
- } else {
54
- imageURI = null;
55
- }
56
- isAddImage = imageURI != null;
57
- if (isAddImage) { return; }
58
- }
59
-
60
- Dynamic dynamic = mPayload.getDynamic("value");
61
- if (dynamic.getType().equals(ReadableType.Array)) {
62
- ReadableArray array = dynamic.asArray();
63
- if (array.size() > 0 && mPayload.getString("type").equals("array")) {
64
- ReadableMap map = array.getMap(0);
65
- if (map != null && map.getString("type").equals("string")) {
66
- isExpression = true;
67
- mExpression = ExpressionParser.fromTyped(mPayload);
68
- }
69
- }
70
- }
71
- }
72
-
73
- private boolean isTokenizedValue(String value) {
74
- return (value.startsWith("{") && value.endsWith("}"));
75
- }
76
-
77
- public String getType() {
78
- return mType;
79
- }
80
-
81
- public boolean isFunction() {
82
- return mType.equals("function");
83
- }
84
-
85
- public int getInt(String key) {
86
- return mPayload.getInt(key);
87
- }
88
-
89
- public String getString(String key) {
90
- return mPayload.getString(key);
91
- }
92
-
93
- public Double getDouble(String key) {
94
- return mPayload.getDouble(key);
95
- }
96
-
97
- public Float getFloat(String key) {
98
- return getDouble(key).floatValue();
99
- }
100
-
101
- public Dynamic getDynamic(String key) {
102
- return mPayload.getDynamic(key);
103
- }
104
-
105
- public ReadableArray getArray(String key) {
106
- return mPayload.getArray(key);
107
- }
108
-
109
- public Boolean getBoolean(String key) {
110
- return mPayload.getBoolean(key);
111
- }
112
-
113
- public Float[] getFloatArray(String key) {
114
- ReadableArray arr = getArray(key);
115
-
116
- Float[] floatArr = new Float[arr.size()];
117
- for (int i = 0; i < arr.size(); i++) {
118
- ReadableMap item = arr.getMap(i);
119
- floatArr[i] = (float) item.getDouble("value");
120
- }
121
-
122
- return floatArr;
123
- }
124
-
125
- public String[] getStringArray(String key) {
126
- ReadableArray arr = getArray(key);
127
-
128
- String[] stringArr = new String[arr.size()];
129
- for (int i = 0; i < arr.size(); i++) {
130
- ReadableMap item = arr.getMap(i);
131
- stringArr[i] = item.getString("value");
132
- }
133
-
134
- return stringArr;
135
- }
136
-
137
- public ReadableMap getMap() {
138
- if ("hashmap".equals(mPayload.getString("type"))) {
139
- ReadableArray keyValues = mPayload.getArray("value");
140
- WritableNativeMap result = new WritableNativeMap();
141
- for (int i = 0; i < keyValues.size(); i++) {
142
- ReadableArray keyValue = keyValues.getArray(i);
143
- String stringKey = keyValue.getMap(0).getString("value");
144
- WritableNativeMap value = new WritableNativeMap();
145
- value.merge(keyValue.getMap(1));
146
- result.putMap(stringKey, value);
147
- }
148
- return result;
149
- }
150
-
151
- return null;
152
- }
153
-
154
- public ReadableMap getMap(String _key) {
155
- return getMap();
156
- }
157
-
158
- public Expression getExpression() {
159
- return mExpression;
160
- }
161
-
162
- public boolean isExpression() {
163
- return isExpression;
164
- }
165
-
166
- public boolean shouldAddImage() {
167
- return isAddImage;
168
- }
169
-
170
- public Boolean isImageStringValue() {
171
- return "string".equals(mPayload.getString("type"));
172
- }
173
-
174
- public String getImageStringValue() {
175
- return mPayload.getString("value");
176
- }
177
-
178
- public String getImageURI() {
179
- return imageURI;
180
- }
181
-
182
- public double getImageScale() {
183
- return imageScale;
184
- }
185
-
186
- public TransitionOptions getTransition() {
187
- if (!mType.equals("transition")) {
188
- return null;
189
- }
190
- ReadableMap config = getMap(MLRNStyleFactory.VALUE_KEY);
191
-
192
- boolean enablePlacementTransitions = true;
193
- if (config.hasKey("enablePlacementTransitions")) {
194
- enablePlacementTransitions = config.getMap("enablePlacementTransitions").getBoolean("value");
195
- }
196
- int duration = 300;
197
- int delay = 0;
198
- if (config.hasKey("duration") && ReadableType.Map.equals(config.getType("duration"))) {
199
- duration = config.getMap("duration").getInt("value");
200
- }
201
- if (config.hasKey("delay") && ReadableType.Map.equals(config.getType("delay"))) {
202
- delay = config.getMap("delay").getInt("value");
203
- }
204
-
205
- return new TransitionOptions(duration, delay, enablePlacementTransitions);
206
- }
207
- }
@@ -1,34 +0,0 @@
1
- package org.maplibre.reactnative.events;
2
-
3
- import android.view.View;
4
-
5
- import com.facebook.react.bridge.WritableArray;
6
- import com.facebook.react.bridge.WritableMap;
7
- import org.maplibre.reactnative.events.constants.EventKeys;
8
-
9
- public class AndroidCallbackEvent extends AbstractEvent {
10
- private final WritableMap mPayload;
11
-
12
- public AndroidCallbackEvent(View view, String callbackID, WritableMap payload) {
13
- super(view, callbackID);
14
- mPayload = payload;
15
- }
16
-
17
- @Override
18
- public String getKey() {
19
- return EventKeys.MAP_ANDROID_CALLBACK;
20
- }
21
-
22
- @Override
23
- public WritableMap getPayload() {
24
- return mPayload;
25
- }
26
-
27
- @Override
28
- public boolean canCoalesce() {
29
- // Make sure EventDispatcher never merges EventKeys.MAP_ANDROID_CALLBACK events.
30
- // These events are couples to unique callbacks references (promises) on the JS side which
31
- // each expect response with their corresponding callbackID
32
- return false;
33
- }
34
- }