Skip to content
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

feat: migrate Camera to new arch #3090

Merged
merged 7 commits into from
Oct 2, 2023
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
@@ -1,8 +1,10 @@
package com.rnmapbox.rnmbx.components.camera
import com.facebook.react.bridge.Dynamic
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.RNMBXCameraManagerInterface
import com.mapbox.geojson.FeatureCollection
import com.rnmapbox.rnmbx.components.AbstractEventEmitter
import com.rnmapbox.rnmbx.components.camera.CameraStop.Companion.fromReadableMap
Expand All @@ -12,7 +14,7 @@ import com.rnmapbox.rnmbx.utils.GeoJSONUtils.toLatLngBounds
class RNMBXCameraManager(private val mContext: ReactApplicationContext) :
AbstractEventEmitter<RNMBXCamera?>(
mContext
) {
), RNMBXCameraManagerInterface<RNMBXCamera> {
override fun customEvents(): Map<String, String>? {
return HashMap()
}
Expand All @@ -26,82 +28,90 @@ class RNMBXCameraManager(private val mContext: ReactApplicationContext) :
}

@ReactProp(name = "stop")
fun setStop(camera: RNMBXCamera, map: ReadableMap?) {
if (map != null) {
val stop = fromReadableMap(mContext, map, null)
override fun setStop(camera: RNMBXCamera, map: Dynamic) {
if (!map.isNull) {
val stop = fromReadableMap(mContext, map.asMap(), null)
camera.setStop(stop)
}
}

@ReactProp(name = "defaultStop")
fun setDefaultStop(camera: RNMBXCamera, map: ReadableMap?) {
if (map != null) {
val stop = fromReadableMap(mContext, map, null)
override fun setDefaultStop(camera: RNMBXCamera, map: Dynamic) {
if (!map.isNull) {
val stop = fromReadableMap(mContext, map.asMap(), null)
camera.setDefaultStop(stop)
}
}

@ReactProp(name = "userTrackingMode")
fun setUserTrackingMode(camera: RNMBXCamera, userTrackingMode: Int) {
camera.setUserTrackingMode(userTrackingMode)
override fun setUserTrackingMode(camera: RNMBXCamera, userTrackingMode: Dynamic) {
camera.setUserTrackingMode(userTrackingMode.asInt())
throw AssertionError("Unused code")
}

@ReactProp(name = "zoomLevel")
fun setZoomLevel(camera: RNMBXCamera, zoomLevel: Double) {
camera.setZoomLevel(zoomLevel)
override fun setZoomLevel(camera: RNMBXCamera, zoomLevel: Dynamic) {
camera.setZoomLevel(zoomLevel.asDouble())
}

@ReactProp(name = "minZoomLevel")
fun setMinZoomLevel(camera: RNMBXCamera, value: Double) {
camera.setMinZoomLevel(value)
override fun setMinZoomLevel(camera: RNMBXCamera, value: Dynamic) {
camera.setMinZoomLevel(value.asDouble())
}

@ReactProp(name = "maxZoomLevel")
fun setMaxZoomLevel(camera: RNMBXCamera, value: Double) {
camera.setMaxZoomLevel(value)
override fun setMaxZoomLevel(camera: RNMBXCamera, value: Dynamic) {
camera.setMaxZoomLevel(value.asDouble())
}

@ReactProp(name = "followUserLocation")
fun setFollowUserLocation(camera: RNMBXCamera, value: Boolean) {
camera.setFollowUserLocation(value)
override fun setFollowUserLocation(camera: RNMBXCamera, value: Dynamic) {
camera.setFollowUserLocation(value.asBoolean())
}

@ReactProp(name = "followUserMode")
fun setFollowUserMode(camera: RNMBXCamera, value: String?) {
camera.setFollowUserMode(value)
override fun setFollowUserMode(camera: RNMBXCamera, value: Dynamic) {
camera.setFollowUserMode(value.asString())
}

@ReactProp(name = "followZoomLevel")
fun setFollowZoomLevel(camera: RNMBXCamera, value: Double) {
camera.setFollowZoomLevel(value)
override fun setFollowZoomLevel(camera: RNMBXCamera, value: Dynamic) {
camera.setFollowZoomLevel(value.asDouble())
}

@ReactProp(name = "followPitch")
fun setFollowPitch(camera: RNMBXCamera, value: Double) {
camera.setFollowPitch(value)
override fun setFollowPitch(camera: RNMBXCamera, value: Dynamic) {
camera.setFollowPitch(value.asDouble())
}

@ReactProp(name = "followHeading")
fun setFollowHeading(camera: RNMBXCamera, value: Double) {
camera.setFollowHeading(value)
override fun setFollowHeading(camera: RNMBXCamera, value: Dynamic) {
camera.setFollowHeading(value.asDouble())
}

@ReactProp(name = "followPadding")
fun setFollowPadding(camera: RNMBXCamera, value: ReadableMap) {
camera.setFollowPadding(value)
override fun setFollowPadding(camera: RNMBXCamera, value: Dynamic) {
camera.setFollowPadding(value.asMap())
}

@ReactProp(name = "maxBounds")
fun setMaxBounds(camera: RNMBXCamera, value: String?) {
if (value != null) {
val collection = FeatureCollection.fromJson(value)
override fun setMaxBounds(camera: RNMBXCamera, value: Dynamic) {
if (!value.isNull) {
val collection = FeatureCollection.fromJson(value.asString())
camera.setMaxBounds(toLatLngBounds(collection))
} else {
camera.setMaxBounds(null)
}
}

override fun setAnimationDuration(view: RNMBXCamera?, value: Dynamic) {
// no-op on Android
}

override fun setAnimationMode(view: RNMBXCamera?, value: Dynamic) {
// no-op on Android
}

companion object {
const val REACT_CLASS = "RNMBXCamera"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,20 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso

// region React Props
@ReactProp(name = "projection")
override fun setProjection(mapView: RNMBXMapView, projection: String?) {
mapView.setReactProjection( if (projection == "globe") ProjectionName.GLOBE else ProjectionName.MERCATOR )
override fun setProjection(mapView: RNMBXMapView, projection: Dynamic) {
mapView.setReactProjection( if (projection.asString() == "globe") ProjectionName.GLOBE else ProjectionName.MERCATOR )
}

@ReactProp(name = "localizeLabels")
override fun setLocalizeLabels(mapView: RNMBXMapView, localeMap: ReadableMap?) {
val locale = localeMap?.getString("locale")
val layerIds = localeMap?.getArray("layerIds")?.toArrayList()?.mapNotNull {it?.toString()}
override fun setLocalizeLabels(mapView: RNMBXMapView, localeMap: Dynamic) {
val locale = localeMap.asMap().getString("locale")
val layerIds = localeMap.asMap().getArray("layerIds")?.toArrayList()?.mapNotNull {it?.toString()}
mapView.setReactLocalizeLabels(locale, layerIds)
}

@ReactProp(name = "styleURL")
override fun setStyleURL(mapView: RNMBXMapView, styleURL: String?) {
mapView.setReactStyleURL(styleURL!!)
override fun setStyleURL(mapView: RNMBXMapView, styleURL:Dynamic) {
mapView.setReactStyleURL(styleURL.asString())
}

@ReactProp(name = "preferredFramesPerSecond")
Expand All @@ -150,141 +150,122 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso
}

@ReactProp(name = "zoomEnabled")
override fun setZoomEnabled(map: RNMBXMapView, zoomEnabled: Boolean) {
override fun setZoomEnabled(map: RNMBXMapView, zoomEnabled: Dynamic) {
val mapView = map.mapView
mapView.gestures.pinchToZoomEnabled = zoomEnabled
mapView.gestures.doubleTouchToZoomOutEnabled = zoomEnabled
mapView.gestures.doubleTapToZoomInEnabled = zoomEnabled
mapView.gestures.pinchToZoomEnabled = zoomEnabled.asBoolean()
mapView.gestures.doubleTouchToZoomOutEnabled = zoomEnabled.asBoolean()
mapView.gestures.doubleTapToZoomInEnabled = zoomEnabled.asBoolean()
}

@ReactProp(name = "scrollEnabled")
override fun setScrollEnabled(map: RNMBXMapView, scrollEnabled: Boolean) {
override fun setScrollEnabled(map: RNMBXMapView, scrollEnabled: Dynamic) {
val mapView = map.mapView
mapView.gestures.scrollEnabled = scrollEnabled
mapView.gestures.scrollEnabled = scrollEnabled.asBoolean()
}

@ReactProp(name = "pitchEnabled")
override fun setPitchEnabled(map: RNMBXMapView, pitchEnabled: Boolean) {
override fun setPitchEnabled(map: RNMBXMapView, pitchEnabled: Dynamic) {
val mapView = map.mapView
mapView.gestures.pitchEnabled = pitchEnabled
mapView.gestures.pitchEnabled = pitchEnabled.asBoolean()
}

@ReactProp(name = "rotateEnabled")
override fun setRotateEnabled(map: RNMBXMapView, rotateEnabled: Boolean) {
override fun setRotateEnabled(map: RNMBXMapView, rotateEnabled: Dynamic) {
val mapView = map.mapView
mapView.gestures.rotateEnabled = rotateEnabled
mapView.gestures.rotateEnabled = rotateEnabled.asBoolean()
}

@ReactProp(name = "attributionEnabled")
override fun setAttributionEnabled(mapView: RNMBXMapView, attributionEnabled: Boolean) {
mapView.setReactAttributionEnabled(attributionEnabled)
override fun setAttributionEnabled(mapView: RNMBXMapView, attributionEnabled: Dynamic) {
mapView.setReactAttributionEnabled(attributionEnabled.asBoolean())
}

@ReactProp(name = "attributionPosition")
fun setAttributionPosition(mapView: RNMBXMapView, attributionPosition: ReadableMap) {
mapView.setReactAttributionPosition(attributionPosition)
override fun setAttributionPosition(mapView: RNMBXMapView, attributionPosition: Dynamic) {
mapView.setReactAttributionPosition(attributionPosition.asMap())
}

@ReactProp(name = "attributionViewMargins")
fun setAttributionViewMargins(mapView: RNMBXMapView, scaleBarMargins: ReadableMap) {
mapView.setReactAttributionViewMargins(scaleBarMargins)
override fun setAttributionViewMargins(mapView: RNMBXMapView, scaleBarMargins: Dynamic) {
mapView.setReactAttributionViewMargins(scaleBarMargins.asMap())
}

@ReactProp(name = "attributionViewPosition")
fun setAttributionViewPosition(mapView: RNMBXMapView, scaleBarPosition: Int) {
mapView.setReactAttributionViewPosition(scaleBarPosition)
override fun setAttributionViewPosition(mapView: RNMBXMapView, attributionViewPosition: Dynamic) {
mapView.setReactAttributionViewPosition(attributionViewPosition.asInt())
}

@ReactProp(name = "logoEnabled")
override fun setLogoEnabled(mapView: RNMBXMapView, logoEnabled: Boolean) {
mapView.setReactLogoEnabled(logoEnabled)
override fun setLogoEnabled(mapView: RNMBXMapView, logoEnabled: Dynamic) {
mapView.setReactLogoEnabled(logoEnabled.asBoolean())
}

@ReactProp(name = "logoPosition")
fun setLogoPosition(mapView: RNMBXMapView, logoPosition: ReadableMap?) {
mapView.setReactLogoPosition(logoPosition)
override fun setLogoPosition(mapView: RNMBXMapView, logoPosition: Dynamic) {
mapView.setReactLogoPosition(logoPosition.asMap())
}

@ReactProp(name = "scaleBarEnabled")
override fun setScaleBarEnabled(mapView: RNMBXMapView, scaleBarEnabled: Boolean) {
mapView.setReactScaleBarEnabled(scaleBarEnabled)
override fun setScaleBarEnabled(mapView: RNMBXMapView, scaleBarEnabled: Dynamic) {
mapView.setReactScaleBarEnabled(scaleBarEnabled.asBoolean())
}

@ReactProp(name = "scaleBarViewMargins")
fun setScaleBarViewMargins(mapView: RNMBXMapView, scaleBarMargins: ReadableMap) {
mapView.setReactScaleBarViewMargins(scaleBarMargins)
}

@ReactProp(name = "scaleBarViewPosition")
fun setScaleBarViewPosition(mapView: RNMBXMapView, scaleBarPosition: Int) {
mapView.setReactScaleBarViewPosition(scaleBarPosition)
override fun setScaleBarViewMargins(mapView: RNMBXMapView, scaleBarMargins: Dynamic) {
mapView.setReactScaleBarViewMargins(scaleBarMargins.asMap())
}

@ReactProp(name = "scaleBarPosition")
fun scaleBarViewPosition(mapView: RNMBXMapView?, scaleBarPosition: ReadableMap) {
mapView!!.setReactScaleBarPosition(scaleBarPosition)
override fun setScaleBarPosition(mapView: RNMBXMapView, scaleBarPosition: Dynamic) {
mapView.setReactScaleBarPosition(scaleBarPosition.asMap())
}

@ReactProp(name = "compassEnabled")
override fun setCompassEnabled(mapView: RNMBXMapView, compassEnabled: Boolean) {
mapView.setReactCompassEnabled(compassEnabled)
override fun setCompassEnabled(mapView: RNMBXMapView, compassEnabled: Dynamic) {
mapView.setReactCompassEnabled(compassEnabled.asBoolean())
}

@ReactProp(name = "compassFadeWhenNorth")
override fun setCompassFadeWhenNorth(mapView: RNMBXMapView, compassFadeWhenNorth: Boolean) {
mapView.setReactCompassFadeWhenNorth(compassFadeWhenNorth)
override fun setCompassFadeWhenNorth(mapView: RNMBXMapView, compassFadeWhenNorth: Dynamic) {
mapView.setReactCompassFadeWhenNorth(compassFadeWhenNorth.asBoolean())
}

@ReactProp(name = "compassViewMargins")
override fun setCompassViewMargins(mapView: RNMBXMapView, compassViewMargins: ReadableMap?) {
mapView.setReactCompassViewMargins(compassViewMargins ?: return)
override fun setCompassViewMargins(mapView: RNMBXMapView, compassViewMargins: Dynamic) {
mapView.setReactCompassViewMargins(compassViewMargins.asMap() ?: return)
}

@ReactProp(name = "compassViewPosition")
override fun setCompassViewPosition(mapView: RNMBXMapView, compassViewPosition: Int) {
mapView.setReactCompassViewPosition(compassViewPosition)
override fun setCompassViewPosition(mapView: RNMBXMapView, compassViewPosition: Dynamic) {
mapView.setReactCompassViewPosition(compassViewPosition.asInt())
}

@ReactProp(name = "compassPosition")
fun setCompassPosition(mapView: RNMBXMapView, compassMargins: ReadableMap) {
mapView.setReactCompassPosition(compassMargins)
override fun setCompassPosition(mapView: RNMBXMapView, compassMargins: Dynamic) {
mapView.setReactCompassPosition(compassMargins.asMap())
}

@ReactProp(name = "contentInset")
fun setContentInset(mapView: RNMBXMapView, array: ReadableArray) {
// remember to add it to codegen if it will be used
//mapView.setReactContentInset(array);
}

@ReactProp(name = "tintColor", customType = "Color")
fun setTintColor(mapView: RNMBXMapView, tintColor: Int) {
// remember to add it to codegen if it will be used
//mapView.setTintColor(tintColor);
}

@ReactProp(name = "requestDisallowInterceptTouchEvent")
override fun setRequestDisallowInterceptTouchEvent(mapView: RNMBXMapView, requestDisallowInterceptTouchEvent: Boolean) {
mapView.requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent
}

override fun setAttributionPosition(view: RNMBXMapView, value: Dynamic) {
this.setAttributionPosition(view, value.asMap())
}

override fun setLogoPosition(view: RNMBXMapView, value: Dynamic) {
this.setLogoPosition(view, value.asMap())
}

override fun setCompassPosition(view: RNMBXMapView, value: Dynamic) {
this.setCompassPosition(view, value.asMap())
override fun setRequestDisallowInterceptTouchEvent(mapView: RNMBXMapView, requestDisallowInterceptTouchEvent: Dynamic) {
mapView.requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent.asBoolean()
}

override fun setCompassImage(view: RNMBXMapView, value: String?) {
override fun setCompassImage(view: RNMBXMapView, value: Dynamic?) {
// TODO: No-op on Android?
}

override fun setScaleBarPosition(view: RNMBXMapView, value: Dynamic) {
// TODO: should this call setScaleBarViewPosition?
}

//endregion
//region Custom Events
override fun customEvents(): Map<String, String>? {
Expand Down
Loading
Loading