Skip to content

Commit

Permalink
feat(v11): add slot to layers (#3196)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas authored Nov 22, 2023
1 parent 1b1721b commit 3ac008a
Show file tree
Hide file tree
Showing 54 changed files with 1,293 additions and 657 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.facebook.react.viewmanagers.RNMBXCircleLayerManagerInterface

class RNMBXCircleLayerManager : ViewGroupManager<RNMBXCircleLayer>(),
RNMBXCircleLayerManagerInterface<RNMBXCircleLayer> {

override fun getName(): String {
return REACT_CLASS
}
Expand All @@ -16,6 +17,7 @@ class RNMBXCircleLayerManager : ViewGroupManager<RNMBXCircleLayer>(),
return RNMBXCircleLayer(reactContext)
}

// @{codepart-replace-start(LayerManagerCommonProps.codepart-kt.ejs,{layerType:"RNMBXCircleLayer"})}
@ReactProp(name = "id")
override fun setId(layer: RNMBXCircleLayer, id: Dynamic) {
layer.iD = id.asString()
Expand Down Expand Up @@ -71,6 +73,12 @@ class RNMBXCircleLayerManager : ViewGroupManager<RNMBXCircleLayer>(),
layer.setFilter(filterList.asArray())
}

@ReactProp(name = "slot")
override fun setSlot(layer: RNMBXCircleLayer, slot: Dynamic) {
layer.setSlot(slot.asString())
}
// @{codepart-replace-end}

companion object {
const val REACT_CLASS = "RNMBXCircleLayer"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RNMBXFillLayerManager : ViewGroupManager<RNMBXFillLayer>(),
return RNMBXFillLayer(reactContext)
}

// @{codepart-replace-start(LayerManagerCommonProps.codepart-kt.ejs,{layerType:"RNMBXFillLayer"})}
@ReactProp(name = "id")
override fun setId(layer: RNMBXFillLayer, id: Dynamic) {
layer.iD = id.asString()
Expand All @@ -31,11 +32,6 @@ class RNMBXFillLayerManager : ViewGroupManager<RNMBXFillLayer>(),
layer.setSourceID(sourceID.asString())
}

@ReactProp(name = "sourceLayerID")
override fun setSourceLayerID(layer: RNMBXFillLayer, sourceLayerID: Dynamic) {
layer.setSourceLayerID(sourceLayerID.asString())
}

@ReactProp(name = "aboveLayerID")
override fun setAboveLayerID(layer: RNMBXFillLayer, aboveLayerID: Dynamic) {
layer.setAboveLayerID(aboveLayerID.asString())
Expand Down Expand Up @@ -66,11 +62,22 @@ class RNMBXFillLayerManager : ViewGroupManager<RNMBXFillLayer>(),
layer.setReactStyle(style.asMap())
}

@ReactProp(name = "sourceLayerID")
override fun setSourceLayerID(layer: RNMBXFillLayer, sourceLayerID: Dynamic) {
layer.setSourceLayerID(sourceLayerID.asString())
}

@ReactProp(name = "filter")
override fun setFilter(layer: RNMBXFillLayer, filterList: Dynamic) {
layer.setFilter(filterList.asArray())
}

@ReactProp(name = "slot")
override fun setSlot(layer: RNMBXFillLayer, slot: Dynamic) {
layer.setSlot(slot.asString())
}
// @{codepart-replace-end}

companion object {
const val REACT_CLASS = "RNMBXFillLayer"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RNMBXHeatmapLayerManager : ViewGroupManager<RNMBXHeatmapLayer>(),
return RNMBXHeatmapLayer(reactContext)
}

// @{codepart-replace-start(LayerManagerCommonProps.codepart-kt.ejs,{layerType:"RNMBXHeatmapLayer"})}
@ReactProp(name = "id")
override fun setId(layer: RNMBXHeatmapLayer, id: Dynamic) {
layer.iD = id.asString()
Expand Down Expand Up @@ -71,6 +72,12 @@ class RNMBXHeatmapLayerManager : ViewGroupManager<RNMBXHeatmapLayer>(),
layer.setFilter(filterList.asArray())
}

@ReactProp(name = "slot")
override fun setSlot(layer: RNMBXHeatmapLayer, slot: Dynamic) {
layer.setSlot(slot.asString())
}
// @{codepart-replace-end}

companion object {
const val REACT_CLASS = "RNMBXHeatmapLayer"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.rnmapbox.rnmbx.components.RemovalReason
import com.rnmapbox.rnmbx.utils.ExpressionParser
import java.lang.ClassCastException
import com.rnmapbox.rnmbx.utils.Logger
import com.rnmapbox.rnmbx.v11compat.layer.*

abstract class RNMBXLayer<T : Layer?>(protected var mContext: Context) : AbstractSourceConsumer(
mContext
Expand Down Expand Up @@ -133,6 +134,13 @@ abstract class RNMBXLayer<T : Layer?>(protected var mContext: Context) : Abstrac
}
}

var mSlot: String? = null

fun setSlot(slot: String?) {
mSlot = slot
applySlot()
}

fun setExisting(existing: Boolean) {
mExisting = existing
}
Expand Down Expand Up @@ -232,16 +240,27 @@ abstract class RNMBXLayer<T : Layer?>(protected var mContext: Context) : Abstrac
add ()
} } }
}
setZoomBounds()
applyZoomBounds()
applySlot()
}
}

protected fun setZoomBounds() {
if (mMaxZoomLevel != null) {
mLayer!!.maxZoom(mMaxZoomLevel!!.toFloat().toDouble())
protected fun applyZoomBounds() {
mLayer?.let {layer ->
mMaxZoomLevel?.let {
layer.maxZoom(it.toDouble())
}
mMinZoomLevel?.let {
layer.minZoom(it.toDouble())
}
}
if (mMinZoomLevel != null) {
mLayer!!.minZoom(mMinZoomLevel!!.toFloat().toDouble())
}

protected fun applySlot() {
mLayer?.let { layer ->
mSlot?.let {
layer.slot(it)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RNMBXLineLayerManager : ViewGroupManager<RNMBXLineLayer>(),
return RNMBXLineLayer(reactContext)
}

// @{codepart-replace-start(LayerManagerCommonProps.codepart-kt.ejs,{layerType:"RNMBXLineLayer"})}
@ReactProp(name = "id")
override fun setId(layer: RNMBXLineLayer, id: Dynamic) {
layer.iD = id.asString()
Expand Down Expand Up @@ -71,6 +72,12 @@ class RNMBXLineLayerManager : ViewGroupManager<RNMBXLineLayer>(),
layer.setFilter(filterList.asArray())
}

@ReactProp(name = "slot")
override fun setSlot(layer: RNMBXLineLayer, slot: Dynamic) {
layer.setSlot(slot.asString())
}
// @{codepart-replace-end}

companion object {
const val REACT_CLASS = "RNMBXLineLayer"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ class RNMBXRasterLayer(context: Context?) : RNMBXLayer<RasterLayer?>(
Logger.e("RNMBXRasterLayer", "mLayer is null")
}
}

fun setSourceLayerID(asString: String?) {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RNMBXRasterLayerManager : ViewGroupManager<RNMBXRasterLayer>(),
return RNMBXRasterLayer(reactContext)
}

// @{codepart-replace-start(LayerManagerCommonProps.codepart-kt.ejs,{layerType:"RNMBXRasterLayer"})}
@ReactProp(name = "id")
override fun setId(layer: RNMBXRasterLayer, id: Dynamic) {
layer.iD = id.asString()
Expand Down Expand Up @@ -63,15 +64,20 @@ class RNMBXRasterLayerManager : ViewGroupManager<RNMBXRasterLayer>(),

@ReactProp(name = "sourceLayerID")
override fun setSourceLayerID(layer: RNMBXRasterLayer, sourceLayerID: Dynamic) {
// not available
// layer.setSourceLayerID(sourceLayerID.asString())
layer.setSourceLayerID(sourceLayerID.asString())
}

@ReactProp(name = "filter")
override fun setFilter(layer: RNMBXRasterLayer, filterList: Dynamic) {
layer.setFilter(filterList.asArray())
}

@ReactProp(name = "slot")
override fun setSlot(layer: RNMBXRasterLayer, slot: Dynamic) {
layer.setSlot(slot.asString())
}
// @{codepart-replace-end}

companion object {
const val REACT_CLASS = "RNMBXRasterLayer"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RNMBXSymbolLayerManager : ViewGroupManager<RNMBXSymbolLayer>(),
return RNMBXSymbolLayer(reactContext)
}

// @{codepart-replace-start(LayerManagerCommonProps.codepart-kt.ejs,{layerType:"RNMBXSymbolLayer"})}
@ReactProp(name = "id")
override fun setId(layer: RNMBXSymbolLayer, id: Dynamic) {
layer.iD = id.asString()
Expand Down Expand Up @@ -71,6 +72,13 @@ class RNMBXSymbolLayerManager : ViewGroupManager<RNMBXSymbolLayer>(),
layer.setFilter(filterList.asArray())
}

@ReactProp(name = "slot")
override fun setSlot(layer: RNMBXSymbolLayer, slot: Dynamic) {
layer.setSlot(slot.asString())
}

// @{codepart-replace-end}

companion object {
const val REACT_CLASS = "RNMBXSymbolLayer"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@ReactProp(name = "id")
override fun setId(layer: <%= layerType %>, id: Dynamic) {
layer.iD = id.asString()
}

@ReactProp(name = "existing")
override fun setExisting(layer: <%= layerType %>, existing: Dynamic) {
layer.setExisting(existing.asBoolean())
}

@ReactProp(name = "sourceID")
override fun setSourceID(layer: <%= layerType %>, sourceID: Dynamic) {
layer.setSourceID(sourceID.asString())
}

@ReactProp(name = "aboveLayerID")
override fun setAboveLayerID(layer: <%= layerType %>, aboveLayerID: Dynamic) {
layer.setAboveLayerID(aboveLayerID.asString())
}

@ReactProp(name = "belowLayerID")
override fun setBelowLayerID(layer: <%= layerType %>, belowLayerID: Dynamic) {
layer.setBelowLayerID(belowLayerID.asString())
}

@ReactProp(name = "layerIndex")
override fun setLayerIndex(layer: <%= layerType %>, layerIndex: Dynamic) {
layer.setLayerIndex(layerIndex.asInt())
}

@ReactProp(name = "minZoomLevel")
override fun setMinZoomLevel(layer: <%= layerType %>, minZoomLevel: Dynamic) {
layer.setMinZoomLevel(minZoomLevel.asDouble())
}

@ReactProp(name = "maxZoomLevel")
override fun setMaxZoomLevel(layer: <%= layerType %>, maxZoomLevel: Dynamic) {
layer.setMaxZoomLevel(maxZoomLevel.asDouble())
}

@ReactProp(name = "reactStyle")
override fun setReactStyle(layer: <%= layerType %>, style: Dynamic) {
layer.setReactStyle(style.asMap())
}

@ReactProp(name = "sourceLayerID")
override fun setSourceLayerID(layer: <%= layerType %>, sourceLayerID: Dynamic) {
layer.setSourceLayerID(sourceLayerID.asString())
}

@ReactProp(name = "filter")
override fun setFilter(layer: <%= layerType %>, filterList: Dynamic) {
layer.setFilter(filterList.asArray())
}

@ReactProp(name = "slot")
override fun setSlot(layer: <%= layerType %>, slot: Dynamic) {
layer.setSlot(slot.asString())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.rnmapbox.rnmbx.v11compat.layer;

import com.mapbox.maps.extension.style.layers.Layer

fun Layer.slot(slot: String) {
// V11 only
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.rnmapbox.rnmbx.v11compat.layer;

import com.mapbox.maps.extension.style.layers.Layer
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public RNMBXCircleLayerManagerDelegate(U viewManager) {
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case "id":
mViewManager.setId(view, new DynamicFromObject(value));
break;
case "sourceID":
mViewManager.setSourceID(view, new DynamicFromObject(value));
break;
Expand All @@ -43,9 +40,6 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "layerIndex":
mViewManager.setLayerIndex(view, new DynamicFromObject(value));
break;
case "reactStyle":
mViewManager.setReactStyle(view, new DynamicFromObject(value));
break;
case "maxZoomLevel":
mViewManager.setMaxZoomLevel(view, new DynamicFromObject(value));
break;
Expand All @@ -55,6 +49,15 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "sourceLayerID":
mViewManager.setSourceLayerID(view, new DynamicFromObject(value));
break;
case "slot":
mViewManager.setSlot(view, new DynamicFromObject(value));
break;
case "id":
mViewManager.setId(view, new DynamicFromObject(value));
break;
case "reactStyle":
mViewManager.setReactStyle(view, new DynamicFromObject(value));
break;
default:
super.setProperty(view, propName, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
import com.facebook.react.bridge.Dynamic;

public interface RNMBXCircleLayerManagerInterface<T extends View> {
void setId(T view, Dynamic value);
void setSourceID(T view, Dynamic value);
void setExisting(T view, Dynamic value);
void setFilter(T view, Dynamic value);
void setAboveLayerID(T view, Dynamic value);
void setBelowLayerID(T view, Dynamic value);
void setLayerIndex(T view, Dynamic value);
void setReactStyle(T view, Dynamic value);
void setMaxZoomLevel(T view, Dynamic value);
void setMinZoomLevel(T view, Dynamic value);
void setSourceLayerID(T view, Dynamic value);
void setSlot(T view, Dynamic value);
void setId(T view, Dynamic value);
void setReactStyle(T view, Dynamic value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public RNMBXFillLayerManagerDelegate(U viewManager) {
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case "id":
mViewManager.setId(view, new DynamicFromObject(value));
break;
case "sourceID":
mViewManager.setSourceID(view, new DynamicFromObject(value));
break;
Expand All @@ -43,9 +40,6 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "layerIndex":
mViewManager.setLayerIndex(view, new DynamicFromObject(value));
break;
case "reactStyle":
mViewManager.setReactStyle(view, new DynamicFromObject(value));
break;
case "maxZoomLevel":
mViewManager.setMaxZoomLevel(view, new DynamicFromObject(value));
break;
Expand All @@ -55,6 +49,15 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "sourceLayerID":
mViewManager.setSourceLayerID(view, new DynamicFromObject(value));
break;
case "slot":
mViewManager.setSlot(view, new DynamicFromObject(value));
break;
case "id":
mViewManager.setId(view, new DynamicFromObject(value));
break;
case "reactStyle":
mViewManager.setReactStyle(view, new DynamicFromObject(value));
break;
default:
super.setProperty(view, propName, value);
}
Expand Down
Loading

0 comments on commit 3ac008a

Please sign in to comment.