Skip to content

Forms : Revert map state #348

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

Merged
merged 3 commits into from
Mar 5, 2024
Merged
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
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
#android.enableBuildConfigAsBytecode=true
artifactoryUrl=https://olympus.esri.com/artifactory/arcgisruntime-snapshot-local
artifactoryGroupId=com.esri
artifactoryArtifactBaseId=arcgis-maps-kotlin-toolkit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun MainScreen() {
// show a composable map using the mapViewModel
ComposableMap(
modifier = Modifier.fillMaxSize(),
mapState = mapViewModel
mapInterface = mapViewModel
) {
Row(modifier = Modifier
.height(IntrinsicSize.Max)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.toolkit.composablemap.MapInsets
import com.arcgismaps.toolkit.composablemap.MapState
import com.arcgismaps.toolkit.composablemap.MapInterface

class MapViewModel(
arcGISMap: ArcGISMap,
mapInsets: MapInsets = MapInsets()
) : ViewModel(), MapState by MapState(arcGISMap, mapInsets)
) : ViewModel(), MapInterface by MapInterface(arcGISMap, mapInsets)

class MapViewModelFactory(
private val arcGISMap: ArcGISMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fun MapScreen(mapViewModel: MapViewModel = hiltViewModel(), onBackPressed: () ->
modifier = Modifier
.padding(padding)
.fillMaxSize(),
mapState = mapViewModel
mapInterface = mapViewModel
)
AnimatedVisibility(
visible = featureForm != null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import com.arcgismaps.mapping.featureforms.FieldFormElement
import com.arcgismaps.mapping.layers.FeatureLayer
import com.arcgismaps.mapping.view.MapView
import com.arcgismaps.mapping.view.SingleTapConfirmedEvent
import com.arcgismaps.toolkit.composablemap.MapState
import com.arcgismaps.toolkit.composablemap.MapInterface
import com.arcgismaps.toolkit.composablemap.MapInterfaceImpl
import com.arcgismaps.toolkit.featureforms.ValidationErrorVisibility
import com.arcgismaps.toolkit.featureformsapp.data.PortalItemRepository
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -75,7 +76,7 @@ class MapViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val portalItemRepository: PortalItemRepository
) : ViewModel(),
MapState by MapState() {
MapInterface by MapInterfaceImpl(ArcGISMap()) {
private val itemId: String = savedStateHandle["uri"]!!
lateinit var portalItem: PortalItem

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun MainScreen() {
val mapViewModel = viewModel<MapViewModel>(factory = MapViewModelFactory(map))
ComposableMap(
modifier = Modifier.fillMaxSize(),
mapState = mapViewModel
mapInterface = mapViewModel
)

val templateViewModel = viewModel<TemplateViewModel>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import androidx.lifecycle.ViewModelProvider
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.mapping.view.MapView
import com.arcgismaps.mapping.view.SingleTapConfirmedEvent
import com.arcgismaps.toolkit.composablemap.MapState
import com.arcgismaps.toolkit.composablemap.MapStateImpl
import com.arcgismaps.toolkit.composablemap.MapInterface
import com.arcgismaps.toolkit.composablemap.MapInterfaceImpl
import kotlinx.coroutines.CoroutineScope

class MapViewModel(
arcGISMap: ArcGISMap
) : ViewModel(), MapState by MapStateImpl(arcGISMap) {
) : ViewModel(), MapInterface by MapInterfaceImpl(arcGISMap) {

context(MapView, CoroutineScope) override fun onSingleTapConfirmed(singleTapEvent: SingleTapConfirmedEvent) {
// example of how to add a tap handler with a MapView and CoroutineScope in context.
Expand Down
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ val projects = listOf("template", "featureforms", "authentication", "compass")

pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
google()
mavenCentral()
Expand All @@ -43,7 +42,6 @@ dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
@Suppress("UnstableApiUsage")
repositories {
mavenLocal()
google()
mavenCentral()
maven {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class ComposableMapTests {

@Test
fun testComposableMapLayout() {
val mockMapInterface = MapState(ArcGISMap())
val mockMapInterface = MapInterface(ArcGISMap())

composeTestRule.setContent {
ComposableMap(mapState = mockMapInterface) {
ComposableMap(mapInterface = mockMapInterface) {
Card(modifier = Modifier.semantics { contentDescription = "Card" }) {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,64 +41,64 @@ import kotlinx.coroutines.launch

@Composable
public fun ComposableMap(
mapState: MapState,
mapInterface: MapInterface,
modifier: Modifier = Modifier,
content: @Composable () -> Unit = {},
) {
val context = LocalContext.current
val coroutineScope = rememberCoroutineScope()
val lifecycleOwner = LocalLifecycleOwner.current

val map by mapState.map.collectAsState()
val insets by mapState.insets.collectAsState()
val map by mapInterface.map.collectAsState()
val insets by mapInterface.insets.collectAsState()
val mapView = remember {
MapView(context).also { view ->
with(view) {
with(coroutineScope) {
launch {
view.onDown.collect {
mapState.onDown(it)
mapInterface.onDown(it)
}
}
launch {
view.onUp.collect {
mapState.onUp(it)
mapInterface.onUp(it)
}
}
launch {
view.onSingleTapConfirmed.collect {
mapState.onSingleTapConfirmed(it)
mapInterface.onSingleTapConfirmed(it)
}
}
launch {
view.onDoubleTap.collect {
mapState.onDoubleTap(it)
mapInterface.onDoubleTap(it)
}
}
launch {
view.onLongPress.collect {
mapState.onLongPress(it)
mapInterface.onLongPress(it)
}
}
launch {
view.onTwoPointerTap.collect {
mapState.onTwoPointerTap(it)
mapInterface.onTwoPointerTap(it)
}
}
launch {
view.onPan.collect {
mapState.onPan(it)
mapInterface.onPan(it)
}
}
launch {
view.mapRotation.collect {
mapState.onViewpointRotationChanged(it)
mapInterface.onViewpointRotationChanged(it)
}
}
launch {
view.viewpointChanged.collect {
view.getCurrentViewpoint(ViewpointType.CenterAndScale)?.let {
mapState.onViewpointChanged(it)
mapInterface.onViewpointChanged(it)
}
}
}
Expand All @@ -117,12 +117,12 @@ public fun ComposableMap(

LaunchedEffect(Unit) {
launch {
mapState.mapRotation.collect(DuplexFlow.Type.Write) {
mapInterface.mapRotation.collect(DuplexFlow.Type.Write) {
mapView.setViewpointRotation(it)
}
}
launch {
mapState.viewpoint.collect(DuplexFlow.Type.Write) {
mapInterface.viewpoint.collect(DuplexFlow.Type.Write) {
it?.let {
mapView.setViewpoint(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ public interface MapEvents {
* An interface for consumption by [ComposableMap]. This interface represents the state needed
* for [ComposableMap] to re/compose.
*/
public interface MapState : MapEvents {
public interface MapInterface : MapEvents {
/**
* The model for [ComposableMap]
*/
public val map: StateFlow<ArcGISMap?>
public val map: StateFlow<ArcGISMap>

/**
* Insets to apply to the Box which contains the [ComposableMap]
Expand All @@ -154,22 +154,22 @@ public interface MapState : MapEvents {
}

/**
* Factory function for the default implementation of [MapState]
* Factory function for the default implementation of [MapInterface]
*/
public fun MapState(map: ArcGISMap? = null, mapInsets: MapInsets = MapInsets()): MapState =
MapStateImpl(map, mapInsets)
public fun MapInterface(arcGISMap: ArcGISMap, mapInsets: MapInsets = MapInsets()): MapInterface =
MapInterfaceImpl(arcGISMap, mapInsets)

/**
* A default implementation for the [MapState]
* A default implementation for the [MapInterface]
*/

public class MapStateImpl(
map: ArcGISMap?,
public class MapInterfaceImpl(
arcGISMap: ArcGISMap,
mapInsets: MapInsets = MapInsets()
) : MapState {
) : MapInterface {

private val _map: MutableStateFlow<ArcGISMap?> = MutableStateFlow(map)
override val map: StateFlow<ArcGISMap?> = _map.asStateFlow()
private val _map: MutableStateFlow<ArcGISMap> = MutableStateFlow(arcGISMap)
override val map: StateFlow<ArcGISMap> = _map.asStateFlow()

private val _insets: MutableStateFlow<MapInsets> = MutableStateFlow(mapInsets)
override val insets: StateFlow<MapInsets> = _insets.asStateFlow()
Expand Down