Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.google.android.gms.maps.model.PolylineOptions
import com.google.android.gms.maps.model.TileOverlay
import com.google.android.gms.maps.model.TileOverlayOptions
import com.google.android.gms.maps.model.UrlTileProvider
import com.luggmaps.extensions.findViewByTag
import com.luggmaps.LuggCalloutView
import com.luggmaps.LuggCircleView
import com.luggmaps.LuggCircleViewDelegate
Expand Down Expand Up @@ -506,7 +507,7 @@ class GoogleMapProvider(private val context: Context) :

if (map != null && oldInsets != edgeInsets) {
val cameraUpdate = CameraUpdateFactory.newCameraPosition(map.cameraPosition)
applyEdgeInsets()
applyEdgeInsets(duration)
when {
duration < 0 -> map.animateCamera(cameraUpdate)
duration > 0 -> map.animateCamera(cameraUpdate, duration, null)
Expand Down Expand Up @@ -1176,10 +1177,36 @@ class GoogleMapProvider(private val context: Context) :
}
}

private fun applyEdgeInsets() {
private fun applyEdgeInsets(duration: Int = 0) {
googleMap?.setPadding(edgeInsets.left, edgeInsets.top, edgeInsets.right, edgeInsets.bottom)
applyWatermarkTranslation(duration)
}

private fun applyWatermarkTranslation(duration: Int = 0) {
val view = mapView ?: return
view.findViewByTag("GoogleWatermark")?.let { watermark ->
val targetY = -edgeInsets.bottom.toFloat()
val targetX = edgeInsets.left.toFloat()
if (duration > 0) {
watermark.animate()
.translationY(targetY)
.translationX(targetX)
.setDuration(duration.toLong())
.start()
} else if (duration < 0) {
watermark.animate()
.translationY(targetY)
.translationX(targetX)
.start()
} else {
watermark.translationY = targetY
watermark.translationX = targetX
}
}
}



override fun onConfigurationChanged(newConfig: Configuration) {
val newNightMode = newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK
if (newNightMode != currentNightMode) {
Expand Down
11 changes: 11 additions & 0 deletions android/src/main/java/com/luggmaps/extensions/ViewExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.luggmaps.extensions

import android.view.View
import android.view.ViewGroup
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.events.Event
Expand All @@ -12,3 +13,13 @@ fun View.dispatchEvent(event: Event<*>) {
)
eventDispatcher?.dispatchEvent(event)
}

fun View.findViewByTag(tag: String): View? {
if (this.tag?.toString() == tag) return this
if (this !is ViewGroup) return null
for (i in 0 until childCount) {
val found = getChildAt(i).findViewByTag(tag)
if (found != null) return found
}
return null
}
4 changes: 3 additions & 1 deletion ios/core/AppleMapProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ @implementation AppleMapProvider {
CADisplayLink *_edgeInsetsDisplayLink;
UIEdgeInsets _edgeInsetsFrom;
UIEdgeInsets _edgeInsetsTo;
UIEdgeInsets _edgeInsetsCurrent;
CFTimeInterval _edgeInsetsAnimationStart;
CFTimeInterval _edgeInsetsAnimationDuration;
BOOL _poiEnabled;
Expand Down Expand Up @@ -394,6 +395,7 @@ - (void)setEdgeInsets:(UIEdgeInsets)edgeInsets
CGFloat deltaY = newOffsetY - oldOffsetY;

_mapView.layoutMargins = edgeInsets;
_edgeInsetsCurrent = edgeInsets;

if (deltaX != 0 || deltaY != 0) {
CLLocationCoordinate2D currentCenter = _mapView.centerCoordinate;
Expand Down Expand Up @@ -444,7 +446,7 @@ - (void)edgeInsetsAnimationTick:(CADisplayLink *)displayLink {
_edgeInsetsFrom.right +
(_edgeInsetsTo.right - _edgeInsetsFrom.right) * t);

[self setEdgeInsets:current oldEdgeInsets:_mapView.layoutMargins];
[self setEdgeInsets:current oldEdgeInsets:_edgeInsetsCurrent];

if (progress >= 1.0) {
[self stopEdgeInsetsAnimation];
Expand Down
Loading