Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: recomposition demo, updates Camera #544

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.Marker
import com.google.maps.android.compose.theme.MapsComposeSampleTheme
import kotlin.random.Random
Expand All @@ -44,14 +46,10 @@ class RecompositionActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val cameraPositionState = rememberCameraPositionState {
position = defaultCameraPosition
}
Box(Modifier.fillMaxSize()) {
MapsComposeSampleTheme {
GoogleMapView(
modifier = Modifier.matchParentSize(),
cameraPositionState = cameraPositionState
modifier = Modifier.matchParentSize()
)
}
}
Expand All @@ -61,10 +59,13 @@ class RecompositionActivity : ComponentActivity() {
@Composable
fun GoogleMapView(
modifier: Modifier = Modifier,
cameraPositionState: CameraPositionState = rememberCameraPositionState(),
content: @Composable () -> Unit = {},
) {
val markerState = rememberMarkerState(position = singapore)
val cameraPosition = CameraPosition.fromLatLngZoom(markerState.position, 11f)
val cameraPositionState = rememberCameraPositionState {
position = cameraPosition
}

val uiSettings by remember { mutableStateOf(MapUiSettings(compassEnabled = false)) }
val mapProperties by remember {
Expand Down Expand Up @@ -100,13 +101,14 @@ class RecompositionActivity : ComponentActivity() {
}
Column {
Button(onClick = {
val randomValue = Random.nextInt(3)
val randomValue = Random.nextInt(4)
markerState.position = when (randomValue) {
0 -> singapore
1 -> singapore2
2 -> singapore3
else -> singapore
else -> singapore4
}
cameraPositionState.position = CameraPosition.fromLatLngZoom(markerState.position, 11f)
}) {
Text("Change Location")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.google.android.gms.maps.model.LatLng
import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.suspendCancellableCoroutine
import java.lang.Integer.MAX_VALUE
Expand Down