Skip to content

add support for attribution text #187

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 7 commits into from
Nov 9, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* COPYRIGHT 1995-2023 ESRI
*
* TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
* Unpublished material - all rights reserved under the
* Copyright Laws of the United States.
*
* For additional information, contact:
* Environmental Systems Research Institute, Inc.
* Attn: Contracts Dept
* 380 New York Street
* Redlands, California, USA 92373
*
* email: [email protected]
*/

package com.arcgismaps.toolkit.geocompose

import androidx.compose.runtime.Stable
import com.arcgismaps.mapping.view.AttributionBarLayoutChangeEvent

/**
* State holder for attribution bar related properties/events on the [com.arcgismaps.toolkit.geocompose.MapView].
*
* @since 200.3.0
*/
@Stable
public data class AttributionState(
val isAttributionBarVisible: Boolean = true,
val onAttributionTextChanged: ((String) -> Unit)? = null,
val onAttributionBarLayoutChanged: ((AttributionBarLayoutChangeEvent) -> Unit)? = null
)

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import kotlinx.coroutines.launch
* @param grid represents the display of a coordinate system [Grid] on the composable MapView
* @param backgroundGrid the default color and context grid behind the map surface
* @param wrapAroundMode the [WrapAroundMode] to specify whether continuous panning across the international date line is enabled
* @param attributionState specifies the attribution bar's visibility, text changed and layout changed events
* @param onViewpointChanged lambda invoked when the viewpoint of the composable MapView has changed
* @param onInteractingChanged lambda invoked when the user starts and ends interacting with the composable MapView
* @param onRotate lambda invoked when a user performs a rotation gesture on the composable MapView
Expand All @@ -90,11 +91,12 @@ public fun MapView(
arcGISMap: ArcGISMap? = null,
graphicsOverlays: GraphicsOverlayCollection = rememberGraphicsOverlayCollection(),
locationDisplay: LocationDisplay = rememberLocationDisplay(),
wrapAroundMode: WrapAroundMode = WrapAroundMode.EnabledWhenSupported,
geometryEditor: GeometryEditor? = null,
mapViewInteractionOptions: MapViewInteractionOptions = MapViewInteractionOptions(),
viewLabelProperties: ViewLabelProperties = ViewLabelProperties(),
selectionProperties: SelectionProperties = SelectionProperties(),
wrapAroundMode: WrapAroundMode = WrapAroundMode.EnabledWhenSupported,
attributionState: AttributionState = AttributionState(),
grid: Grid? = null,
backgroundGrid: BackgroundGrid = BackgroundGrid(),
onViewpointChanged: (() -> Unit)? = null,
Expand Down Expand Up @@ -142,6 +144,8 @@ public fun MapView(
}
}

AttributionStateHandler(mapView, attributionState)

MapViewEventHandler(
mapView,
onViewpointChanged,
Expand All @@ -161,6 +165,27 @@ public fun MapView(
GraphicsOverlaysUpdater(graphicsOverlays, mapView)
}

/**
* Sets up the attribution bar's property and events.
*/
@Composable
private fun AttributionStateHandler(mapView: MapView, attributionState: AttributionState) {
LaunchedEffect(attributionState) {
// isAttributionBarVisible does not take effect if applied in the AndroidView update callback
mapView.isAttributionBarVisible = attributionState.isAttributionBarVisible
launch {
mapView.attributionText.collect {
attributionState.onAttributionTextChanged?.invoke(it)
}
}
launch {
mapView.onAttributionBarLayoutChanged.collect { attributionBarLayoutChangedEvent ->
attributionState.onAttributionBarLayoutChanged?.invoke(attributionBarLayoutChangedEvent)
}
}
}
}

/**
* Sets up the callbacks for all the view-based [mapView] events.
*/
Expand Down