Skip to content

Commit

Permalink
feat: Add public currentCameraPositionState property (#262)
Browse files Browse the repository at this point in the history
* feat: Add CompositionLocal for camera state

* Change to a GoogleMapComposable-annotated property

* Add kdoc
  • Loading branch information
DSteve595 committed Feb 8, 2023
1 parent d0c01ff commit bf88134
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ package com.google.maps.android.compose

import androidx.annotation.UiThread
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import com.google.android.gms.maps.CameraUpdate
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
Expand Down Expand Up @@ -309,3 +311,11 @@ public class CameraPositionState(
)
}
}

/** Provides the [CameraPositionState] used by the map. */
internal val LocalCameraPositionState = staticCompositionLocalOf { CameraPositionState() }

/** The current [CameraPositionState] used by the map. */
public val currentCameraPositionState: CameraPositionState
@[GoogleMapComposable ReadOnlyComposable Composable]
get() = LocalCameraPositionState.current
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composition
import androidx.compose.runtime.CompositionContext
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
Expand Down Expand Up @@ -132,7 +133,11 @@ public fun GoogleMap(
mapProperties = currentMapProperties,
mapUiSettings = currentUiSettings,
)
currentContent?.invoke()
CompositionLocalProvider(
LocalCameraPositionState provides cameraPositionState,
) {
currentContent?.invoke()
}
}
}
}
Expand Down

0 comments on commit bf88134

Please sign in to comment.