@lugg/maps 0.2.0-alpha.3 → 0.2.0-alpha.30

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 (124) hide show
  1. package/README.md +21 -3
  2. package/android/src/main/java/com/luggmaps/LuggMapView.kt +265 -0
  3. package/android/src/main/java/com/luggmaps/{LuggGoogleMapViewManager.kt → LuggMapViewManager.kt} +75 -36
  4. package/android/src/main/java/com/luggmaps/LuggMapWrapperView.kt +6 -5
  5. package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +136 -14
  6. package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +21 -0
  7. package/android/src/main/java/com/luggmaps/LuggPackage.kt +1 -4
  8. package/android/src/main/java/com/luggmaps/LuggPolylineView.kt +16 -0
  9. package/android/src/main/java/com/luggmaps/LuggPolylineViewManager.kt +22 -0
  10. package/android/src/main/java/com/luggmaps/{LuggGoogleMapView.kt → core/GoogleMapProvider.kt} +251 -241
  11. package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +55 -0
  12. package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +163 -52
  13. package/ios/LuggMapView.h +9 -0
  14. package/ios/LuggMapView.mm +312 -0
  15. package/ios/LuggMarkerView.h +9 -0
  16. package/ios/LuggMarkerView.mm +79 -0
  17. package/ios/LuggPolylineView.h +4 -0
  18. package/ios/LuggPolylineView.mm +23 -0
  19. package/ios/core/AppleMapProvider.h +15 -0
  20. package/ios/core/AppleMapProvider.mm +664 -0
  21. package/ios/core/GMSPolylineAnimator.h +3 -0
  22. package/ios/core/GMSPolylineAnimator.m +175 -40
  23. package/ios/core/GoogleMapProvider.h +13 -0
  24. package/ios/core/GoogleMapProvider.mm +513 -0
  25. package/ios/core/MKPolylineAnimator.h +4 -0
  26. package/ios/core/MKPolylineAnimator.m +224 -68
  27. package/ios/core/MapProviderDelegate.h +72 -0
  28. package/ios/core/PolylineAnimatorBase.h +24 -1
  29. package/ios/core/PolylineAnimatorBase.m +82 -19
  30. package/ios/extensions/MKMapView+Zoom.h +2 -0
  31. package/ios/extensions/MKMapView+Zoom.m +14 -4
  32. package/lib/module/MapProvider.js +13 -0
  33. package/lib/module/MapProvider.js.map +1 -0
  34. package/lib/module/MapProvider.types.js +4 -0
  35. package/lib/module/MapProvider.types.js.map +1 -0
  36. package/lib/module/MapProvider.web.js +20 -0
  37. package/lib/module/MapProvider.web.js.map +1 -0
  38. package/lib/module/MapView.js +29 -16
  39. package/lib/module/MapView.js.map +1 -1
  40. package/lib/module/MapView.web.js +290 -0
  41. package/lib/module/MapView.web.js.map +1 -0
  42. package/lib/module/components/Marker.js +19 -2
  43. package/lib/module/components/Marker.js.map +1 -1
  44. package/lib/module/components/Marker.web.js +33 -0
  45. package/lib/module/components/Marker.web.js.map +1 -0
  46. package/lib/module/components/Polyline.js +17 -4
  47. package/lib/module/components/Polyline.js.map +1 -1
  48. package/lib/module/components/Polyline.web.js +229 -0
  49. package/lib/module/components/Polyline.web.js.map +1 -0
  50. package/lib/module/components/index.js +2 -2
  51. package/lib/module/components/index.js.map +1 -1
  52. package/lib/module/components/index.web.js +5 -0
  53. package/lib/module/components/index.web.js.map +1 -0
  54. package/lib/module/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +19 -7
  55. package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +7 -1
  56. package/lib/module/fabric/LuggPolylineViewNativeComponent.ts +8 -0
  57. package/lib/module/index.js +4 -2
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/index.web.js +7 -0
  60. package/lib/module/index.web.js.map +1 -0
  61. package/lib/typescript/src/MapProvider.d.ts +8 -0
  62. package/lib/typescript/src/MapProvider.d.ts.map +1 -0
  63. package/lib/typescript/src/MapProvider.types.d.ts +16 -0
  64. package/lib/typescript/src/MapProvider.types.d.ts.map +1 -0
  65. package/lib/typescript/src/MapProvider.web.d.ts +11 -0
  66. package/lib/typescript/src/MapProvider.web.d.ts.map +1 -0
  67. package/lib/typescript/src/MapView.d.ts +4 -4
  68. package/lib/typescript/src/MapView.d.ts.map +1 -1
  69. package/lib/typescript/src/MapView.types.d.ts +23 -7
  70. package/lib/typescript/src/MapView.types.d.ts.map +1 -1
  71. package/lib/typescript/src/MapView.web.d.ts +3 -0
  72. package/lib/typescript/src/MapView.web.d.ts.map +1 -0
  73. package/lib/typescript/src/components/Marker.d.ts +25 -1
  74. package/lib/typescript/src/components/Marker.d.ts.map +1 -1
  75. package/lib/typescript/src/components/Marker.web.d.ts +3 -0
  76. package/lib/typescript/src/components/Marker.web.d.ts.map +1 -0
  77. package/lib/typescript/src/components/Polyline.d.ts +36 -1
  78. package/lib/typescript/src/components/Polyline.d.ts.map +1 -1
  79. package/lib/typescript/src/components/Polyline.web.d.ts +3 -0
  80. package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -0
  81. package/lib/typescript/src/components/index.d.ts +4 -2
  82. package/lib/typescript/src/components/index.d.ts.map +1 -1
  83. package/lib/typescript/src/components/index.web.d.ts +5 -0
  84. package/lib/typescript/src/components/index.web.d.ts.map +1 -0
  85. package/lib/typescript/src/fabric/{LuggGoogleMapViewNativeComponent.d.ts → LuggMapViewNativeComponent.d.ts} +8 -4
  86. package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -0
  87. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +4 -1
  88. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
  89. package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts +7 -0
  90. package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts.map +1 -1
  91. package/lib/typescript/src/index.d.ts +8 -3
  92. package/lib/typescript/src/index.d.ts.map +1 -1
  93. package/lib/typescript/src/index.web.d.ts +10 -0
  94. package/lib/typescript/src/index.web.d.ts.map +1 -0
  95. package/lib/typescript/src/types.d.ts +4 -0
  96. package/lib/typescript/src/types.d.ts.map +1 -1
  97. package/package.json +17 -3
  98. package/src/MapProvider.tsx +10 -0
  99. package/src/MapProvider.types.ts +16 -0
  100. package/src/MapProvider.web.tsx +14 -0
  101. package/src/MapView.tsx +28 -26
  102. package/src/MapView.types.ts +24 -7
  103. package/src/MapView.web.tsx +364 -0
  104. package/src/components/Marker.tsx +50 -4
  105. package/src/components/Marker.web.tsx +33 -0
  106. package/src/components/Polyline.tsx +51 -2
  107. package/src/components/Polyline.web.tsx +287 -0
  108. package/src/components/index.ts +8 -2
  109. package/src/components/index.web.ts +4 -0
  110. package/src/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +19 -7
  111. package/src/fabric/LuggMarkerViewNativeComponent.ts +7 -1
  112. package/src/fabric/LuggPolylineViewNativeComponent.ts +8 -0
  113. package/src/index.ts +18 -2
  114. package/src/index.web.ts +20 -0
  115. package/src/types.ts +5 -0
  116. package/ios/LuggAppleMapView.h +0 -16
  117. package/ios/LuggAppleMapView.mm +0 -580
  118. package/ios/LuggGoogleMapView.h +0 -13
  119. package/ios/LuggGoogleMapView.mm +0 -454
  120. package/lib/module/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
  121. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts +0 -54
  122. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts.map +0 -1
  123. package/lib/typescript/src/fabric/LuggGoogleMapViewNativeComponent.d.ts.map +0 -1
  124. package/src/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
@@ -1,11 +1,16 @@
1
1
  package com.luggmaps
2
2
 
3
3
  import android.content.Context
4
- import android.util.Log
4
+ import android.graphics.Bitmap
5
+ import android.graphics.Canvas
5
6
  import android.view.View
7
+ import android.view.ViewGroup
8
+ import androidx.core.graphics.createBitmap
6
9
  import androidx.core.view.isNotEmpty
7
10
  import com.facebook.react.views.view.ReactViewGroup
8
11
  import com.google.android.gms.maps.model.AdvancedMarker
12
+ import com.google.android.gms.maps.model.BitmapDescriptor
13
+ import com.google.android.gms.maps.model.BitmapDescriptorFactory
9
14
 
10
15
  interface LuggMarkerViewDelegate {
11
16
  fun markerViewDidUpdate(markerView: LuggMarkerView)
@@ -13,6 +18,8 @@ interface LuggMarkerViewDelegate {
13
18
  }
14
19
 
15
20
  class LuggMarkerView(context: Context) : ReactViewGroup(context) {
21
+ private var scaleUpdateRunnable: Runnable? = null
22
+
16
23
  var name: String? = null
17
24
  private set
18
25
 
@@ -34,23 +41,118 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
34
41
  var anchorY: Float = 1.0f
35
42
  private set
36
43
 
44
+ var zIndex: Float = 0f
45
+ private set
46
+
47
+ var rotate: Float = 0f
48
+ private set
49
+
50
+ var scale: Float = 1f
51
+ private set
52
+
53
+ var scaleChanged: Boolean = false
54
+ private set
55
+
56
+ var rasterize: Boolean = true
57
+ private set
58
+
37
59
  var didLayout: Boolean = false
38
60
  private set
39
61
 
40
62
  val hasCustomView: Boolean
41
63
  get() = iconView.isNotEmpty()
42
64
 
43
- val iconView: ReactViewGroup = object : ReactViewGroup(context) {
44
- override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
45
- var maxWidth = 0
46
- var maxHeight = 0
47
- for (i in 0 until childCount) {
48
- val child = getChildAt(i)
49
- if (child.width > maxWidth) maxWidth = child.width
50
- if (child.height > maxHeight) maxHeight = child.height
65
+ val iconView: ReactViewGroup = ReactViewGroup(context)
66
+
67
+ private fun measureIconViewBounds(): Pair<Int, Int> {
68
+ var maxWidth = 0
69
+ var maxHeight = 0
70
+ for (i in 0 until iconView.childCount) {
71
+ val child = iconView.getChildAt(i)
72
+ val childRight = child.left + child.width
73
+ val childBottom = child.top + child.height
74
+ if (childRight > maxWidth) maxWidth = childRight
75
+ if (childBottom > maxHeight) maxHeight = childBottom
76
+ }
77
+ return Pair(maxWidth, maxHeight)
78
+ }
79
+
80
+ private fun createIconBitmap(): BitmapDescriptor? {
81
+ val (width, height) = measureIconViewBounds()
82
+ if (width <= 0 || height <= 0) return null
83
+
84
+ val scaledWidth = (width * scale).toInt()
85
+ val scaledHeight = (height * scale).toInt()
86
+
87
+ val bitmap = createBitmap(scaledWidth, scaledHeight)
88
+ val canvas = Canvas(bitmap)
89
+ canvas.scale(scale, scale)
90
+ iconView.draw(canvas)
91
+ return BitmapDescriptorFactory.fromBitmap(bitmap)
92
+ }
93
+
94
+ private fun createIconViewWrapper(): View {
95
+ val (width, height) = measureIconViewBounds()
96
+ val scaledWidth = (width * scale).toInt()
97
+ val scaledHeight = (height * scale).toInt()
98
+
99
+ (iconView.parent as? ViewGroup)?.removeView(iconView)
100
+ iconView.scaleX = scale
101
+ iconView.scaleY = scale
102
+ iconView.pivotX = 0f
103
+ iconView.pivotY = 0f
104
+
105
+ return object : ReactViewGroup(context) {
106
+ init {
107
+ addView(iconView)
108
+ }
109
+
110
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
111
+ setMeasuredDimension(scaledWidth, scaledHeight)
112
+ }
113
+ }
114
+ }
115
+
116
+ fun applyIconToMarker() {
117
+ val m = marker ?: return
118
+ if (!hasCustomView) return
119
+
120
+ if (rasterize) {
121
+ createIconBitmap()?.let { m.setIcon(it) }
122
+ } else {
123
+ m.iconView = createIconViewWrapper()
124
+ }
125
+ }
126
+
127
+ fun applyScaleToMarker() {
128
+ val m = marker ?: return
129
+ if (!hasCustomView) return
130
+
131
+ scaleUpdateRunnable?.let { removeCallbacks(it) }
132
+ scaleUpdateRunnable = Runnable {
133
+ if (rasterize) {
134
+ createIconBitmap()?.let { m.setIcon(it) }
135
+ } else {
136
+ m.iconView = createIconViewWrapper()
51
137
  }
138
+ }
139
+ post(scaleUpdateRunnable)
140
+ }
52
141
 
53
- setMeasuredDimension(maxWidth, maxHeight)
142
+ fun updateIcon(onAddMarker: () -> Unit) {
143
+ if (!hasCustomView) return
144
+ if (rasterize) {
145
+ post {
146
+ if (marker == null) {
147
+ onAddMarker()
148
+ } else {
149
+ applyIconToMarker()
150
+ }
151
+ }
152
+ } else {
153
+ marker?.remove()
154
+ marker = null
155
+ post { onAddMarker() }
54
156
  }
55
157
  }
56
158
 
@@ -90,6 +192,7 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
90
192
  bottom: Int
91
193
  ) {
92
194
  super.onLayout(changed, left, top, right, bottom)
195
+
93
196
  if (changed && !didLayout) {
94
197
  didLayout = true
95
198
  delegate?.markerViewDidLayout(this)
@@ -114,6 +217,27 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
114
217
  anchorY = y.toFloat()
115
218
  }
116
219
 
220
+ fun setZIndex(zIndex: Float) {
221
+ this.zIndex = zIndex
222
+ }
223
+
224
+ fun setRotate(rotate: Float) {
225
+ this.rotate = rotate
226
+ }
227
+
228
+ fun setScale(scale: Float) {
229
+ scaleChanged = this.scale != scale
230
+ this.scale = scale
231
+ }
232
+
233
+ fun clearScaleChanged() {
234
+ scaleChanged = false
235
+ }
236
+
237
+ fun setRasterize(rasterize: Boolean) {
238
+ this.rasterize = rasterize
239
+ }
240
+
117
241
  fun setName(name: String?) {
118
242
  this.name = name
119
243
  }
@@ -123,12 +247,10 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
123
247
  }
124
248
 
125
249
  fun onDropViewInstance() {
250
+ scaleUpdateRunnable?.let { removeCallbacks(it) }
251
+ scaleUpdateRunnable = null
126
252
  didLayout = false
127
253
  delegate = null
128
254
  iconView.removeAllViews()
129
255
  }
130
-
131
- companion object {
132
- private const val TAG = "Lugg"
133
- }
134
256
  }
@@ -63,6 +63,27 @@ class LuggMarkerViewManager :
63
63
  }
64
64
  }
65
65
 
66
+ @ReactProp(name = "zIndex", defaultFloat = 0f)
67
+ override fun setZIndex(view: LuggMarkerView, zIndex: Float) {
68
+ super.setZIndex(view, zIndex)
69
+ view.setZIndex(zIndex)
70
+ }
71
+
72
+ @ReactProp(name = "rotate", defaultDouble = 0.0)
73
+ override fun setRotate(view: LuggMarkerView, value: Double) {
74
+ view.setRotate(value.toFloat())
75
+ }
76
+
77
+ @ReactProp(name = "scale", defaultDouble = 1.0)
78
+ override fun setScale(view: LuggMarkerView, value: Double) {
79
+ view.setScale(value.toFloat())
80
+ }
81
+
82
+ @ReactProp(name = "rasterize", defaultBoolean = true)
83
+ override fun setRasterize(view: LuggMarkerView, value: Boolean) {
84
+ view.setRasterize(value)
85
+ }
86
+
66
87
  companion object {
67
88
  const val NAME = "LuggMarkerView"
68
89
  }
@@ -1,13 +1,10 @@
1
1
  package com.luggmaps
2
2
 
3
3
  import com.facebook.react.ReactPackage
4
- import com.facebook.react.bridge.NativeModule
5
4
  import com.facebook.react.bridge.ReactApplicationContext
6
5
  import com.facebook.react.uimanager.ViewManager
7
6
 
8
7
  class LuggPackage : ReactPackage {
9
8
  override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
10
- listOf(LuggGoogleMapViewManager(), LuggMarkerViewManager(), LuggMapWrapperViewManager(), LuggPolylineViewManager())
11
-
12
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> = emptyList()
9
+ listOf(LuggMapViewManager(), LuggMarkerViewManager(), LuggMapWrapperViewManager(), LuggPolylineViewManager())
13
10
  }
@@ -12,6 +12,8 @@ interface LuggPolylineViewDelegate {
12
12
  fun polylineViewDidUpdate(polylineView: LuggPolylineView)
13
13
  }
14
14
 
15
+ data class AnimatedOptions(val duration: Long = 2150L, val easing: String = "linear", val trailLength: Float = 1f, val delay: Long = 0L)
16
+
15
17
  class LuggPolylineView(context: Context) : ReactViewGroup(context) {
16
18
  var coordinates: List<LatLng> = emptyList()
17
19
  private set
@@ -25,6 +27,12 @@ class LuggPolylineView(context: Context) : ReactViewGroup(context) {
25
27
  var animated: Boolean = false
26
28
  private set
27
29
 
30
+ var animatedOptions: AnimatedOptions = AnimatedOptions()
31
+ private set
32
+
33
+ var zIndex: Float = 0f
34
+ private set
35
+
28
36
  var cachedSpans: List<StyleSpan>? = null
29
37
  private set
30
38
 
@@ -55,6 +63,14 @@ class LuggPolylineView(context: Context) : ReactViewGroup(context) {
55
63
  animated = value
56
64
  }
57
65
 
66
+ fun setAnimatedOptions(options: AnimatedOptions) {
67
+ animatedOptions = options
68
+ }
69
+
70
+ fun setZIndex(value: Float) {
71
+ zIndex = value
72
+ }
73
+
58
74
  fun getOrCreateSpans(): List<StyleSpan> {
59
75
  cachedSpans?.let { return it }
60
76
 
@@ -1,6 +1,7 @@
1
1
  package com.luggmaps
2
2
 
3
3
  import com.facebook.react.bridge.ReadableArray
4
+ import com.facebook.react.bridge.ReadableMap
4
5
  import com.facebook.react.module.annotations.ReactModule
5
6
  import com.facebook.react.uimanager.ThemedReactContext
6
7
  import com.facebook.react.uimanager.ViewGroupManager
@@ -65,6 +66,27 @@ class LuggPolylineViewManager :
65
66
  view.setAnimated(value)
66
67
  }
67
68
 
69
+ @ReactProp(name = "animatedOptions")
70
+ override fun setAnimatedOptions(view: LuggPolylineView, value: ReadableMap?) {
71
+ val options = if (value != null) {
72
+ AnimatedOptions(
73
+ duration = if (value.hasKey("duration")) value.getDouble("duration").toLong() else 2150L,
74
+ easing = if (value.hasKey("easing")) value.getString("easing") ?: "linear" else "linear",
75
+ trailLength = if (value.hasKey("trailLength")) value.getDouble("trailLength").toFloat() else 1f,
76
+ delay = if (value.hasKey("delay")) value.getDouble("delay").toLong() else 0L
77
+ )
78
+ } else {
79
+ AnimatedOptions()
80
+ }
81
+ view.setAnimatedOptions(options)
82
+ }
83
+
84
+ @ReactProp(name = "zIndex", defaultFloat = 0f)
85
+ override fun setZIndex(view: LuggPolylineView, value: Float) {
86
+ super.setZIndex(view, value)
87
+ view.setZIndex(value)
88
+ }
89
+
68
90
  companion object {
69
91
  const val NAME = "LuggPolylineView"
70
92
  }