Skip to content

Commit 55bc0b3

Browse files
Move logic to W3WGoogleMap
1 parent 5fe855a commit 55bc0b3

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapComponent.kt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.what3words.components.compose.maps
22

33
import android.graphics.PointF
4-
import android.view.View
5-
import android.widget.RelativeLayout
64
import androidx.compose.foundation.layout.Box
75
import androidx.compose.foundation.layout.padding
86
import androidx.compose.runtime.Composable
@@ -19,8 +17,6 @@ import androidx.compose.ui.Modifier
1917
import androidx.compose.ui.geometry.Rect
2018
import androidx.compose.ui.layout.boundsInParent
2119
import androidx.compose.ui.layout.onGloballyPositioned
22-
import androidx.compose.ui.platform.LocalView
23-
import androidx.core.view.doOnLayout
2420
import com.what3words.components.compose.maps.W3WMapDefaults.MapColors
2521
import com.what3words.components.compose.maps.W3WMapDefaults.defaultMapColors
2622
import com.what3words.components.compose.maps.buttons.MapButtons
@@ -315,8 +311,6 @@ internal fun W3WMapContent(
315311
onMapViewPortProvided: (W3WGridScreenCell) -> Unit,
316312
onRecallButtonPositionProvided: ((PointF) -> Unit),
317313
) {
318-
val view = LocalView.current
319-
320314
var bounds by remember { mutableStateOf(Rect.Zero) }
321315

322316
// Check if the map is initialized, use to prevent LaunchedEffect to re-run on configuration changes
@@ -379,24 +373,6 @@ internal fun W3WMapContent(
379373
}
380374
}
381375

382-
// Reposition Google Map compass to align with app's design
383-
LaunchedEffect(mapProvider, mapConfig.isGoogleCompassAlignedRight) {
384-
if (mapProvider == MapProvider.GOOGLE_MAP && mapConfig.isGoogleCompassAlignedRight) {
385-
val compass = view.findViewWithTag<View>("GoogleMapCompass")
386-
387-
compass?.doOnLayout {
388-
val params = compass.layoutParams as RelativeLayout.LayoutParams
389-
params.addRule(RelativeLayout.ALIGN_PARENT_START, 0)
390-
params.addRule(RelativeLayout.ALIGN_PARENT_END)
391-
params.addRule(RelativeLayout.ALIGN_PARENT_TOP)
392-
393-
compass.layoutParams = params
394-
compass.requestLayout()
395-
}
396-
}
397-
}
398-
399-
400376
Box(
401377
modifier = modifier
402378
.onGloballyPositioned { coordinates ->

lib-compose/src/main/java/com/what3words/components/compose/maps/providers/googlemap/W3WGoogleMap.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.what3words.components.compose.maps.providers.googlemap
22

33
import android.graphics.Point
4+
import android.view.View
5+
import android.widget.RelativeLayout
46
import androidx.compose.runtime.Composable
57
import androidx.compose.runtime.LaunchedEffect
68
import androidx.compose.runtime.getValue
@@ -9,6 +11,8 @@ import androidx.compose.runtime.remember
911
import androidx.compose.runtime.setValue
1012
import androidx.compose.runtime.snapshotFlow
1113
import androidx.compose.ui.Modifier
14+
import androidx.compose.ui.platform.LocalView
15+
import androidx.core.view.doOnLayout
1216
import com.google.android.gms.maps.Projection
1317
import com.google.android.gms.maps.model.LatLngBounds
1418
import com.google.android.gms.maps.model.MapStyleOptions
@@ -116,6 +120,24 @@ fun W3WGoogleMap(
116120
onCameraUpdated(state.cameraState)
117121
}
118122

123+
// Reposition Google Map compass to align with app's design
124+
val view = LocalView.current
125+
LaunchedEffect(mapConfig.isGoogleCompassAlignedRight) {
126+
if (mapConfig.isGoogleCompassAlignedRight) {
127+
val compass = view.findViewWithTag<View>("GoogleMapCompass")
128+
129+
compass?.doOnLayout {
130+
val params = compass.layoutParams as RelativeLayout.LayoutParams
131+
params.addRule(RelativeLayout.ALIGN_PARENT_START, 0)
132+
params.addRule(RelativeLayout.ALIGN_PARENT_END)
133+
params.addRule(RelativeLayout.ALIGN_PARENT_TOP)
134+
135+
compass.layoutParams = params
136+
compass.requestLayout()
137+
}
138+
}
139+
}
140+
119141
GoogleMap(
120142
modifier = modifier,
121143
cameraPositionState = cameraPositionState,

0 commit comments

Comments
 (0)