dima.avdeev
2 years ago
committed by
GitHub
5 changed files with 54 additions and 6 deletions
@ -1,21 +1,49 @@ |
|||||||
package example.imageviewer.view |
package example.imageviewer.view |
||||||
|
|
||||||
|
import android.view.MotionEvent |
||||||
import androidx.compose.runtime.Composable |
import androidx.compose.runtime.Composable |
||||||
|
import androidx.compose.runtime.LaunchedEffect |
||||||
|
import androidx.compose.runtime.MutableState |
||||||
|
import androidx.compose.ui.ExperimentalComposeUiApi |
||||||
import androidx.compose.ui.Modifier |
import androidx.compose.ui.Modifier |
||||||
|
import androidx.compose.ui.input.pointer.pointerInteropFilter |
||||||
import com.google.android.gms.maps.model.CameraPosition |
import com.google.android.gms.maps.model.CameraPosition |
||||||
import com.google.android.gms.maps.model.LatLng |
import com.google.android.gms.maps.model.LatLng |
||||||
import com.google.maps.android.compose.GoogleMap |
import com.google.maps.android.compose.GoogleMap |
||||||
import com.google.maps.android.compose.rememberCameraPositionState |
import com.google.maps.android.compose.rememberCameraPositionState |
||||||
import example.imageviewer.model.GpsPosition |
import example.imageviewer.model.GpsPosition |
||||||
|
|
||||||
|
@OptIn(ExperimentalComposeUiApi::class) |
||||||
@Composable |
@Composable |
||||||
actual fun LocationVisualizer(modifier: Modifier, gps: GpsPosition, title: String) { |
actual fun LocationVisualizer( |
||||||
|
modifier: Modifier, |
||||||
|
gps: GpsPosition, |
||||||
|
title: String, |
||||||
|
parentScrollEnableState: MutableState<Boolean> |
||||||
|
) { |
||||||
val currentLocation = LatLng(gps.latitude, gps.longitude) |
val currentLocation = LatLng(gps.latitude, gps.longitude) |
||||||
val cameraPositionState = rememberCameraPositionState { |
val cameraPositionState = rememberCameraPositionState { |
||||||
position = CameraPosition.fromLatLngZoom(currentLocation, 10f) |
position = CameraPosition.fromLatLngZoom(currentLocation, 10f) |
||||||
} |
} |
||||||
|
LaunchedEffect(cameraPositionState.isMoving) { |
||||||
|
// This code helps to use Compose GoogleMap inside scrollable container. |
||||||
|
// Useful code sample: https://github.com/googlemaps/android-maps-compose/blob/abb3e3581681f26316fdd0b8284597f8fc61daa1/app/src/main/java/com/google/maps/android/compose/MapInColumnActivity.kt#L57 |
||||||
|
if (!cameraPositionState.isMoving) { |
||||||
|
parentScrollEnableState.value = true |
||||||
|
} |
||||||
|
} |
||||||
GoogleMap( |
GoogleMap( |
||||||
modifier = modifier, |
modifier = modifier.pointerInteropFilter( |
||||||
|
onTouchEvent = { |
||||||
|
when (it.action) { |
||||||
|
MotionEvent.ACTION_DOWN -> { |
||||||
|
parentScrollEnableState.value = false |
||||||
|
false |
||||||
|
} |
||||||
|
else -> true |
||||||
|
} |
||||||
|
} |
||||||
|
), |
||||||
cameraPositionState = cameraPositionState |
cameraPositionState = cameraPositionState |
||||||
) |
) |
||||||
} |
} |
||||||
|
@ -1,8 +1,14 @@ |
|||||||
package example.imageviewer.view |
package example.imageviewer.view |
||||||
|
|
||||||
import androidx.compose.runtime.Composable |
import androidx.compose.runtime.Composable |
||||||
|
import androidx.compose.runtime.MutableState |
||||||
import androidx.compose.ui.Modifier |
import androidx.compose.ui.Modifier |
||||||
import example.imageviewer.model.GpsPosition |
import example.imageviewer.model.GpsPosition |
||||||
|
|
||||||
@Composable |
@Composable |
||||||
expect fun LocationVisualizer(modifier: Modifier, gps: GpsPosition, title: String) |
expect fun LocationVisualizer( |
||||||
|
modifier: Modifier, |
||||||
|
gps: GpsPosition, |
||||||
|
title: String, |
||||||
|
parentScrollEnableState: MutableState<Boolean> |
||||||
|
) |
||||||
|
Loading…
Reference in new issue