|
1 | 1 | /*
|
2 |
| - * |
3 | 2 | * Copyright 2023 Esri
|
4 | 3 | *
|
5 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
|
18 | 17 |
|
19 | 18 | package com.arcgismaps.toolkit.geocompose
|
20 | 19 |
|
21 |
| -import androidx.compose.material3.Text |
22 | 20 | import androidx.compose.runtime.Composable
|
| 21 | +import androidx.compose.runtime.DisposableEffect |
| 22 | +import androidx.compose.runtime.LaunchedEffect |
| 23 | +import androidx.compose.runtime.remember |
| 24 | +import androidx.compose.ui.Modifier |
| 25 | +import androidx.compose.ui.platform.LocalContext |
| 26 | +import androidx.compose.ui.platform.LocalLifecycleOwner |
23 | 27 | import androidx.compose.ui.tooling.preview.Preview
|
| 28 | +import androidx.compose.ui.viewinterop.AndroidView |
| 29 | +import com.arcgismaps.mapping.view.MapView |
| 30 | +import kotlinx.coroutines.launch |
24 | 31 |
|
25 | 32 | @Composable
|
26 |
| -public fun Map() { |
27 |
| - // Todo implementation... |
28 |
| - Text("Implement Map here! ") |
| 33 | +public fun Map(modifier: Modifier = Modifier, mapState: MapState = MapState()) { |
| 34 | + |
| 35 | + val lifecycleOwner = LocalLifecycleOwner.current |
| 36 | + val context = LocalContext.current |
| 37 | + val mapView = remember { MapView(context) } |
| 38 | + |
| 39 | + AndroidView(modifier = modifier, factory = { mapView }) |
| 40 | + |
| 41 | + DisposableEffect(Unit) { |
| 42 | + lifecycleOwner.lifecycle.addObserver(mapView) |
| 43 | + onDispose { |
| 44 | + lifecycleOwner.lifecycle.removeObserver(mapView) |
| 45 | + mapView.onDestroy(lifecycleOwner) |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + LaunchedEffect(mapState) { |
| 50 | + launch { |
| 51 | + mapState.arcGISMap.collect { |
| 52 | + mapView.map = it |
| 53 | + } |
| 54 | + } |
| 55 | + } |
29 | 56 | }
|
30 | 57 |
|
31 | 58 | @Preview
|
|
0 commit comments