Skip to content
Open
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 @@ -159,14 +159,14 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
_updateViewportState();
}

fun setFollowPadding(padding: ReadableMap) {
fun setFollowPadding(padding: ReadableMap?) {
// scale padding by pixel ratio
val metrics = context.resources.displayMetrics
val edgeInsets = EdgeInsets(
if (padding.hasKey("paddingTop")) padding.getDouble("paddingTop") * metrics.density else 0.0,
if (padding.hasKey("paddingLeft")) padding.getDouble("paddingLeft") * metrics.density else 0.0,
if (padding.hasKey("paddingBottom")) padding.getDouble("paddingBottom") * metrics.density else 0.0,
if (padding.hasKey("paddingRight")) padding.getDouble("paddingRight") * metrics.density else 0.0,
if (padding?.hasKey("paddingTop") == true) padding.getDouble("paddingTop") * metrics.density else 0.0,
if (padding?.hasKey("paddingLeft") == true) padding.getDouble("paddingLeft") * metrics.density else 0.0,
if (padding?.hasKey("paddingBottom") == true) padding.getDouble("paddingBottom") * metrics.density else 0.0,
if (padding?.hasKey("paddingRight") == true) padding.getDouble("paddingRight") * metrics.density else 0.0,
)

mFollowPadding = edgeInsets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,8 @@ class RNMBXCameraManager(private val mContext: ReactApplicationContext, val view

@ReactProp(name = "followPadding")
override fun setFollowPadding(camera: RNMBXCamera, value: Dynamic) {
val mapValue = value.asMap()
if (mapValue == null) {
Logger.e("RNMBXCameraManager", "followPadding map is null")
return
}
camera.setFollowPadding(mapValue)
// unset: no padding
camera.setFollowPadding(if (value.isNull) null else value.asMap())
}

@ReactProp(name = "maxBounds")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
changes.add(Property.COMPASS)
}

fun setReactCompassViewMargins(compassViewMargins: ReadableMap) {
fun setReactCompassViewMargins(compassViewMargins: ReadableMap?) {
mCompassSettings.margins = compassViewMargins
changes.add(Property.COMPASS)
}
Expand All @@ -1711,7 +1711,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
changes.add(Property.COMPASS)
}

fun setReactCompassPosition(compassPosition: ReadableMap) {
fun setReactCompassPosition(compassPosition: ReadableMap?) {
mCompassSettings.setPosAndMargins(compassPosition)
changes.add(Property.COMPASS)
}
Expand Down Expand Up @@ -1766,7 +1766,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
changes.add(Property.SCALEBAR)
}

fun setReactScaleBarPosition(scaleBarPosition: ReadableMap) {
fun setReactScaleBarPosition(scaleBarPosition: ReadableMap?) {
mScaleBarSettings.setPosAndMargins(scaleBarPosition)
changes.add(Property.SCALEBAR)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import com.rnmapbox.rnmbx.utils.ViewTagResolver
import com.rnmapbox.rnmbx.utils.extensions.getAndLogIfNotBoolean
import com.rnmapbox.rnmbx.utils.extensions.getAndLogIfNotDouble
import com.rnmapbox.rnmbx.utils.extensions.getAndLogIfNotMap
import com.rnmapbox.rnmbx.utils.extensions.asBooleanOrNull
import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
import com.rnmapbox.rnmbx.utils.extensions.asStringOrNull
import java.lang.Exception
import java.util.HashMap

Expand Down Expand Up @@ -129,7 +132,7 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso
// region React Props
@ReactProp(name = "projection")
override fun setProjection(mapView: RNMBXMapView, projection: Dynamic) {
mapView.setReactProjection( if (projection.asString() == "globe") ProjectionName.GLOBE else ProjectionName.MERCATOR )
mapView.setReactProjection( if (projection.asStringOrNull() == "globe") ProjectionName.GLOBE else ProjectionName.MERCATOR )
}

@ReactProp(name = "localizeLabels")
Expand Down Expand Up @@ -246,15 +249,19 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso

@ReactProp(name = "preferredFramesPerSecond")
override fun setPreferredFramesPerSecond(mapView: RNMBXMapView, preferredFramesPerSecond: Dynamic) {
// unset: Android has no way to restore the uncapped default, keep the current cap
if (preferredFramesPerSecond.isNull) return
mapView.setReactPreferredFramesPerSecond(preferredFramesPerSecond.asInt())
}

@ReactProp(name = "zoomEnabled")
override fun setZoomEnabled(map: RNMBXMapView, zoomEnabled: Dynamic) {
// unset: back to the Mapbox default, enabled
val enabled = zoomEnabled.asBooleanOrNull() ?: true
map.withMapView {
it.gestures.pinchToZoomEnabled = zoomEnabled.asBoolean()
it.gestures.doubleTouchToZoomOutEnabled = zoomEnabled.asBoolean()
it.gestures.doubleTapToZoomInEnabled = zoomEnabled.asBoolean()
it.gestures.pinchToZoomEnabled = enabled
it.gestures.doubleTouchToZoomOutEnabled = enabled
it.gestures.doubleTapToZoomInEnabled = enabled
}
}

Expand Down Expand Up @@ -323,11 +330,8 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso

@ReactProp(name = "attributionPosition")
override fun setAttributionPosition(mapView: RNMBXMapView, attributionPosition: Dynamic) {
val mapValue = attributionPosition.asMap()
if (mapValue == null) {
Logger.e(LOG_TAG, "attributionPosition map is null")
return
}
// unset: keep the current position, the setters have no "default" to go back to
val mapValue = attributionPosition.asMapOrNull() ?: return
mapView.setReactAttributionPosition(mapValue)
}

Expand All @@ -353,11 +357,8 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso

@ReactProp(name = "logoPosition")
override fun setLogoPosition(mapView: RNMBXMapView, logoPosition: Dynamic) {
val mapValue = logoPosition.asMap()
if (mapValue == null) {
Logger.e(LOG_TAG, "logoPosition map is null")
return
}
// unset: keep the current position, the setters have no "default" to go back to
val mapValue = logoPosition.asMapOrNull() ?: return
mapView.setReactLogoPosition(mapValue)
}

Expand All @@ -378,17 +379,14 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso

@ReactProp(name = "scaleBarPosition")
override fun setScaleBarPosition(mapView: RNMBXMapView, scaleBarPosition: Dynamic) {
val mapValue = scaleBarPosition.asMap()
if (mapValue == null) {
Logger.e(LOG_TAG, "scaleBarPosition map is null")
return
}
// unset: keep the current position, the setters have no "default" to go back to
val mapValue = scaleBarPosition.asMapOrNull() ?: return
mapView.setReactScaleBarPosition(mapValue)
}

@ReactProp(name = "scaleBarUnits")
override fun setScaleBarUnits(mapView: RNMBXMapView, scaleBarUnits: Dynamic) {
mapView.setReactScaleBarUnits(scaleBarUnits.asString())
mapView.setReactScaleBarUnits(scaleBarUnits.asStringOrNull())
}

@ReactProp(name = "compassEnabled")
Expand All @@ -403,26 +401,20 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso

@ReactProp(name = "compassViewMargins")
override fun setCompassViewMargins(mapView: RNMBXMapView, compassViewMargins: Dynamic) {
val mapValue = compassViewMargins.asMap()
if (mapValue == null) {
Logger.e(LOG_TAG, "compassViewMargins map is null")
return
}
// unset: keep the current position, the setters have no "default" to go back to
val mapValue = compassViewMargins.asMapOrNull() ?: return
mapView.setReactCompassViewMargins(mapValue)
}

@ReactProp(name = "compassViewPosition")
override fun setCompassViewPosition(mapView: RNMBXMapView, compassViewPosition: Dynamic) {
mapView.setReactCompassViewPosition(compassViewPosition.asInt())
mapView.setReactCompassViewPosition(if (compassViewPosition.isNull) -1 else compassViewPosition.asInt())
}

@ReactProp(name = "compassPosition")
override fun setCompassPosition(mapView: RNMBXMapView, compassMargins: Dynamic) {
val mapValue = compassMargins.asMap()
if (mapValue == null) {
Logger.e(LOG_TAG, "compassPosition map is null")
return
}
// unset: keep the current position, the setters have no "default" to go back to
val mapValue = compassMargins.asMapOrNull() ?: return
mapView.setReactCompassPosition(mapValue)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.facebook.react.viewmanagers.RNMBXBackgroundLayerManagerInterface
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.RNMBXBackgroundLayerManagerDelegate
import com.rnmapbox.rnmbx.utils.extensions.asStringOrNull
import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
import com.rnmapbox.rnmbx.utils.extensions.asDoubleOrNull

class RNMBXBackgroundLayerManager : ViewGroupManager<RNMBXBackgroundLayer>(),
RNMBXBackgroundLayerManagerInterface<RNMBXBackgroundLayer> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.facebook.react.viewmanagers.RNMBXCircleLayerManagerInterface
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.RNMBXCircleLayerManagerDelegate
import com.rnmapbox.rnmbx.utils.extensions.asStringOrNull
import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
import com.rnmapbox.rnmbx.utils.extensions.asDoubleOrNull

class RNMBXCircleLayerManager : ViewGroupManager<RNMBXCircleLayer>(),
RNMBXCircleLayerManagerInterface<RNMBXCircleLayer> {
Expand Down Expand Up @@ -52,22 +54,22 @@ class RNMBXCircleLayerManager : ViewGroupManager<RNMBXCircleLayer>(),

@ReactProp(name = "layerIndex")
override fun setLayerIndex(layer: RNMBXCircleLayer, layerIndex: Dynamic) {
layer.setLayerIndex(layerIndex.asInt())
layer.setLayerIndex(if (layerIndex.isNull) null else layerIndex.asInt())
}

@ReactProp(name = "minZoomLevel")
override fun setMinZoomLevel(layer: RNMBXCircleLayer, minZoomLevel: Dynamic) {
layer.setMinZoomLevel(minZoomLevel.asDouble())
layer.setMinZoomLevel(minZoomLevel.asDoubleOrNull())
}

@ReactProp(name = "maxZoomLevel")
override fun setMaxZoomLevel(layer: RNMBXCircleLayer, maxZoomLevel: Dynamic) {
layer.setMaxZoomLevel(maxZoomLevel.asDouble())
layer.setMaxZoomLevel(maxZoomLevel.asDoubleOrNull())
}

@ReactProp(name = "reactStyle")
override fun setReactStyle(layer: RNMBXCircleLayer, style: Dynamic) {
layer.setReactStyle(style.asMap())
layer.setReactStyle(style.asMapOrNull())
}

@ReactProp(name = "sourceLayerID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.facebook.react.viewmanagers.RNMBXFillExtrusionLayerManagerInterface
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.RNMBXFillExtrusionLayerManagerDelegate
import com.rnmapbox.rnmbx.utils.extensions.asStringOrNull
import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
import com.rnmapbox.rnmbx.utils.extensions.asDoubleOrNull

class RNMBXFillExtrusionLayerManager : ViewGroupManager<RNMBXFillExtrusionLayer>(),
RNMBXFillExtrusionLayerManagerInterface<RNMBXFillExtrusionLayer> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.facebook.react.viewmanagers.RNMBXFillLayerManagerInterface
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.RNMBXFillLayerManagerDelegate
import com.rnmapbox.rnmbx.utils.extensions.asStringOrNull
import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
import com.rnmapbox.rnmbx.utils.extensions.asDoubleOrNull

class RNMBXFillLayerManager : ViewGroupManager<RNMBXFillLayer>(),
RNMBXFillLayerManagerInterface<RNMBXFillLayer> {
Expand Down Expand Up @@ -51,22 +53,22 @@ class RNMBXFillLayerManager : ViewGroupManager<RNMBXFillLayer>(),

@ReactProp(name = "layerIndex")
override fun setLayerIndex(layer: RNMBXFillLayer, layerIndex: Dynamic) {
layer.setLayerIndex(layerIndex.asInt())
layer.setLayerIndex(if (layerIndex.isNull) null else layerIndex.asInt())
}

@ReactProp(name = "minZoomLevel")
override fun setMinZoomLevel(layer: RNMBXFillLayer, minZoomLevel: Dynamic) {
layer.setMinZoomLevel(minZoomLevel.asDouble())
layer.setMinZoomLevel(minZoomLevel.asDoubleOrNull())
}

@ReactProp(name = "maxZoomLevel")
override fun setMaxZoomLevel(layer: RNMBXFillLayer, maxZoomLevel: Dynamic) {
layer.setMaxZoomLevel(maxZoomLevel.asDouble())
layer.setMaxZoomLevel(maxZoomLevel.asDoubleOrNull())
}

@ReactProp(name = "reactStyle")
override fun setReactStyle(layer: RNMBXFillLayer, style: Dynamic) {
layer.setReactStyle(style.asMap())
layer.setReactStyle(style.asMapOrNull())
}

@ReactProp(name = "sourceLayerID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.facebook.react.viewmanagers.RNMBXHeatmapLayerManagerInterface
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.RNMBXHeatmapLayerManagerDelegate
import com.rnmapbox.rnmbx.utils.extensions.asStringOrNull
import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
import com.rnmapbox.rnmbx.utils.extensions.asDoubleOrNull

class RNMBXHeatmapLayerManager : ViewGroupManager<RNMBXHeatmapLayer>(),
RNMBXHeatmapLayerManagerInterface<RNMBXHeatmapLayer> {
Expand Down Expand Up @@ -51,22 +53,22 @@ class RNMBXHeatmapLayerManager : ViewGroupManager<RNMBXHeatmapLayer>(),

@ReactProp(name = "layerIndex")
override fun setLayerIndex(layer: RNMBXHeatmapLayer, layerIndex: Dynamic) {
layer.setLayerIndex(layerIndex.asInt())
layer.setLayerIndex(if (layerIndex.isNull) null else layerIndex.asInt())
}

@ReactProp(name = "minZoomLevel")
override fun setMinZoomLevel(layer: RNMBXHeatmapLayer, minZoomLevel: Dynamic) {
layer.setMinZoomLevel(minZoomLevel.asDouble())
layer.setMinZoomLevel(minZoomLevel.asDoubleOrNull())
}

@ReactProp(name = "maxZoomLevel")
override fun setMaxZoomLevel(layer: RNMBXHeatmapLayer, maxZoomLevel: Dynamic) {
layer.setMaxZoomLevel(maxZoomLevel.asDouble())
layer.setMaxZoomLevel(maxZoomLevel.asDoubleOrNull())
}

@ReactProp(name = "reactStyle")
override fun setReactStyle(layer: RNMBXHeatmapLayer, style: Dynamic) {
layer.setReactStyle(style.asMap())
layer.setReactStyle(style.asMapOrNull())
}

@ReactProp(name = "sourceLayerID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.facebook.react.viewmanagers.RNMBXHillshadeLayerManagerInterface
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.RNMBXHillshadeLayerManagerDelegate
import com.rnmapbox.rnmbx.utils.extensions.asStringOrNull
import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
import com.rnmapbox.rnmbx.utils.extensions.asDoubleOrNull

class RNMBXHillshadeLayerManager : ViewGroupManager<RNMBXHillshadeLayer>(),
RNMBXHillshadeLayerManagerInterface<RNMBXHillshadeLayer> {
Expand Down Expand Up @@ -51,22 +53,22 @@ class RNMBXHillshadeLayerManager : ViewGroupManager<RNMBXHillshadeLayer>(),

@ReactProp(name = "layerIndex")
override fun setLayerIndex(layer: RNMBXHillshadeLayer, layerIndex: Dynamic) {
layer.setLayerIndex(layerIndex.asInt())
layer.setLayerIndex(if (layerIndex.isNull) null else layerIndex.asInt())
}

@ReactProp(name = "minZoomLevel")
override fun setMinZoomLevel(layer: RNMBXHillshadeLayer, minZoomLevel: Dynamic) {
layer.setMinZoomLevel(minZoomLevel.asDouble())
layer.setMinZoomLevel(minZoomLevel.asDoubleOrNull())
}

@ReactProp(name = "maxZoomLevel")
override fun setMaxZoomLevel(layer: RNMBXHillshadeLayer, maxZoomLevel: Dynamic) {
layer.setMaxZoomLevel(maxZoomLevel.asDouble())
layer.setMaxZoomLevel(maxZoomLevel.asDoubleOrNull())
}

@ReactProp(name = "reactStyle")
override fun setReactStyle(layer: RNMBXHillshadeLayer, style: Dynamic) {
layer.setReactStyle(style.asMap())
layer.setReactStyle(style.asMapOrNull())
}

@ReactProp(name = "sourceLayerID")
Expand Down
Loading