@lugg/maps 0.2.0-alpha.23 → 0.2.0-alpha.24
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.
- package/android/src/main/java/com/luggmaps/LuggMapView.kt +43 -3
- package/android/src/main/java/com/luggmaps/LuggMapViewManager.kt +2 -2
- package/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +9 -15
- package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +3 -1
- package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +5 -3
- package/ios/LuggMapView.mm +27 -45
- package/package.json +1 -1
|
@@ -4,8 +4,10 @@ import android.annotation.SuppressLint
|
|
|
4
4
|
import android.view.View
|
|
5
5
|
import android.view.View.VISIBLE
|
|
6
6
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
7
|
+
import com.facebook.react.util.RNLog
|
|
7
8
|
import com.facebook.react.views.view.ReactViewGroup
|
|
8
9
|
import com.google.android.gms.maps.model.LatLng
|
|
10
|
+
import com.luggmaps.core.EdgeInsets
|
|
9
11
|
import com.luggmaps.core.GoogleMapProvider
|
|
10
12
|
import com.luggmaps.core.MapProvider
|
|
11
13
|
import com.luggmaps.core.MapProviderDelegate
|
|
@@ -37,11 +39,20 @@ class LuggMapView(private val reactContext: ThemedReactContext) :
|
|
|
37
39
|
private var provider: MapProvider? = null
|
|
38
40
|
private var mapWrapperView: LuggMapWrapperView? = null
|
|
39
41
|
|
|
40
|
-
// Cached
|
|
42
|
+
// Cached props (applied during initializeProvider)
|
|
41
43
|
private var mapId: String = GoogleMapProvider.DEMO_MAP_ID
|
|
42
44
|
private var initialLatitude: Double = 37.78
|
|
43
45
|
private var initialLongitude: Double = -122.43
|
|
44
46
|
private var initialZoom: Float = 14f
|
|
47
|
+
private var theme: String = "system"
|
|
48
|
+
private var zoomEnabled: Boolean = true
|
|
49
|
+
private var scrollEnabled: Boolean = true
|
|
50
|
+
private var rotateEnabled: Boolean = true
|
|
51
|
+
private var pitchEnabled: Boolean = true
|
|
52
|
+
private var userLocationEnabled: Boolean = false
|
|
53
|
+
private var minZoom: Double? = null
|
|
54
|
+
private var maxZoom: Double? = null
|
|
55
|
+
private var padding: EdgeInsets = EdgeInsets()
|
|
45
56
|
|
|
46
57
|
// region View Lifecycle
|
|
47
58
|
|
|
@@ -97,6 +108,8 @@ class LuggMapView(private val reactContext: ThemedReactContext) :
|
|
|
97
108
|
google.delegate = this
|
|
98
109
|
provider = google
|
|
99
110
|
|
|
111
|
+
applyProps()
|
|
112
|
+
|
|
100
113
|
google.initializeMap(mapWrapperView!!, initialLatitude, initialLongitude, initialZoom)
|
|
101
114
|
|
|
102
115
|
// Flush children mounted before provider was created
|
|
@@ -128,6 +141,24 @@ class LuggMapView(private val reactContext: ThemedReactContext) :
|
|
|
128
141
|
|
|
129
142
|
// region Property Setters
|
|
130
143
|
|
|
144
|
+
private fun applyProps() {
|
|
145
|
+
provider?.setZoomEnabled(zoomEnabled)
|
|
146
|
+
provider?.setScrollEnabled(scrollEnabled)
|
|
147
|
+
provider?.setRotateEnabled(rotateEnabled)
|
|
148
|
+
provider?.setPitchEnabled(pitchEnabled)
|
|
149
|
+
provider?.setUserLocationEnabled(userLocationEnabled)
|
|
150
|
+
provider?.setTheme(theme)
|
|
151
|
+
minZoom?.let { provider?.setMinZoom(it) }
|
|
152
|
+
maxZoom?.let { provider?.setMaxZoom(it) }
|
|
153
|
+
provider?.setPadding(padding)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
fun setProvider(value: String?) {
|
|
157
|
+
if (value != null && value != "google") {
|
|
158
|
+
RNLog.w(reactContext, "LuggMapView: Only Google Maps is supported on Android")
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
131
162
|
fun setMapId(value: String?) {
|
|
132
163
|
if (value.isNullOrEmpty()) return
|
|
133
164
|
mapId = value
|
|
@@ -143,39 +174,48 @@ class LuggMapView(private val reactContext: ThemedReactContext) :
|
|
|
143
174
|
}
|
|
144
175
|
|
|
145
176
|
fun setZoomEnabled(enabled: Boolean) {
|
|
177
|
+
zoomEnabled = enabled
|
|
146
178
|
provider?.setZoomEnabled(enabled)
|
|
147
179
|
}
|
|
148
180
|
|
|
149
181
|
fun setScrollEnabled(enabled: Boolean) {
|
|
182
|
+
scrollEnabled = enabled
|
|
150
183
|
provider?.setScrollEnabled(enabled)
|
|
151
184
|
}
|
|
152
185
|
|
|
153
186
|
fun setRotateEnabled(enabled: Boolean) {
|
|
187
|
+
rotateEnabled = enabled
|
|
154
188
|
provider?.setRotateEnabled(enabled)
|
|
155
189
|
}
|
|
156
190
|
|
|
157
191
|
fun setPitchEnabled(enabled: Boolean) {
|
|
192
|
+
pitchEnabled = enabled
|
|
158
193
|
provider?.setPitchEnabled(enabled)
|
|
159
194
|
}
|
|
160
195
|
|
|
161
196
|
fun setUserLocationEnabled(enabled: Boolean) {
|
|
197
|
+
userLocationEnabled = enabled
|
|
162
198
|
provider?.setUserLocationEnabled(enabled)
|
|
163
199
|
}
|
|
164
200
|
|
|
165
201
|
fun setMinZoom(zoom: Double) {
|
|
202
|
+
minZoom = zoom
|
|
166
203
|
provider?.setMinZoom(zoom)
|
|
167
204
|
}
|
|
168
205
|
|
|
169
206
|
fun setMaxZoom(zoom: Double) {
|
|
207
|
+
maxZoom = zoom
|
|
170
208
|
provider?.setMaxZoom(zoom)
|
|
171
209
|
}
|
|
172
210
|
|
|
173
211
|
fun setTheme(value: String) {
|
|
212
|
+
theme = value
|
|
174
213
|
provider?.setTheme(value)
|
|
175
214
|
}
|
|
176
215
|
|
|
177
|
-
fun
|
|
178
|
-
|
|
216
|
+
fun setPadding(top: Int, left: Int, bottom: Int, right: Int) {
|
|
217
|
+
padding = EdgeInsets(top, left, bottom, right)
|
|
218
|
+
provider?.setPadding(padding)
|
|
179
219
|
}
|
|
180
220
|
|
|
181
221
|
// endregion
|
|
@@ -66,7 +66,7 @@ class LuggMapViewManager :
|
|
|
66
66
|
|
|
67
67
|
@ReactProp(name = "provider")
|
|
68
68
|
override fun setProvider(view: LuggMapView, value: String?) {
|
|
69
|
-
|
|
69
|
+
view.setProvider(value)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
@ReactProp(name = "mapId")
|
|
@@ -135,7 +135,7 @@ class LuggMapViewManager :
|
|
|
135
135
|
val left = if (it.hasKey("left")) it.getDouble("left").toFloat().dpToPx().toInt() else 0
|
|
136
136
|
val bottom = if (it.hasKey("bottom")) it.getDouble("bottom").toFloat().dpToPx().toInt() else 0
|
|
137
137
|
val right = if (it.hasKey("right")) it.getDouble("right").toFloat().dpToPx().toInt() else 0
|
|
138
|
-
view.
|
|
138
|
+
view.setPadding(top, left, bottom, right)
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
|
@@ -62,10 +62,7 @@ class GoogleMapProvider(private val context: Context) :
|
|
|
62
62
|
private var theme: String = "system"
|
|
63
63
|
|
|
64
64
|
// Padding
|
|
65
|
-
private var
|
|
66
|
-
private var paddingLeft: Int = 0
|
|
67
|
-
private var paddingBottom: Int = 0
|
|
68
|
-
private var paddingRight: Int = 0
|
|
65
|
+
private var padding: EdgeInsets = EdgeInsets()
|
|
69
66
|
|
|
70
67
|
// region MapProvider
|
|
71
68
|
|
|
@@ -202,11 +199,8 @@ class GoogleMapProvider(private val context: Context) :
|
|
|
202
199
|
}
|
|
203
200
|
}
|
|
204
201
|
|
|
205
|
-
override fun
|
|
206
|
-
|
|
207
|
-
paddingLeft = left
|
|
208
|
-
paddingBottom = bottom
|
|
209
|
-
paddingRight = right
|
|
202
|
+
override fun setPadding(padding: EdgeInsets) {
|
|
203
|
+
this.padding = padding
|
|
210
204
|
applyPadding()
|
|
211
205
|
}
|
|
212
206
|
|
|
@@ -425,10 +419,10 @@ class GoogleMapProvider(private val context: Context) :
|
|
|
425
419
|
val right = paddingRight.toFloat().dpToPx().toInt()
|
|
426
420
|
|
|
427
421
|
map.setPadding(
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
422
|
+
padding.left + left,
|
|
423
|
+
padding.top + top,
|
|
424
|
+
padding.right + right,
|
|
425
|
+
padding.bottom + bottom
|
|
432
426
|
)
|
|
433
427
|
|
|
434
428
|
val cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 0)
|
|
@@ -439,7 +433,7 @@ class GoogleMapProvider(private val context: Context) :
|
|
|
439
433
|
else -> map.moveCamera(cameraUpdate)
|
|
440
434
|
}
|
|
441
435
|
|
|
442
|
-
map.setPadding(
|
|
436
|
+
map.setPadding(padding.left, padding.top, padding.right, padding.bottom)
|
|
443
437
|
}
|
|
444
438
|
|
|
445
439
|
// endregion
|
|
@@ -463,7 +457,7 @@ class GoogleMapProvider(private val context: Context) :
|
|
|
463
457
|
}
|
|
464
458
|
|
|
465
459
|
private fun applyPadding() {
|
|
466
|
-
googleMap?.setPadding(
|
|
460
|
+
googleMap?.setPadding(padding.left, padding.top, padding.right, padding.bottom)
|
|
467
461
|
}
|
|
468
462
|
|
|
469
463
|
private fun applyTheme() {
|
|
@@ -4,6 +4,8 @@ import android.view.View
|
|
|
4
4
|
import com.luggmaps.LuggMarkerView
|
|
5
5
|
import com.luggmaps.LuggPolylineView
|
|
6
6
|
|
|
7
|
+
data class EdgeInsets(val top: Int = 0, val left: Int = 0, val bottom: Int = 0, val right: Int = 0)
|
|
8
|
+
|
|
7
9
|
interface MapProviderDelegate {
|
|
8
10
|
fun mapProviderDidReady()
|
|
9
11
|
fun mapProviderDidMoveCamera(latitude: Double, longitude: Double, zoom: Float, gesture: Boolean)
|
|
@@ -26,7 +28,7 @@ interface MapProvider {
|
|
|
26
28
|
fun setTheme(value: String)
|
|
27
29
|
fun setMinZoom(zoom: Double)
|
|
28
30
|
fun setMaxZoom(zoom: Double)
|
|
29
|
-
fun
|
|
31
|
+
fun setPadding(padding: EdgeInsets)
|
|
30
32
|
|
|
31
33
|
// Children
|
|
32
34
|
fun addMarkerView(markerView: LuggMarkerView)
|
|
@@ -91,10 +91,10 @@ class PolylineAnimator {
|
|
|
91
91
|
computeCumulativeDistances()
|
|
92
92
|
|
|
93
93
|
val trailLength = animatedOptions.trailLength.coerceIn(0.01f, 1f)
|
|
94
|
-
val
|
|
94
|
+
val maxProgress = if (trailLength < 1f) 1f else 2.15f
|
|
95
95
|
|
|
96
|
-
animator = ValueAnimator.ofFloat(0f,
|
|
97
|
-
duration = animatedOptions.duration
|
|
96
|
+
animator = ValueAnimator.ofFloat(0f, maxProgress).apply {
|
|
97
|
+
duration = (animatedOptions.duration * maxProgress).toLong()
|
|
98
98
|
startDelay = animatedOptions.delay
|
|
99
99
|
repeatCount = ValueAnimator.INFINITE
|
|
100
100
|
interpolator = LinearInterpolator()
|
|
@@ -232,6 +232,8 @@ class PolylineAnimator {
|
|
|
232
232
|
reusablePoints.add(endCoord)
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
if (reusablePoints.size < 2) return
|
|
236
|
+
|
|
235
237
|
poly.points = reusablePoints
|
|
236
238
|
|
|
237
239
|
if (strokeColors.size <= 1) {
|
package/ios/LuggMapView.mm
CHANGED
|
@@ -107,7 +107,7 @@ using namespace luggmaps::events;
|
|
|
107
107
|
[super didMoveToWindow];
|
|
108
108
|
if (self.window) {
|
|
109
109
|
if (!_provider && _mapWrapperView) {
|
|
110
|
-
[self
|
|
110
|
+
[self initializeProvider];
|
|
111
111
|
}
|
|
112
112
|
[_provider resumeAnimations];
|
|
113
113
|
} else {
|
|
@@ -124,9 +124,9 @@ using namespace luggmaps::events;
|
|
|
124
124
|
_initialized = NO;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
#pragma mark -
|
|
127
|
+
#pragma mark - Provider Initialization
|
|
128
128
|
|
|
129
|
-
- (void)
|
|
129
|
+
- (void)initializeProvider {
|
|
130
130
|
if (_provider || !_mapWrapperView)
|
|
131
131
|
return;
|
|
132
132
|
|
|
@@ -144,14 +144,7 @@ using namespace luggmaps::events;
|
|
|
144
144
|
_provider.delegate = self;
|
|
145
145
|
|
|
146
146
|
// Apply cached props before initialization
|
|
147
|
-
[
|
|
148
|
-
[_provider setScrollEnabled:_scrollEnabled];
|
|
149
|
-
[_provider setRotateEnabled:_rotateEnabled];
|
|
150
|
-
[_provider setPitchEnabled:_pitchEnabled];
|
|
151
|
-
[_provider setUserLocationEnabled:_userLocationEnabled];
|
|
152
|
-
[_provider setTheme:_theme];
|
|
153
|
-
[_provider setMinZoom:_minZoom];
|
|
154
|
-
[_provider setMaxZoom:_maxZoom];
|
|
147
|
+
[self applyProps];
|
|
155
148
|
|
|
156
149
|
CLLocationCoordinate2D coordinate =
|
|
157
150
|
CLLocationCoordinate2DMake(viewProps.initialCoordinate.latitude,
|
|
@@ -199,6 +192,17 @@ using namespace luggmaps::events;
|
|
|
199
192
|
|
|
200
193
|
#pragma mark - Property Setters
|
|
201
194
|
|
|
195
|
+
- (void)applyProps {
|
|
196
|
+
[_provider setZoomEnabled:_zoomEnabled];
|
|
197
|
+
[_provider setScrollEnabled:_scrollEnabled];
|
|
198
|
+
[_provider setRotateEnabled:_rotateEnabled];
|
|
199
|
+
[_provider setPitchEnabled:_pitchEnabled];
|
|
200
|
+
[_provider setUserLocationEnabled:_userLocationEnabled];
|
|
201
|
+
[_provider setTheme:_theme];
|
|
202
|
+
[_provider setMinZoom:_minZoom];
|
|
203
|
+
[_provider setMaxZoom:_maxZoom];
|
|
204
|
+
}
|
|
205
|
+
|
|
202
206
|
- (void)updateProps:(Props::Shared const &)props
|
|
203
207
|
oldProps:(Props::Shared const &)oldProps {
|
|
204
208
|
const auto &oldViewProps =
|
|
@@ -206,7 +210,6 @@ using namespace luggmaps::events;
|
|
|
206
210
|
const auto &newViewProps =
|
|
207
211
|
*std::static_pointer_cast<LuggMapViewProps const>(props);
|
|
208
212
|
|
|
209
|
-
// Capture provider and mapId before content is created
|
|
210
213
|
_providerType = newViewProps.provider;
|
|
211
214
|
|
|
212
215
|
NSString *newMapId =
|
|
@@ -215,12 +218,22 @@ using namespace luggmaps::events;
|
|
|
215
218
|
_mapId = newMapId;
|
|
216
219
|
}
|
|
217
220
|
|
|
218
|
-
// Cache
|
|
221
|
+
// Cache props
|
|
219
222
|
_zoomEnabled = newViewProps.zoomEnabled;
|
|
220
223
|
_scrollEnabled = newViewProps.scrollEnabled;
|
|
221
224
|
_rotateEnabled = newViewProps.rotateEnabled;
|
|
222
225
|
_pitchEnabled = newViewProps.pitchEnabled;
|
|
223
226
|
_userLocationEnabled = newViewProps.userLocationEnabled;
|
|
227
|
+
_minZoom = newViewProps.minZoom;
|
|
228
|
+
_maxZoom = newViewProps.maxZoom;
|
|
229
|
+
|
|
230
|
+
if (newViewProps.theme == LuggMapViewTheme::Dark) {
|
|
231
|
+
_theme = @"dark";
|
|
232
|
+
} else if (newViewProps.theme == LuggMapViewTheme::Light) {
|
|
233
|
+
_theme = @"light";
|
|
234
|
+
} else {
|
|
235
|
+
_theme = @"system";
|
|
236
|
+
}
|
|
224
237
|
|
|
225
238
|
UIEdgeInsets oldPadding = _padding;
|
|
226
239
|
_padding =
|
|
@@ -228,39 +241,8 @@ using namespace luggmaps::events;
|
|
|
228
241
|
newViewProps.padding.bottom, newViewProps.padding.right);
|
|
229
242
|
|
|
230
243
|
if (_provider) {
|
|
231
|
-
[
|
|
232
|
-
[_provider setScrollEnabled:_scrollEnabled];
|
|
233
|
-
[_provider setRotateEnabled:_rotateEnabled];
|
|
234
|
-
[_provider setPitchEnabled:_pitchEnabled];
|
|
235
|
-
[_provider setUserLocationEnabled:_userLocationEnabled];
|
|
236
|
-
|
|
237
|
-
if (oldViewProps.theme != newViewProps.theme) {
|
|
238
|
-
NSString *theme;
|
|
239
|
-
if (newViewProps.theme == LuggMapViewTheme::Dark) {
|
|
240
|
-
theme = @"dark";
|
|
241
|
-
} else if (newViewProps.theme == LuggMapViewTheme::Light) {
|
|
242
|
-
theme = @"light";
|
|
243
|
-
} else {
|
|
244
|
-
theme = @"system";
|
|
245
|
-
}
|
|
246
|
-
_theme = theme;
|
|
247
|
-
[_provider setTheme:_theme];
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
[_provider setMinZoom:newViewProps.minZoom];
|
|
251
|
-
[_provider setMaxZoom:newViewProps.maxZoom];
|
|
244
|
+
[self applyProps];
|
|
252
245
|
[_provider setPadding:_padding oldPadding:oldPadding];
|
|
253
|
-
} else {
|
|
254
|
-
// Cache theme for later
|
|
255
|
-
if (newViewProps.theme == LuggMapViewTheme::Dark) {
|
|
256
|
-
_theme = @"dark";
|
|
257
|
-
} else if (newViewProps.theme == LuggMapViewTheme::Light) {
|
|
258
|
-
_theme = @"light";
|
|
259
|
-
} else {
|
|
260
|
-
_theme = @"system";
|
|
261
|
-
}
|
|
262
|
-
_minZoom = newViewProps.minZoom;
|
|
263
|
-
_maxZoom = newViewProps.maxZoom;
|
|
264
246
|
}
|
|
265
247
|
|
|
266
248
|
[super updateProps:props oldProps:oldProps];
|