Skip to content

Commit

Permalink
Add stable area changed callback
Browse files Browse the repository at this point in the history
  • Loading branch information
kmadsen committed Sep 6, 2022
1 parent 75fd274 commit 03ac46a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ void getters(MapboxCarMap mapboxCarMap) {
CarContext carContext = mapboxCarMap.getCarContext();
Rect visibleArea = mapboxCarMap.getVisibleArea();
EdgeInsets edgeInsets = mapboxCarMap.getEdgeInsets();
Rect stableArea = mapboxCarMap.getStableArea();
EdgeInsets stableEdgeInsets = mapboxCarMap.getStableEdgeInsets();
MapboxCarMapSurface mapboxCarMapSurface = mapboxCarMap.getCarMapSurface();
}

Expand All @@ -49,6 +51,11 @@ public void onVisibleAreaChanged(@NonNull Rect visibleArea, @NonNull EdgeInsets

}

@Override
public void onStableAreaChanged(@NonNull Rect stableArea, @NonNull EdgeInsets edgeInsets) {

}

@Override
public void onDetached(@NonNull MapboxCarMapSurface mapboxCarMapSurface) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ internal class CarMapSurfaceOwner(
private set
internal var visibleCenter: ScreenCoordinate = visibleCenter()
private set
internal var stableArea: Rect? = null
private set
internal var stableEdgeInsets: EdgeInsets? = null

internal lateinit var carContext: CarContext
internal lateinit var mapInitOptions: MapInitOptions
Expand Down Expand Up @@ -122,7 +125,15 @@ internal class CarMapSurfaceOwner(
}

override fun onStableAreaChanged(stableArea: Rect) {
// Have not found a need for this.
logI(TAG, "onStableAreaChanged stableArea:$stableArea")
this.stableEdgeInsets = stableArea.edgeInsets()
this.stableArea = stableArea
ifNonNull(mapboxCarMapSurface, stableArea, stableEdgeInsets) { _, area, edge ->
logI(TAG, "notifyStableAreaChanged $area $edge")
carMapObservers.forEach {
it.onStableAreaChanged(area, edge)
}
}
}

override fun onScroll(distanceX: Float, distanceY: Float) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ class MapboxCarMap {
val edgeInsets: EdgeInsets?
get() { return carMapSurfaceOwner.edgeInsets }

/**
* Accessor to the stable area calculated by the car library. It is recommended to
* use the values returned by [MapboxCarMapObserver.onStableAreaChanged].
*/
val stableArea: Rect?
get() { return carMapSurfaceOwner.stableArea }

/**
* Accessor to the stableEdgeInsets calculated by the car library. It is recommended to
* use the values returned by [MapboxCarMapObserver.onStableAreaChanged].
*/
val stableEdgeInsets: EdgeInsets?
get() { return carMapSurfaceOwner.stableEdgeInsets }

/**
* @param mapboxCarMapObserver implements the desired mapbox car experiences
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,15 @@ interface MapboxCarMapObserver {
fun onVisibleAreaChanged(visibleArea: Rect, edgeInsets: EdgeInsets) {
// No op by default
}

/**
* Called when the car library updates the stable region for the surface. This area will remain
* constant while the visible area changes when views come in and out of view.
*
* @param stableArea the stable area provided by the host
* @param edgeInsets distance from each side of the screen that creates the [stableArea]
*/
fun onStableAreaChanged(stableArea: Rect, edgeInsets: EdgeInsets) {
// No op by default
}
}

0 comments on commit 03ac46a

Please sign in to comment.