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 4 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

/**
* Data class for attribution bar related properties/events on the [com.arcgismaps.toolkit.geocompose.MapView].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wording nitpick...

Suggested change
* Data class for attribution bar related properties/events on the [com.arcgismaps.toolkit.geocompose.MapView].
* 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 @@ -64,6 +64,7 @@ import kotlinx.coroutines.launch
* @param viewLabelProperties the [ViewLabelProperties] used by the composable [com.arcgismaps.toolkit.geocompose.MapView]
* @param selectionProperties the [SelectionProperties] used by the composable [com.arcgismaps.toolkit.geocompose.MapView]
* @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 @@ -84,11 +85,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(),
onViewpointChanged: (() -> Unit)? = null,
onInteractingChanged: ((isInteracting: Boolean) -> Unit)? = null,
onRotate: ((RotationChangeEvent) -> Unit)? = null,
Expand Down Expand Up @@ -131,6 +133,8 @@ public fun MapView(
}
}

AttributionStateHandler(mapView, attributionState)

MapViewEventHandler(
mapView,
onViewpointChanged,
Expand All @@ -149,6 +153,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 MapView events.
*/
Expand Down