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 RNMBXPointAnnotation to new arch #3130

Merged
merged 11 commits into from
Oct 25, 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
12 changes: 11 additions & 1 deletion android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import com.facebook.react.uimanager.ViewManager
import com.rnmapbox.rnmbx.components.annotation.RNMBXCalloutManager
import com.rnmapbox.rnmbx.components.annotation.RNMBXMarkerViewManager
import com.rnmapbox.rnmbx.components.annotation.RNMBXPointAnnotationManager
import com.rnmapbox.rnmbx.components.annotation.RNMBXPointAnnotationModule
import com.rnmapbox.rnmbx.components.camera.RNMBXCameraManager
import com.rnmapbox.rnmbx.components.images.RNMBXImageManager
import com.rnmapbox.rnmbx.components.images.RNMBXImagesManager
import com.rnmapbox.rnmbx.components.location.RNMBXNativeUserLocationManager
import com.rnmapbox.rnmbx.components.mapview.NativeMapViewModule
import com.rnmapbox.rnmbx.components.mapview.RNMBXAndroidTextureMapViewManager
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapViewManager
import com.rnmapbox.rnmbx.components.styles.RNMBXStyleImportManager
import com.rnmapbox.rnmbx.components.styles.atmosphere.RNMBXAtmosphereManager
Expand Down Expand Up @@ -69,6 +69,7 @@ class RNMBXPackage : TurboReactPackage() {
RNMBXLogging.REACT_CLASS -> return RNMBXLogging(reactApplicationContext)
NativeMapViewModule.NAME -> return NativeMapViewModule(reactApplicationContext, getViewTagResolver(reactApplicationContext))
RNMBXShapeSourceModule.NAME -> return RNMBXShapeSourceModule(reactApplicationContext, getViewTagResolver(reactApplicationContext))
RNMBXPointAnnotationModule.NAME -> return RNMBXPointAnnotationModule(reactApplicationContext, getViewTagResolver(reactApplicationContext))
}
return null
}
Expand Down Expand Up @@ -187,6 +188,15 @@ class RNMBXPackage : TurboReactPackage() {
false, // isCxxModule
isTurboModule // isTurboModule
)
moduleInfos[RNMBXPointAnnotationModule.NAME] = ReactModuleInfo(
RNMBXPointAnnotationModule.NAME,
RNMBXPointAnnotationModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
)
moduleInfos
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.rnmapbox.rnmbx.components.annotation

import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.RNMBXCalloutManagerDelegate
import com.facebook.react.viewmanagers.RNMBXCalloutManagerInterface

class RNMBXCalloutManager : ViewGroupManager<RNMBXCallout>(),
RNMBXCalloutManagerInterface<RNMBXCallout> {

private val mDelegate: ViewManagerDelegate<RNMBXCallout>

init {
mDelegate = RNMBXCalloutManagerDelegate(this)
}

override fun getDelegate(): ViewManagerDelegate<RNMBXCallout> {
return mDelegate
}

override fun getName(): String {
return REACT_CLASS
}

override fun createViewInstance(reactContext: ThemedReactContext): RNMBXCallout {
return RNMBXCallout(reactContext)
}

companion object {
const val REACT_CLASS = "RNMBXCallout"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,56 @@ package com.rnmapbox.rnmbx.components.annotation

import android.view.View
import android.widget.FrameLayout
import com.facebook.react.bridge.Dynamic
import com.rnmapbox.rnmbx.utils.GeoJSONUtils.toPointGeometry
import com.facebook.react.bridge.ReactApplicationContext
import com.rnmapbox.rnmbx.components.AbstractEventEmitter
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.MapBuilder
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.RNMBXMarkerViewManagerDelegate
import com.facebook.react.viewmanagers.RNMBXMarkerViewManagerInterface
import com.mapbox.maps.ScreenCoordinate
import com.mapbox.maps.viewannotation.OnViewAnnotationUpdatedListener
import com.mapbox.maps.viewannotation.ViewAnnotationManager
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView

class RNMBXMarkerViewManager(reactApplicationContext: ReactApplicationContext) :
AbstractEventEmitter<RNMBXMarkerView?>(reactApplicationContext) {
AbstractEventEmitter<RNMBXMarkerView>(reactApplicationContext),
RNMBXMarkerViewManagerInterface<RNMBXMarkerView> {
private val mDelegate: ViewManagerDelegate<RNMBXMarkerView>

init {
mDelegate = RNMBXMarkerViewManagerDelegate(this)
}

override fun getDelegate(): ViewManagerDelegate<RNMBXMarkerView> {
return mDelegate
}

override fun getName(): String {
return REACT_CLASS
}

@ReactProp(name = "coordinate")
fun setCoordinate(markerView: RNMBXMarkerView, geoJSONStr: String?) {
markerView.setCoordinate(toPointGeometry(geoJSONStr))
override fun setCoordinate(markerView: RNMBXMarkerView, geoJSONStr: Dynamic) {
markerView.setCoordinate(toPointGeometry(geoJSONStr.asString()))
}

@ReactProp(name = "anchor")
fun setAnchor(markerView: RNMBXMarkerView, map: ReadableMap) {
markerView.setAnchor(map.getDouble("x").toFloat(), map.getDouble("y").toFloat())
override fun setAnchor(markerView: RNMBXMarkerView, map: Dynamic) {
markerView.setAnchor(map.asMap().getDouble("x").toFloat(), map.asMap().getDouble("y").toFloat())
}

@ReactProp(name = "allowOverlap")
fun setAllowOverlap(markerView: RNMBXMarkerView, allowOverlap: Boolean) {
markerView.setAllowOverlap(allowOverlap)
override fun setAllowOverlap(markerView: RNMBXMarkerView, allowOverlap: Dynamic) {
markerView.setAllowOverlap(allowOverlap.asBoolean())
}

@ReactProp(name = "isSelected")
fun setIsSelected(markerView: RNMBXMarkerView, isSelected: Boolean) {
markerView.setIsSelected(isSelected)
override fun setIsSelected(markerView: RNMBXMarkerView, isSelected: Dynamic) {
markerView.setIsSelected(isSelected.asBoolean())
}

override fun createViewInstance(reactContext: ThemedReactContext): RNMBXMarkerView {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.rnmapbox.rnmbx.components.annotation

import com.facebook.react.bridge.Dynamic
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.common.MapBuilder
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.RNMBXPointAnnotationManagerDelegate
import com.facebook.react.viewmanagers.RNMBXPointAnnotationManagerInterface
import com.rnmapbox.rnmbx.components.AbstractEventEmitter
import com.rnmapbox.rnmbx.events.constants.EventKeys
import com.rnmapbox.rnmbx.utils.GeoJSONUtils.toPointGeometry

class RNMBXPointAnnotationManager(reactApplicationContext: ReactApplicationContext) : AbstractEventEmitter<RNMBXPointAnnotation>(reactApplicationContext),
RNMBXPointAnnotationManagerInterface<RNMBXPointAnnotation> {

private val mDelegate: ViewManagerDelegate<RNMBXPointAnnotation>

init {
mDelegate = RNMBXPointAnnotationManagerDelegate(this)
}

override fun getDelegate(): ViewManagerDelegate<RNMBXPointAnnotation> {
return mDelegate
}

override fun getName(): String {
return REACT_CLASS
}

override fun customEvents(): Map<String, String> {
return MapBuilder.builder<String, String>()
.put(EventKeys.POINT_ANNOTATION_SELECTED, "onMapboxPointAnnotationSelected")
.put(EventKeys.POINT_ANNOTATION_DESELECTED, "onMapboxPointAnnotationDeselected")
.put(EventKeys.POINT_ANNOTATION_DRAG_START, "onMapboxPointAnnotationDragStart")
.put(EventKeys.POINT_ANNOTATION_DRAG, "onMapboxPointAnnotationDrag")
.put(EventKeys.POINT_ANNOTATION_DRAG_END, "onMapboxPointAnnotationDragEnd")
.build()
}

// TODO: check why it does not work correctly
override fun createViewInstance(reactContext: ThemedReactContext): RNMBXPointAnnotation {
return RNMBXPointAnnotation(reactContext!!, this)
}

@ReactProp(name = "id")
override fun setId(annotation: RNMBXPointAnnotation, id: Dynamic) {
annotation.iD = id.asString()
}

@ReactProp(name = "coordinate")
override fun setCoordinate(annotation: RNMBXPointAnnotation, geoJSONStr: Dynamic) {
annotation.setCoordinate(toPointGeometry(geoJSONStr.asString())!!)
}

@ReactProp(name = "anchor")
override fun setAnchor(annotation: RNMBXPointAnnotation, map: Dynamic) {
annotation.setAnchor(map.asMap().getDouble("x").toFloat(), map.asMap().getDouble("y").toFloat())
}

@ReactProp(name = "draggable")
override fun setDraggable(annotation: RNMBXPointAnnotation, draggable: Dynamic) {
annotation.setDraggable(draggable.asBoolean())
}

companion object {
const val REACT_CLASS = "RNMBXPointAnnotation"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.rnmapbox.rnmbx.components.annotation

import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.module.annotations.ReactModule
import com.rnmapbox.rnmbx.NativeRNMBXPointAnnotationModuleSpec
import com.rnmapbox.rnmbx.utils.ViewTagResolver

@ReactModule(name = RNMBXPointAnnotationModule.NAME)
class RNMBXPointAnnotationModule(reactContext: ReactApplicationContext?, private val viewTagResolver: ViewTagResolver) :
NativeRNMBXPointAnnotationModuleSpec(reactContext) {

companion object {
const val NAME = "RNMBXPointAnnotationModule"
}

private fun withPointAnnotationOnUIThread(viewRef: Double?, reject: Promise, fn: (RNMBXPointAnnotation) -> Unit) {
if (viewRef == null) {
reject.reject(Exception("viewRef is null for RNMBXPointAnnotation"))
} else {
viewTagResolver.withViewResolved(viewRef.toInt(), reject, fn)
}
}

@ReactMethod
override fun refresh(viewRef: Double?, promise: Promise) {
withPointAnnotationOnUIThread(viewRef, promise) {
it.refresh()
promise.resolve(null)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ class RNMBXAtmosphereManager : ViewGroupManager<RNMBXAtmosphere>(), RNMBXAtmosph
return RNMBXAtmosphere(reactContext)
}

@ReactProp(name = "id")
fun setId(layer: RNMBXAtmosphere, id: String?) {
layer.iD = id
}

@ReactProp(name = "reactStyle")
override fun setReactStyle(atmosphere: RNMBXAtmosphere, reactStyle: Dynamic) {
atmosphere.setReactStyle(reactStyle.asMap())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;

public class RNMBXCalloutManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & RNMBXCalloutManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public RNMBXCalloutManagerDelegate(U viewManager) {
super(viewManager);
}
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
super.setProperty(view, propName, value);
}
}
Loading
Loading