Skip to content

Commit ca0a2cf

Browse files
committed
Remove unnecessary key() statement
1 parent b7eb9e3 commit ca0a2cf

1 file changed

Lines changed: 77 additions & 80 deletions

File tree

  • mapconductor-for-googlemaps/src/main/java/com/mapconductor/googlemaps

mapconductor-for-googlemaps/src/main/java/com/mapconductor/googlemaps/GoogleMapView.kt

Lines changed: 77 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.mapconductor.googlemaps
22

33
import androidx.compose.runtime.Composable
44
import androidx.compose.runtime.DisposableEffect
5-
import androidx.compose.runtime.key
65
import androidx.compose.runtime.remember
76
import androidx.compose.ui.Modifier
87
import androidx.compose.ui.node.Ref
@@ -41,92 +40,90 @@ fun GoogleMapsView(
4140
val context = LocalContext.current // Context will be available from MapViewBase too if needed
4241
val registry = remember { scope.buildRegistry() }
4342

44-
key(state.id) {
45-
MapViewBase(
46-
state = state,
47-
modifier = modifier,
48-
holderRef = holderRef,
49-
controllerRef = controllerRef,
50-
viewProvider = { this.mapView }, // Assuming GoogleMapViewHolder has a 'mapView' property
51-
scope = scope,
52-
registry = registry,
53-
onInitialize = {
54-
// Specific Google Maps initialization logic
55-
// This lambda will be executed within state.initAsync by MapViewBase
56-
val cameraPosition =
57-
state.mapCameraPosition.value?.let {
58-
CameraPosition
59-
.Builder()
60-
.apply {
61-
target(GeoPoint.from(it.position).toLatLng())
62-
zoom(it.zoom.toFloat())
63-
bearing(it.bearing.toFloat())
64-
tilt(it.tilt.toFloat())
65-
}.build()
66-
}
43+
MapViewBase(
44+
state = state,
45+
modifier = modifier,
46+
holderRef = holderRef,
47+
controllerRef = controllerRef,
48+
viewProvider = { this.mapView }, // Assuming GoogleMapViewHolder has a 'mapView' property
49+
scope = scope,
50+
registry = registry,
51+
onInitialize = {
52+
// Specific Google Maps initialization logic
53+
// This lambda will be executed within state.initAsync by MapViewBase
54+
val cameraPosition =
55+
state.mapCameraPosition.value?.let {
56+
CameraPosition
57+
.Builder()
58+
.apply {
59+
target(GeoPoint.from(it.position).toLatLng())
60+
zoom(it.zoom.toFloat())
61+
bearing(it.bearing.toFloat())
62+
tilt(it.tilt.toFloat())
63+
}.build()
64+
}
6765

68-
val mapInitOptions =
69-
GoogleMapOptions()
70-
.mapType(state.mapDesignType.getValue())
71-
.camera(cameraPosition)
66+
val mapInitOptions =
67+
GoogleMapOptions()
68+
.mapType(state.mapDesignType.getValue())
69+
.camera(cameraPosition)
7270

73-
val controller =
74-
GoogleMapViewControllerStore.getOrCreate(
75-
context = context, // Use context from the outer scope
76-
id = state.id,
77-
options = mapInitOptions,
78-
)
79-
(state as? GoogleMapViewState)?.let { mapViewState ->
80-
mapViewState.controller = controller
81-
controller.cameraMoveListener = mapViewState::OnCameraChange
82-
}
83-
controller.mapClickListener = onMapClick
84-
controller.markerClickListener = onMarkerClick
85-
controller.markerDragStartListener = onMarkerDragStart
86-
controller.markerDragListener = onMarkerDrag
87-
controller.markerDragEndListener = onMarkerDragEnd
88-
controller.circleClickListener = onCircleClick
89-
controller.polylineClickListener = onPolylineClick
90-
controller.setOnMarkerAnimationStart(onMarkerAnimateStart)
91-
controller.setOnMarkerAnimationEnd(onMarkerAnimateEnd)
71+
val controller =
72+
GoogleMapViewControllerStore.getOrCreate(
73+
context = context, // Use context from the outer scope
74+
id = state.id,
75+
options = mapInitOptions,
76+
)
77+
(state as? GoogleMapViewState)?.let { mapViewState ->
78+
mapViewState.controller = controller
79+
controller.cameraMoveListener = mapViewState::OnCameraChange
80+
}
81+
controller.mapClickListener = onMapClick
82+
controller.markerClickListener = onMarkerClick
83+
controller.markerDragStartListener = onMarkerDragStart
84+
controller.markerDragListener = onMarkerDrag
85+
controller.markerDragEndListener = onMarkerDragEnd
86+
controller.circleClickListener = onCircleClick
87+
controller.polylineClickListener = onPolylineClick
88+
controller.setOnMarkerAnimationStart(onMarkerAnimateStart)
89+
controller.setOnMarkerAnimationEnd(onMarkerAnimateEnd)
9290

93-
holderRef.value = controller.holder
94-
controllerRef.value = controller
95-
true // Return success/failure of initialization
96-
},
97-
customDisposableEffect = { _state, _holderRef ->
98-
// Specific Google Maps DisposableEffect logic
99-
val lifecycle = LocalLifecycleOwner.current.lifecycle // Get lifecycle here
100-
DisposableEffect(lifecycle) {
101-
val stateId = _state.id
102-
val observer =
103-
object : DefaultLifecycleObserver {
104-
override fun onResume(owner: LifecycleOwner) {}
91+
holderRef.value = controller.holder
92+
controllerRef.value = controller
93+
true // Return success/failure of initialization
94+
},
95+
customDisposableEffect = { _state, _holderRef ->
96+
// Specific Google Maps DisposableEffect logic
97+
val lifecycle = LocalLifecycleOwner.current.lifecycle // Get lifecycle here
98+
DisposableEffect(lifecycle) {
99+
val stateId = _state.id
100+
val observer =
101+
object : DefaultLifecycleObserver {
102+
override fun onResume(owner: LifecycleOwner) {}
105103

106-
override fun onPause(owner: LifecycleOwner) {}
104+
override fun onPause(owner: LifecycleOwner) {}
107105

108-
override fun onDestroy(owner: LifecycleOwner) {
109-
val activity = context.findActivity()
110-
if (activity?.isChangingConfigurations == true) {
111-
(_holderRef.value!!.mapView.parent as? ViewGroup)?.removeView(
112-
_holderRef.value!!.mapView,
113-
)
114-
} else {
115-
GoogleMapViewControllerStore.remove(stateId)
116-
}
106+
override fun onDestroy(owner: LifecycleOwner) {
107+
val activity = context.findActivity()
108+
if (activity?.isChangingConfigurations == true) {
109+
(_holderRef.value!!.mapView.parent as? ViewGroup)?.removeView(
110+
_holderRef.value!!.mapView,
111+
)
112+
} else {
113+
GoogleMapViewControllerStore.remove(stateId)
117114
}
118115
}
119-
lifecycle.addObserver(observer)
120-
onDispose {
121-
_state.resetInitState()
122-
lifecycle.removeObserver(observer)
123116
}
117+
lifecycle.addObserver(observer)
118+
onDispose {
119+
_state.resetInitState()
120+
lifecycle.removeObserver(observer)
124121
}
125-
},
126-
// Pass content if it needs to be rendered within the overlay providers in MapViewBase,
127-
// or handle it here if it's specific to GoogleMapsView structure before calling MapViewBase.
128-
// For now, assuming content relates to overlay definitions.
129-
content = content, // This might need adjustment based on how overlays are handled
130-
)
131-
}
122+
}
123+
},
124+
// Pass content if it needs to be rendered within the overlay providers in MapViewBase,
125+
// or handle it here if it's specific to GoogleMapsView structure before calling MapViewBase.
126+
// For now, assuming content relates to overlay definitions.
127+
content = content, // This might need adjustment based on how overlays are handled
128+
)
132129
}

0 commit comments

Comments
 (0)