Skip to content

SceneView: attribution #247

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
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
Expand Up @@ -17,8 +17,12 @@

package com.arcgismaps.toolkit.geocompose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.Stable
import com.arcgismaps.mapping.view.AttributionBarLayoutChangeEvent
import com.arcgismaps.mapping.view.GeoView
import kotlinx.coroutines.launch

/**
* State holder for attribution bar related properties/events on the [com.arcgismaps.toolkit.geocompose.MapView].
Expand All @@ -32,3 +36,28 @@ public data class AttributionState(
val onAttributionBarLayoutChanged: ((AttributionBarLayoutChangeEvent) -> Unit)? = null
)

/**
* Sets up the attribution bar's property and events.
*
* @since 200.4.0
*/
Copy link
Collaborator

@changanxian changanxian Dec 19, 2023

Choose a reason for hiding this comment

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

missing since tag

Copy link
Collaborator

Choose a reason for hiding this comment

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

updated

@Composable
internal fun AttributionStateHandler(geoView: GeoView, attributionState: AttributionState) {
LaunchedEffect(attributionState) {
// isAttributionBarVisible does not take effect if applied in the AndroidView update callback
geoView.isAttributionBarVisible = attributionState.isAttributionBarVisible
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this line be outside the LaunchedEffect function?

Copy link
Collaborator

@gunt0001 gunt0001 Dec 20, 2023

Choose a reason for hiding this comment

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

It probably could be outside of the LaunchedEffect, but I don't think it matters in this case. The LaunchedEffect will be recomposed with every change of attributionState, and then we simply apply all the AttributionState properties to the GeoView "in one go".

launch {
geoView.attributionText.collect {
attributionState.onAttributionTextChanged?.invoke(it)
}
}
launch {
geoView.onAttributionBarLayoutChanged.collect { attributionBarLayoutChangedEvent ->
attributionState.onAttributionBarLayoutChanged?.invoke(
attributionBarLayoutChangedEvent
)
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -254,29 +254,6 @@ private fun ViewpointChangedStateHandler(
}
}

/**
* 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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import kotlinx.coroutines.launch
* @param graphicsOverlays the [GraphicsOverlayCollection] used by this composable SceneView
* @param sceneViewProxy the [SceneViewProxy] to associate with the composable SceneView
* @param viewLabelProperties the [ViewLabelProperties] used by the composable SceneView
* @param attributionState specifies the attribution bar's visibility, text changed and layout changed events
* @param onNavigationChanged lambda invoked when the navigation status of the composable SceneView has changed
* @param onInteractingChanged lambda invoked when the user starts and ends interacting with the composable SceneView
* @param onRotate lambda invoked when a user performs a rotation gesture on the composable SceneView
Expand All @@ -74,6 +75,7 @@ public fun SceneView(
graphicsOverlays: GraphicsOverlayCollection = rememberGraphicsOverlayCollection(),
sceneViewProxy: SceneViewProxy? = null,
viewLabelProperties: ViewLabelProperties = ViewLabelProperties(),
attributionState: AttributionState = AttributionState(),
onNavigationChanged: ((isNavigating: Boolean) -> Unit)? = null,
onInteractingChanged: ((isInteracting: Boolean) -> Unit)? = null,
onRotate: ((RotationChangeEvent) -> Unit)? = null,
Expand Down Expand Up @@ -117,6 +119,8 @@ public fun SceneView(

GraphicsOverlaysUpdater(graphicsOverlays, sceneView)

AttributionStateHandler(sceneView, attributionState)

SceneViewEventHandler(
sceneView,
onNavigationChanged,
Expand Down