@@ -31,6 +31,7 @@ import androidx.compose.foundation.layout.padding
31
31
import androidx.compose.foundation.layout.sizeIn
32
32
import androidx.compose.runtime.Composable
33
33
import androidx.compose.runtime.LaunchedEffect
34
+ import androidx.compose.runtime.SideEffect
34
35
import androidx.compose.runtime.State
35
36
import androidx.compose.runtime.getValue
36
37
import androidx.compose.runtime.mutableStateOf
@@ -124,15 +125,16 @@ public sealed class GeoViewScope protected constructor(private val geoView: GeoV
124
125
shapes : CalloutShapes = CalloutDefaults .shapes(),
125
126
content : @Composable BoxScope .() -> Unit
126
127
) {
127
- // Enables the recomposition of the first Callout in the content lambda that is displayed
128
- // on the MapView/SceneView
129
- var allowCalloutRecomposition by remember { mutableStateOf(false ) }
130
-
131
- if (this .isCalloutBeingDisplayed.compareAndSet(false , true )
132
- || allowCalloutRecomposition
133
- ) {
134
- allowCalloutRecomposition = true
128
+ if (this .isCalloutBeingDisplayed.compareAndSet(false , true )) {
135
129
this .CalloutInternal (location, modifier, offset, rotateOffsetWithGeoView, colorScheme, shapes, content)
130
+
131
+ SideEffect {
132
+ // The SideEffect is executed after every successful (re)composition. This means that it runs at the
133
+ // end of the GeoView's content lambda from which this Callout function was called. Resetting at this point
134
+ // allows us to run the callout code at subsequent recomposition but also to prevent multiple callouts from
135
+ // being rendered within a single (re)composition pass.
136
+ reset()
137
+ }
136
138
}
137
139
}
138
140
@@ -165,15 +167,16 @@ public sealed class GeoViewScope protected constructor(private val geoView: GeoV
165
167
shapes : CalloutShapes = CalloutDefaults .shapes(),
166
168
content : @Composable BoxScope .() -> Unit
167
169
) {
168
- // Enables the recomposition of the first Callout in the content lambda that is displayed
169
- // on the MapView/SceneView
170
- var allowCalloutRecomposition by remember { mutableStateOf(false ) }
171
-
172
- if (this .isCalloutBeingDisplayed.compareAndSet(false , true )
173
- || allowCalloutRecomposition
174
- ) {
175
- allowCalloutRecomposition = true
170
+ if (this .isCalloutBeingDisplayed.compareAndSet(false , true )) {
176
171
this .CalloutInternal (geoElement, modifier, tapLocation, colorScheme, shapes, content)
172
+
173
+ SideEffect {
174
+ // The SideEffect is executed after every successful (re)composition. This means that it runs at the
175
+ // end of the GeoView's content lambda from which this Callout function was called. Resetting at this point
176
+ // allows us to run the callout code at subsequent recomposition but also to prevent multiple callouts from
177
+ // being rendered within a single (re)composition pass.
178
+ reset()
179
+ }
177
180
}
178
181
}
179
182
@@ -189,7 +192,7 @@ public sealed class GeoViewScope protected constructor(private val geoView: GeoV
189
192
*
190
193
* @since 200.5.0
191
194
*/
192
- internal fun reset () {
195
+ private fun reset () {
193
196
isCalloutBeingDisplayed.set(false )
194
197
}
195
198
0 commit comments